Commit 1aa7a3e4 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/ticker' into 'master'

fix See merge request !169
parents d6bd61a0 7f5030da
...@@ -19,17 +19,25 @@ class HuobiBuilder extends FactoryService ...@@ -19,17 +19,25 @@ class HuobiBuilder extends FactoryService
protected $supported_symbol_change_sort_list = 'supported_symbol_change_sort_huobi_list'; protected $supported_symbol_change_sort_list = 'supported_symbol_change_sort_huobi_list';
protected $quotation_prefix = 'quotation_huobi_'; protected $quotation_prefix = 'quotation_huobi_';
public function getTicker() public function hotTickerUpdate()
{ {
$curl = new Curl(); $curl = new Curl();
$api = $this->base_url . '/market/tickers';
$res = $curl->get($api, false); $symbols = [
if (isset($res['status']) && 'ok' == $res['status']) { 'btcusdt',
$datas = $res['data']; 'ethusdt',
foreach ($datas as $item) { 'eosusdt'
$key = $this->quotation_prefix . $item['symbol']; ];
$this->redis->hmset($key, 'low', $item['low'], 'high', $item['high'], 'last', $item['close'], 'open', $item['open'], 'vol', $item['vol']); foreach ($symbols as $symbol) {
$this->redis->sadd($this->supported_symbol, $item['symbol']); $api = $this->base_url . '/market/detail?symbol=' . $symbol;
$res = $curl->get($api, false);
if (isset($res['status']) && 'ok' == $res['status']) {
$datas = $res['data'];
foreach ($datas as $item) {
$key = $this->quotation_prefix . $item['symbol'];
$this->redis->hmset($key, 'low', $item['low'], 'high', $item['high'], 'last', $item['close'], 'open', $item['open'], 'vol', $item['vol']);
$this->redis->sadd($this->supported_symbol, $item['symbol']);
}
} }
} }
} }
...@@ -37,7 +45,7 @@ class HuobiBuilder extends FactoryService ...@@ -37,7 +45,7 @@ class HuobiBuilder extends FactoryService
public function getTickerFromCache($page = 1) public function getTickerFromCache($page = 1)
{ {
$size = 0; $size = 0;
for ($i = 0; $i < $page; $i ++) { for ($i = 0; $i < $page; $i++) {
$size += 50; $size += 50;
$this->end = $size; $this->end = $size;
} }
...@@ -85,12 +93,13 @@ class HuobiBuilder extends FactoryService ...@@ -85,12 +93,13 @@ class HuobiBuilder extends FactoryService
$data = [ $data = [
'ticker' => $ticker, 'ticker' => $ticker,
'page' => [ 'page' => [
'pageSize' => 50, 'pageSize' => 50,
'currentPage' => (int)$page, 'currentPage' => (int)$page,
] ]
]; ];
return ['code' => $this->code, 'data' => $data]; return ['code' => $this->code, 'data' => $data];
} }
public function TickerSort() public function TickerSort()
{ {
$len = $this->redis->llen($this->supported_symbol_list); $len = $this->redis->llen($this->supported_symbol_list);
...@@ -104,11 +113,11 @@ class HuobiBuilder extends FactoryService ...@@ -104,11 +113,11 @@ class HuobiBuilder extends FactoryService
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100); $temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
array_push($ticker, $temp); array_push($ticker, $temp);
} }
$ticker_sort_close= $this->arraySort($ticker,'close'); $ticker_sort_close = $this->arraySort($ticker, 'close');
foreach ($ticker_sort_close as $val) { foreach ($ticker_sort_close as $val) {
$this->redis->lpush($this->supported_symbol_close_sort_list, $val['symbol']); $this->redis->lpush($this->supported_symbol_close_sort_list, $val['symbol']);
} }
$ticker_change_close= $this->arraySort($ticker,'change'); $ticker_change_close = $this->arraySort($ticker, 'change');
foreach ($ticker_change_close as $val) { foreach ($ticker_change_close as $val) {
$this->redis->lpush($this->supported_symbol_change_sort_list, $val['symbol']); $this->redis->lpush($this->supported_symbol_change_sort_list, $val['symbol']);
} }
......
...@@ -24,9 +24,9 @@ class TickerController extends Controller ...@@ -24,9 +24,9 @@ class TickerController extends Controller
} }
} }
public function actionIndex() public function actionHot()
{ {
$ticker_builder = ExchangeBuilderFactory::create('Huobi'); $ticker_builder = ExchangeBuilderFactory::create('Huobi');
$ticker_builder->getTicker(); $ticker_builder->hotTickerUpdate();
} }
} }
\ 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