Commit e631e21e authored by shajiaiming's avatar shajiaiming

fix

parent d238d1c0
......@@ -85,13 +85,6 @@ class TickerController extends BaseController
$msg = '参数错误';
goto doEnd;
}
$is_exist = Yii::$app->redis_app->sismember($device_code . '_' . $platform, $symbol);
if (true == $is_exist) {
$msg = '数据已存在!';
goto doEnd;
}
$model = CoinOptional::find()->where(['device_code' => $device_code, 'symbol' => $symbol])->one();
if ($model) {
$msg = '数据已存在!';
......@@ -103,7 +96,6 @@ class TickerController extends BaseController
if ($model->load(Yii::$app->request->post(), '') && $model->save()) {
$msg = 'success';
$code = 0;
Yii::$app->redis_app->sadd($device_code . '_' . $platform, $symbol);
} else {
$msg = current($model->firstErrors);
}
......@@ -186,8 +178,19 @@ class TickerController extends BaseController
}
$code = 0;
$msg = 'success';
Yii::$app->redis_app->srem($device_code . '_' . $platform, $symbol);
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionHotTicker()
{
$builder = ExchangeBuilderFactory::create('huobi');
$result = $builder->getHotTicker();
$code = $result['code'];
$data = $result['ticker'];
$msg = 'success';
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ No newline at end of file
......@@ -48,4 +48,39 @@ class HuobiBuilder extends FactoryService
}
return ['code' => $this->code, 'ticker' => $ticker];
}
public function getHotTicker()
{
$curl = new Curl();
$api = $this->base_url . '/market/detail';
$symbol = [
'btcusdt',
'ethusdt',
'eosusdt'
];
$ticker = [];
$this->code = 0;
foreach ($symbol as $key => $val) {
$url = $api . '/?symbol=' . $val;
$res = $curl->get($url, false);
if (isset($res['status']) && 'ok' == $res['status']) {
$explode_arr = explode('usdt', $val);
$temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/' . strtoupper($explode_arr[1]);
$temp['currency'] = strtoupper($explode_arr[0]);
$temp['base_currency'] = strtoupper($explode_arr[0]);
$temp['close'] = (float)sprintf("%0.6f", $res['tick']['close']);
$temp['close_usd'] = (float)sprintf("%0.6f", $res['tick']['close'] * $this->basic_price['USDT']['usd']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $res['tick']['close'] * $this->basic_price['USDT']['rmb']);
$temp['change'] = (float)sprintf("%0.4f", ($res['tick']['close'] - $res['tick']['open']) / $res['tick']['open'] * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $res['tick']['high'] * $this->basic_price['USDT']['usd']);
$temp['low_usd'] = (float)sprintf("%0.4f", $res['tick']['low'] * $this->basic_price['USDT']['usd']);
$temp['high_rmb'] = (float)sprintf("%0.4f", $res['tick']['high'] * $this->basic_price['USDT']['rmb']);
$temp['low_rmb'] = (float)sprintf("%0.4f", $res['tick']['low'] * $this->basic_price['USDT']['rmb']);
$temp['vol'] = (float)sprintf("%0.4f", $res['tick']['amount']);
array_push($ticker, $temp);
}
}
return ['code' => $this->code, 'ticker' => $ticker];
}
}
\ 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