Commit 21ef0982 authored by shajiaiming's avatar shajiaiming

热门行情可自定义

parent 536399a2
......@@ -21,7 +21,7 @@ class TickerController extends BaseController
{
$page = Yii::$app->request->get('page', 1);
$device_code = Yii::$app->request->get('device_code', '');
$platform_id = Yii::$app->request->get('device_code', 0);
$platform_id = Yii::$app->request->get('platform_id', 0);
$exchange = Yii::$app->request->get('exchange', 'zhaobi');
$data_value = Yii::$app->request->get('data_value', '');
$sort_value = Yii::$app->request->get('sort_value', '');
......@@ -283,10 +283,43 @@ class TickerController extends BaseController
public function actionHotTicker()
{
$builder = ExchangeBuilderFactory::create('huobi');
$result = $builder->getHotTicker();
$code = $result['code'];
$data = $result['ticker'];
$platform_id = Yii::$app->request->get('platform_id', 0);
if (17 == $platform_id) {
$datas = [
[
'exchange' => 'huobi',
'symbol' => [
'btcusdt',
'ethusdt',
'eosusdt'
]
]
];
} else {
$datas = [
[
'exchange' => 'huobi',
'symbol' => [
'btcusdt',
'ethusdt'
]
],[
'exchange' => 'zhaobi',
'symbol' => [
'btyusdt'
]
]
];
}
$ticker = [];
foreach ($datas as $data) {
$builder = ExchangeBuilderFactory::create($data['exchange']);
$result = $builder->getHotTicker($data['symbol']);
if (0 != $result['code']) continue;
$ticker = array_merge($ticker, $result['ticker']);
}
$code = 0;
$data = $ticker;
$msg = 'success';
doEnd :
......
......@@ -97,8 +97,8 @@ class HuobiBuilder extends FactoryService
$temp['symbol'] = strtoupper($explode_arr[0]) . '/' . $coin;
$temp['currency'] = strtoupper($explode_arr[0]);
$temp['base_currency'] = strtoupper($coin);
$temp['close'] = rtrim(sprintf('%.8f', floatval($close)),'0');
$temp['close_usd'] = rtrim(sprintf('%.6f', floatval($close * $this->basic_price[$coin]['usd'])),'0');
$temp['close'] = rtrim(sprintf('%.8f', floatval($close)), '0');
$temp['close_usd'] = rtrim(sprintf('%.6f', floatval($close * $this->basic_price[$coin]['usd'])), '0');
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']);
$temp['change'] = (false == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['usd']);
......@@ -168,20 +168,15 @@ class HuobiBuilder extends FactoryService
}
}
public function getHotTicker()
public function getHotTicker($symbol = [])
{
$symbol = [
'btcusdt',
'ethusdt',
'btyusdt'
];
if (empty($symbol)) {
return ['code' => $this->code, 'ticker' => []];
}
$ticker = [];
foreach ($symbol as $val) {
if ('btyusdt' == $val) {
list($low, $high, $close, $open, $vol) = $this->redis->hmget('quotation_zhaobi_' . strtolower($val), 'low', 'high', 'last', 'open', 'vol');
} else {
list($low, $high, $close, $open, $vol) = $this->redis->hmget($this->quotation_prefix . strtolower($val), 'low', 'high', 'last', 'open', 'vol');
}
$explode_arr = explode('usdt', $val);
$temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/USDT';
......
......@@ -167,13 +167,34 @@ class ZhaobiBuilder extends FactoryService
return ['code' => $this->code, 'notice' => $data];
}
protected function arraySort($array, $keys, $sort = SORT_DESC)
public function getHotTicker($symbol = [])
{
$keysValue = [];
foreach ($array as $k => $v) {
$keysValue[$k] = $v[$keys];
if (empty($symbol)) {
return ['code' => $this->code, 'ticker' => []];
}
array_multisort($keysValue, $sort, $array);
return $array;
$ticker = [];
foreach ($symbol as $val) {
list($low, $high, $close, $open, $vol) = $this->redis->hmget($this->quotation_prefix . strtolower($val), 'low', 'high', 'last', 'open', 'vol');
$explode_arr = explode('usdt', $val);
$temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/USDT';
$temp['currency'] = strtoupper($explode_arr[0]);
$temp['base_currency'] = 'USDT';
$temp['close'] = (float)sprintf("%0.6f", $close);
$temp['close_usd'] = (float)sprintf("%0.6f", $close * $this->basic_price['USDT']['usd']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price['USDT']['rmb']);
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price['USDT']['usd']);
$temp['low_usd'] = (float)sprintf("%0.4f", $low * $this->basic_price['USDT']['usd']);
$temp['high_rmb'] = (float)sprintf("%0.4f", $high * $this->basic_price['USDT']['rmb']);
$temp['low_rmb'] = (float)sprintf("%0.4f", $low * $this->basic_price['USDT']['rmb']);
$temp['vol'] = (float)sprintf("%0.4f", $vol);
array_push($ticker, $temp);
}
if (count($ticker) > 0) {
$this->code = 0;
}
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