Commit 95db9035 authored by shajiaiming's avatar shajiaiming

行情

parent 1da8cd6d
......@@ -49,7 +49,7 @@ class TickerController extends BaseController
goto doEnd;
}
$builder = ExchangeBuilderFactory::create($exchange);
$result = $builder->getTicker();
$result = $builder->getTickerFromCache();
$code = $result['code'];
$data = $result['ticker'];
......
......@@ -13,6 +13,8 @@ use linslin\yii2\curl\Curl;
class HuobiBuilder extends FactoryService
{
protected $base_url = 'https://api.huobi.pro';
protected $supported_symbol = 'supported_symbol_huobi';
protected $quotation_prefix = 'quotation_huobi_';
public function getTicker()
{
......@@ -51,6 +53,40 @@ class HuobiBuilder extends FactoryService
return ['code' => $this->code, 'ticker' => $ticker];
}
public function getTickerFromCache()
{
$redis = \Yii::$app->redis;
$keys = $redis->smembers($this->supported_symbol);
$ticker = [];
foreach ($keys as $val) {
foreach ($this->basic_coin as $k => $coin) {
$explode_arr = explode(strtolower($coin), $val);
if (2 == count($explode_arr) && empty($explode_arr[1])) {
list($low, $high, $close, $open, $vol) = $redis->hmget($this->quotation_prefix.strtolower($val), 'low', 'high', 'last', 'open', 'vol');
$temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/' . $coin;
$temp['currency'] = strtoupper($explode_arr[0]);
$temp['base_currency'] = strtoupper($coin);
$temp['close'] = number_format($close, 6, '.', '');
$temp['close_usd'] = (float)sprintf("%0.6f", $close * $this->basic_price[$coin]['usd']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']);
$temp['change'] = (false == $open) ? 0 : (float)sprintf("%0.4f", ($close - $open) / $open * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['usd']);
$temp['low_usd'] = (float)sprintf("%0.4f", $low * $this->basic_price[$coin]['usd']);
$temp['high_rmb'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['rmb']);
$temp['low_rmb'] = (float)sprintf("%0.4f", $low * $this->basic_price[$coin]['rmb']);
$temp['vol'] = (float)sprintf("%0.4f", $vol);
$temp['optional'] = false;
$temp['platform_zh'] = '火币';
$temp['platform_us'] = 'huoBi';
array_push($ticker, $temp);
}
}
}
echo json_encode($ticker);exit;
}
public function getHotTicker()
{
$curl = new Curl();
......
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