Commit dbd91bc4 authored by shajiaiming's avatar shajiaiming

行情排序

parent 9f223312
......@@ -15,6 +15,8 @@ class BinanceBuilder extends FactoryService
protected $base_url = 'https://api.binance.com';
protected $supported_symbol = 'supported_symbol_binance';
protected $supported_symbol_list = 'supported_symbol_binance_list';
protected $supported_symbol_close_sort_list = 'supported_symbol_close_sort_binance_list';
protected $supported_symbol_change_sort_list = 'supported_symbol_change_sort_binance_list';
protected $quotation_prefix = 'quotation_binance_';
public function getTicker()
......@@ -57,7 +59,7 @@ class BinanceBuilder extends FactoryService
public function getTickerFromCache($page = 1)
{
$size = 0;
for ($i = 0; $i < $page; $i ++) {
for ($i = 0; $i < $page; $i++) {
$size += 50;
$this->end = $size;
}
......@@ -111,4 +113,37 @@ class BinanceBuilder extends FactoryService
];
return ['code' => $this->code, 'data' => $data];
}
public function TickerSort()
{
$len = $this->redis->llen($this->supported_symbol_list);
$ticker = [];
for ($i = 0; $i < $len; $i++) {
$symbol = $this->redis->lindex($this->supported_symbol_list, $i);
list($close, $open) = $this->redis->hmget($this->quotation_prefix . strtolower($symbol), 'last', 'open');
$temp = [];
$temp['symbol'] = strtoupper($symbol);
$temp['close'] = number_format($close, 6, '.', '');
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.4f", ($close - $open) / $open * 100);
array_push($ticker, $temp);
}
$ticker_sort_close= $this->arraySort($ticker,'close');
foreach ($ticker_sort_close as $val) {
$this->redis->lpush($this->supported_symbol_close_sort_list, $val['symbol']);
}
$ticker_change_close= $this->arraySort($ticker,'change');
foreach ($ticker_change_close as $val) {
$this->redis->lpush($this->supported_symbol_change_sort_list, $val['symbol']);
}
}
protected function arraySort($array, $keys, $sort = SORT_DESC)
{
$keysValue = [];
foreach ($array as $k => $v) {
$keysValue[$k] = $v[$keys];
}
array_multisort($keysValue, $sort, $array);
return $array;
}
}
\ No newline at end of file
......@@ -15,6 +15,8 @@ class HuobiBuilder extends FactoryService
protected $base_url = 'https://api.huobi.pro';
protected $supported_symbol = 'supported_symbol_huobi';
protected $supported_symbol_list = 'supported_symbol_huobi_list';
protected $supported_symbol_close_sort_list = 'supported_symbol_close_sort_huobi_list';
protected $supported_symbol_change_sort_list = 'supported_symbol_change_sort_huobi_list';
protected $quotation_prefix = 'quotation_huobi_';
public function getTicker()
......@@ -111,6 +113,38 @@ class HuobiBuilder extends FactoryService
];
return ['code' => $this->code, 'data' => $data];
}
public function TickerSort()
{
$len = $this->redis->llen($this->supported_symbol_list);
$ticker = [];
for ($i = 0; $i < $len; $i++) {
$symbol = $this->redis->lindex($this->supported_symbol_list, $i);
list($close, $open) = $this->redis->hmget($this->quotation_prefix . strtolower($symbol), 'last', 'open');
$temp = [];
$temp['symbol'] = strtoupper($symbol);
$temp['close'] = number_format($close, 6, '.', '');
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.4f", ($close - $open) / $open * 100);
array_push($ticker, $temp);
}
$ticker_sort_close= $this->arraySort($ticker,'close');
foreach ($ticker_sort_close as $val) {
$this->redis->lpush($this->supported_symbol_close_sort_list, $val['symbol']);
}
$ticker_change_close= $this->arraySort($ticker,'change');
foreach ($ticker_change_close as $val) {
$this->redis->lpush($this->supported_symbol_change_sort_list, $val['symbol']);
}
}
protected function arraySort($array, $keys, $sort = SORT_DESC)
{
$keysValue = [];
foreach ($array as $k => $v) {
$keysValue[$k] = $v[$keys];
}
array_multisort($keysValue, $sort, $array);
return $array;
}
public function getHotTicker()
{
......
......@@ -13,6 +13,9 @@ use linslin\yii2\curl\Curl;
class ZhaobiBuilder extends FactoryService
{
protected $base_url = 'https://api.biqianbao.top';
protected $supported_symbol = 'supported_symbol_zhaobi';
protected $supported_symbol_close_sort_list = 'supported_symbol_close_sort_zhaobi_list';
protected $supported_symbol_change_sort_list = 'supported_symbol_change_sort_zhaobi_list';
public function getTickerFromCache()
{
......@@ -61,6 +64,29 @@ class ZhaobiBuilder extends FactoryService
return ['code' => $this->code, 'data' => $data];
}
public function TickerSort()
{
$len = $this->redis->llen($this->supported_symbol);
$ticker = [];
for ($i = 0; $i < $len; $i++) {
$symbol = $this->redis->lindex($this->supported_symbol, $i);
list($close, $open) = $this->redis->hmget($this->quotation_prefix . strtolower($symbol), 'last', 'open');
$temp = [];
$temp['symbol'] = strtoupper($symbol);
$temp['close'] = number_format($close, 6, '.', '');
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.4f", ($close - $open) / $open * 100);
array_push($ticker, $temp);
}
$ticker_sort_close= $this->arraySort($ticker,'close');
foreach ($ticker_sort_close as $val) {
$this->redis->lpush($this->supported_symbol_close_sort_list, $val['symbol']);
}
$ticker_change_close= $this->arraySort($ticker,'change');
foreach ($ticker_change_close as $val) {
$this->redis->lpush($this->supported_symbol_change_sort_list, $val['symbol']);
}
}
public function getNotice($params = [])
{
$curl = new Curl();
......
<?php
namespace console\controllers;
use common\business\Chain33Business;
use common\models\psources\CoinGameBet;
use common\service\chain33\Chain33Service;
use common\service\exchange\ExchangeBuilderFactory;
use yii\console\Controller;
use Yii;
class TickerController extends Controller
{
/**
* 行情排序
*/
public function actionTickerSort()
{
$class = [/*'Binance', 'Huobi', */'Zhaobi'];
foreach ($class as $val) {
$ticker_builder = ExchangeBuilderFactory::create($val);
$ticker_builder->TickerSort();
}
}
}
\ 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