Commit c850c3b7 authored by shajiaiming's avatar shajiaiming

行情排序

parent dbd91bc4
......@@ -21,6 +21,8 @@ class TickerController extends BaseController
$page = Yii::$app->request->get('page', 1);
$device_code = Yii::$app->request->get('device_code', '');
$exchange = Yii::$app->request->get('exchange', 'zhaobi');
$data_value = Yii::$app->request->get('data-value','');
$sort = Yii::$app->request->get('sort','');
$exchange_arr = ['huobi', 'binance', 'okex', 'zhaobi'];
if (!in_array($exchange, $exchange_arr)) {
......
......@@ -14,8 +14,10 @@ class ZhaobiBuilder extends FactoryService
{
protected $base_url = 'https://api.biqianbao.top';
protected $supported_symbol = 'supported_symbol_zhaobi';
protected $supported_symbol_list = 'supported_symbol_zhaobi_list';
protected $supported_symbol_close_sort_list = 'supported_symbol_close_sort_zhaobi_list';
protected $supported_symbol_change_sort_list = 'supported_symbol_change_sort_zhaobi_list';
protected $quotation_prefix = 'quotation_zhaobi_';
public function getTickerFromCache()
{
......@@ -66,10 +68,16 @@ class ZhaobiBuilder extends FactoryService
public function TickerSort()
{
$len = $this->redis->llen($this->supported_symbol);
$keys = $this->redis->smembers($this->supported_symbol);
if (false == $this->redis->exists($this->supported_symbol_list)) {
foreach ($keys as $val) {
$this->redis->lpush($this->supported_symbol_list, $val);
}
}
$len = $this->redis->llen($this->supported_symbol_list);
$ticker = [];
for ($i = 0; $i < $len; $i++) {
$symbol = $this->redis->lindex($this->supported_symbol, $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);
......@@ -116,6 +124,15 @@ class ZhaobiBuilder extends FactoryService
];
}
return ['code' => $this->code, 'notice' => $data];
}
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
......@@ -9,17 +9,20 @@ use common\service\exchange\ExchangeBuilderFactory;
use yii\console\Controller;
use Yii;
class TickerController extends Controller
class TickerSortController extends Controller
{
/**
* 行情排序
*/
public function actionTickerSort()
public function actionIndex()
{
$class = [/*'Binance', 'Huobi', */'Zhaobi'];
$class = ['Binance', 'Huobi', 'Zhaobi'];
foreach ($class as $val) {
$ticker_builder = ExchangeBuilderFactory::create($val);
$ticker_builder->TickerSort();
go(function () use ($val) {
\Co::sleep(0.5);
$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