'HuoBi', 1 => 'Hadax', 2 => 'Bitfinex', ]; /** * 保存各个交易所支持的交易对到redis,定时用crontab更新 * @return void */ public static function setSupportedSymbol() { foreach (self::$exchanges as $exchange) { /** * @var $exchange \common\service\exchange\ExchangeInterface */ $exchange = ExchangeFactory::createExchange($exchange); $exchange->setSupportedSymbol(); } } /** * 更新交易所的行情数据保存到redis,定时更新 * @return void */ public static function setQuotation() { foreach (self::$exchanges as $exchange) { /** * @var $exchange \common\service\exchange\ExchangeInterface */ $exchange = ExchangeFactory::createExchange($exchange); $exchange->setQuotation(); } } /** * 根据name返回币种信息 * @param array $condition 需要的币种sid列表 * @return array */ public static function getApiListForIndex($condition = []) { $rows = Coin::getSelectList(1, 999, ['id', 'sid', 'icon', 'name', 'nickname', 'chain'], $condition); if ($rows['count'] > 0) { $rows = $rows['data']; foreach ($rows as $key => $row) { $rows[$key]['sid'] = ucfirst($rows[$key]['sid']); $f = false;//是否获取到行情 foreach (self::$exchanges as $exchange) { /** * @var $exchange \common\service\exchange\Exchange */ $exchange = ExchangeFactory::createExchange($exchange); if ($exchange->symbolExists($row['name'])) { $rows[$key] = array_merge($rows[$key], $exchange->getTicker($row['name'])); $f = true; break; } } if (!$f) { //所有交易所都不能直接获取交易对的行情就通过BTC去转换 //获取BTC_USD $btc_usd = ExchangeFactory::createExchange(self::$exchanges[0])->getTicker('btc'); foreach (self::$exchanges as $exchange) { /** * @var $exchange \common\service\exchange\Exchange */ $exchange = ExchangeFactory::createExchange($exchange); if ($exchange->symbolExists($row['name'], 'btc')) { $price_btc = $exchange->getTicker($row['name'], 'btc'); //获取btcusdt $result = array_map(function ($a, $b) { return $a * $b; }, $price_btc, $btc_usd); $rows[$key] = array_merge($rows[$key], ['low' => $result[0], 'high' => $result[1], 'last' => $result[2]]); break; } } } } return $rows; } return []; } }