Commit 89372932 authored by shajiaiming's avatar shajiaiming

fix

parent 309231c6
......@@ -124,7 +124,7 @@ class BinanceBuilder extends FactoryService
$temp = [];
$temp['symbol'] = strtoupper($symbol);
$temp['close'] = number_format($close, 6, '.', '');
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.4f", ($close - $open) / $open * 100);
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
array_push($ticker, $temp);
}
$ticker_sort_close= $this->arraySort($ticker,'close');
......
......@@ -24,37 +24,15 @@ class HuobiBuilder extends FactoryService
$curl = new Curl();
$api = $this->base_url . '/market/tickers';
$res = $curl->get($api, false);
$ticker = [];
if (isset($res['status']) && 'ok' == $res['status']) {
$this->code = 0;
foreach ($res['data'] as $val) {
foreach ($this->basic_coin as $k => $coin) {
$explode_arr = explode(strtolower($coin), $val['symbol']);
if (2 == count($explode_arr) && empty($explode_arr[1])) {
$temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/' . $coin;
$temp['currency'] = strtoupper($explode_arr[0]);
$temp['base_currency'] = strtoupper($coin);
$temp['close'] = number_format($val['close'], 6, '.', '');
$temp['close_usd'] = (float)sprintf("%0.6f", $val['close'] * $this->basic_price[$coin]['usd']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $val['close'] * $this->basic_price[$coin]['rmb']);
$temp['change'] = (false == $val['open']) ? 0 : (float)sprintf("%0.4f", ($val['close'] - $val['open']) / $val['open'] * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $val['high'] * $this->basic_price[$coin]['usd']);
$temp['low_usd'] = (float)sprintf("%0.4f", $val['low'] * $this->basic_price[$coin]['usd']);
$temp['high_rmb'] = (float)sprintf("%0.4f", $val['high'] * $this->basic_price[$coin]['rmb']);
$temp['low_rmb'] = (float)sprintf("%0.4f", $val['low'] * $this->basic_price[$coin]['rmb']);
$temp['vol'] = (float)sprintf("%0.4f", $val['vol']);
$temp['optional'] = false;
$temp['platform_zh'] = '火币';
$temp['platform_us'] = 'huobi';
array_push($ticker, $temp);
break;
$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']);
}
}
}
}
return ['code' => $this->code, 'ticker' => $ticker];
}
public function getTickerFromCache($page = 1)
{
......@@ -123,7 +101,7 @@ class HuobiBuilder extends FactoryService
$temp = [];
$temp['symbol'] = strtoupper($symbol);
$temp['close'] = number_format($close, 6, '.', '');
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.4f", ($close - $open) / $open * 100);
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
array_push($ticker, $temp);
}
$ticker_sort_close= $this->arraySort($ticker,'close');
......
......@@ -82,7 +82,7 @@ class ZhaobiBuilder extends FactoryService
$temp = [];
$temp['symbol'] = strtoupper($symbol);
$temp['close'] = number_format($close, 6, '.', '');
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.4f", ($close - $open) / $open * 100);
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
array_push($ticker, $temp);
}
$ticker_sort_close= $this->arraySort($ticker,'close');
......
......@@ -10,23 +10,8 @@ use common\service\exchange\ExchangeFactory;
use yii\console\Controller;
use Yii;
class TickerUpdateController extends Controller
class TickerController extends Controller
{
/**
* 行情排序
*/
public function actionIndex()
{
$class = ['Binance', 'HuoBi', 'Zhaobi'];
foreach ($class as $val) {
go(function () use ($val) {
\Co::sleep(0.5);
$exchange = ExchangeFactory::createExchange($val);
$exchange->setQuotation();
});
}
}
public function actionSort()
{
$class = ['Binance', 'Huobi', 'Zhaobi'];
......@@ -38,4 +23,10 @@ class TickerUpdateController extends Controller
});
}
}
public function actionIndex()
{
$ticker_builder = ExchangeBuilderFactory::create('Huobi');
$ticker_builder->getTicker();
}
}
\ 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