Commit 014c24e6 authored by shajiaiming's avatar shajiaiming

逻辑调整

parent 7bb31ae7
......@@ -37,8 +37,7 @@ class TickerController extends BaseController
public function actionIndex()
{
$request = Yii::$app->request;
$device_code = $request->get('device_code', '');
$device_code = Yii::$app->request->get('device_code', '');
$exchange = Yii::$app->request->get('exchange', 'zhaobi');
$exchange_arr = ['huobi', 'binance', 'okex', 'zhaobi'];
......@@ -49,19 +48,9 @@ class TickerController extends BaseController
goto doEnd;
}
$builder = ExchangeBuilderFactory::create($exchange);
$result = $builder->getTicker();
$result = $builder->getTicker($device_code);
$code = $result['code'];
$data = $result['ticker'];
if (false != $device_code && Yii::$app->redis_app->exists($device_code . '_' . $exchange)) {
foreach ($data as &$val) {
if (Yii::$app->redis_app->sismember($device_code . '_' . $exchange, $val['symbol'])) {
$val['optional'] = true;
} else {
$val['optional'] = false;
}
}
}
$msg = 'success';
doEnd :
......
......@@ -14,7 +14,7 @@ class BinanceBuilder extends FactoryService
{
protected $base_url = 'https://api.binance.com';
public function getTicker()
public function getTicker($device_code = '')
{
$curl = new Curl();
$api = $this->base_url . '/api/v1/ticker/24hr';
......@@ -36,6 +36,11 @@ 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 (\Yii::$app->redis_app->sismember($device_code . '_binance', $val['symbol'])) {
$temp['optional'] = true;
} else {
$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()
public function getTicker($device_code = '')
{
$curl = new Curl();
$api = $this->base_url . '/market/tickers';
......@@ -36,6 +36,11 @@ 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 (\Yii::$app->redis_app->sismember($device_code . '_huobi', $val['symbol'])) {
$temp['optional'] = true;
} else {
$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()
public function getTicker($device_code = '')
{
$curl = new Curl();
$api = $this->base_url . '/api/data/Ticker?sort=cname';
......@@ -40,6 +40,11 @@ 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 (\Yii::$app->redis_app->sismember($device_code . '_zhaobi', $val['symbol'])) {
$temp['optional'] = true;
} else {
$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