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; } } } } return ['code' => $this->code, 'ticker' => $ticker]; } public function getTickerFromCache() { $keys = $this->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) = $this->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); } } } if (count($ticker) > 0) { $this->code = 0; } return ['code' => $this->code, 'ticker' => $ticker]; } public function getHotTicker() { $symbol = [ 'btcusdt', 'ethusdt', 'eosusdt' ]; $ticker = []; foreach ($symbol as $val) { list($low, $high, $close, $open, $vol) = $this->redis->hmget($this->quotation_prefix . strtolower($val), 'low', 'high', 'last', 'open', 'vol'); $explode_arr = explode('usdt', $val); $temp = []; $temp['symbol'] = strtoupper($explode_arr[0]) . '/USDT'; $temp['currency'] = strtoupper($explode_arr[0]); $temp['base_currency'] = 'USDT'; $temp['close'] = (float)sprintf("%0.6f", $close); $temp['close_usd'] = (float)sprintf("%0.6f", $close * $this->basic_price['USDT']['usd']); $temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price['USDT']['rmb']); $temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.4f", ($close - $open) / $open * 100); $temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price['USDT']['usd']); $temp['low_usd'] = (float)sprintf("%0.4f", $low * $this->basic_price['USDT']['usd']); $temp['high_rmb'] = (float)sprintf("%0.4f", $high * $this->basic_price['USDT']['rmb']); $temp['low_rmb'] = (float)sprintf("%0.4f", $low * $this->basic_price['USDT']['rmb']); $temp['vol'] = (float)sprintf("%0.4f", $vol); array_push($ticker, $temp); } if (count($ticker) > 0) { $this->code = 0; } return ['code' => $this->code, 'ticker' => $ticker]; } }