Commit c48bd843 authored by shajiaiming's avatar shajiaiming

Merge branch 'master' into feature/ws_ticker

parents b1fffd2c 9845b193
...@@ -41,7 +41,8 @@ class ExchangeBusiness ...@@ -41,7 +41,8 @@ class ExchangeBusiness
12 => 'Boc', 12 => 'Boc',
13 => 'Ex', 13 => 'Ex',
14 => 'Zt', 14 => 'Zt',
15 => 'Tsc' 15 => 'Tsc',
16 => 'Binance'
]; ];
/** /**
...@@ -279,8 +280,11 @@ class ExchangeBusiness ...@@ -279,8 +280,11 @@ class ExchangeBusiness
/** /**
* @var $exchange \common\service\exchange\ExchangeInterface * @var $exchange \common\service\exchange\ExchangeInterface
*/ */
go(function () use ($exchange) {
\Co::sleep(0.5);
$exchange = ExchangeFactory::createExchange($exchange); $exchange = ExchangeFactory::createExchange($exchange);
$exchange->setQuotation(); $exchange->setQuotation();
});
} }
} }
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-26
* Time: 下午7:21
*/
namespace common\service\exchange;
use Yii;
use linslin\yii2\curl\Curl;
class Binance extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_binance';
protected $quotation_prefix = 'quotation_binance_';
protected $base_url = 'https://api.binance.com';
public function formatSymbol($tag = 'BTC', $aim = 'USDT')
{
return strtolower(trim($tag) . trim($aim));
}
public function setSupportedSymbol()
{
$curl = new Curl();
$api = $this->base_url . '/api/v1/ticker/24hr';
$res = $curl->get($api, false);//json
if (is_array($res)) {
foreach ($res as $item) {
$this->redis->sadd($this->supported_symbol, strtolower($item['symbol']));
}
}
}
public function setQuotation()
{
$curl = new Curl();
$api = $this->base_url . '/api/v1/ticker/24hr';
$res = $curl->get($api, false);
if (is_array($res)) {
foreach ($res as $item) {
$key = $this->quotation_prefix . strtolower($item['symbol']);
$this->redis->hmset($key, 'low', $item['lowPrice'], 'high', $item['highPrice'], 'last', $item['lastPrice'], 'open', $item['openPrice']);
$this->redis->sadd($this->supported_symbol, $item['symbol']);
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment