Commit 69c97b4f authored by shajiaiming's avatar shajiaiming

自选逻辑调整

parent ef00564c
......@@ -8,6 +8,7 @@ use api\base\BaseController;
use common\models\psources\CoinOptional;
use common\service\exchange\ExchangeFactory;
use common\service\exchange\ExchangeBuilderFactory;
use yii\helpers\ArrayHelper;
class TickerController extends BaseController
{
......@@ -48,9 +49,20 @@ class TickerController extends BaseController
goto doEnd;
}
$builder = ExchangeBuilderFactory::create($exchange);
$result = $builder->getTicker($device_code);
$result = $builder->getTicker();
$code = $result['code'];
$data = $result['ticker'];
if (false != $device_code) {
$coin_optional = CoinOptional::find()->select('symbol')->where(['platform' => $exchange, 'device_code' => $device_code])->asArray()->all();
$coin_optional = ArrayHelper::getColumn($coin_optional, 'symbol');
foreach ($data as &$val) {
if (in_array($val['symbol'], $coin_optional)) {
$val['optional'] = true;
}
}
}
$msg = 'success';
doEnd :
......
......@@ -14,7 +14,7 @@ class BinanceBuilder extends FactoryService
{
protected $base_url = 'https://api.binance.com';
public function getTicker($device_code = '')
public function getTicker()
{
$curl = new Curl();
$api = $this->base_url . '/api/v1/ticker/24hr';
......@@ -36,11 +36,7 @@ class BinanceBuilder extends FactoryService
$temp['high'] = (float)sprintf("%0.4f", $val['highPrice']);
$temp['low'] = (float)sprintf("%0.4f", $val['lowPrice']);
$temp['vol'] = (float)sprintf("%0.4f", $val['volume']);
if (false != $device_code && \Yii::$app->redis_app->sismember($device_code . '_binance', $val['symbol'])) {
$temp['optional'] = true;
} else {
$temp['optional'] = false;
}
$temp['optional'] = false;
array_push($ticker, $temp);
break;
}
......
......@@ -14,7 +14,7 @@ class HuobiBuilder extends FactoryService
{
protected $base_url = 'https://api.huobi.pro';
public function getTicker($device_code = '')
public function getTicker()
{
$curl = new Curl();
$api = $this->base_url . '/market/tickers';
......@@ -36,11 +36,7 @@ class HuobiBuilder extends FactoryService
$temp['high'] = (float)sprintf("%0.4f", $val['high']);
$temp['low'] = (float)sprintf("%0.4f", $val['low']);
$temp['vol'] = (float)sprintf("%0.4f", $val['vol']);
if (false != $device_code && \Yii::$app->redis_app->sismember($device_code . '_huobi', $val['symbol'])) {
$temp['optional'] = true;
} else {
$temp['optional'] = false;
}
$temp['optional'] = false;
array_push($ticker, $temp);
break;
}
......
......@@ -14,7 +14,7 @@ class ZhaobiBuilder extends FactoryService
{
protected $base_url = 'https://api.biqianbao.top';
public function getTicker($device_code = '')
public function getTicker()
{
$curl = new Curl();
$api = $this->base_url . '/api/data/Ticker?sort=cname';
......@@ -40,11 +40,7 @@ class ZhaobiBuilder extends FactoryService
$temp['high'] = (float)sprintf("%0.4f", $val['high']);
$temp['low'] = (float)sprintf("%0.4f", $val['low']);
$temp['vol'] = (float)sprintf("%0.4f", $val['vol']);
if (false != $device_code && \Yii::$app->redis_app->sismember($device_code . '_zhaobi', $val['symbol'])) {
$temp['optional'] = true;
} else {
$temp['optional'] = false;
}
$temp['optional'] = false;
array_push($ticker, $temp);
break;
}
......
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