Commit d6dc17e9 authored by shajiaiming's avatar shajiaiming

HD ticker

parent ae3e8baa
...@@ -41,7 +41,8 @@ class ExchangeBusiness ...@@ -41,7 +41,8 @@ class ExchangeBusiness
11 => 'Bitnasdaq', 11 => 'Bitnasdaq',
12 => 'Isummit', 12 => 'Isummit',
13 => 'Boc', 13 => 'Boc',
14 => 'Jinwang' 14 => 'Jinwang',
15 => 'Hd'
//1 => 'Hadax', //不需要 //1 => 'Hadax', //不需要
//2 => 'Bitfinex', //不需要 //2 => 'Bitfinex', //不需要
...@@ -340,6 +341,12 @@ class ExchangeBusiness ...@@ -340,6 +341,12 @@ class ExchangeBusiness
goto doEnd; goto doEnd;
} }
if (in_array(strtoupper($tag), ['HDC'])) {
$exchange = ExchangeFactory::createExchange("Hd");
$quotation = $exchange->getTicker('HD', 'USDT');
goto doEnd;
}
foreach (self::$exchanges as $exchange) { foreach (self::$exchanges as $exchange) {
/** /**
* @var $exchange \common\service\exchange\Exchange * @var $exchange \common\service\exchange\Exchange
...@@ -397,7 +404,7 @@ class ExchangeBusiness ...@@ -397,7 +404,7 @@ class ExchangeBusiness
$exchange = ExchangeFactory::createExchange("Go"); $exchange = ExchangeFactory::createExchange("Go");
$rate = $exchange->getTicker("CNY", "USD"); $rate = $exchange->getTicker("CNY", "USD");
$cny_usd_rate = 1 / $rate['last']; $cny_usd_rate = 1 / $rate['last'];
if (in_array(strtoupper($tag), ['FOLI', 'CIC', 'KPC8', 'BVA', 'DAG', 'BNC', 'GHP', 'DRA', 'ETC', 'PAX', 'STH', 'XJH', 'SFT', 'TSC', 'SUM', 'USDW', 'FUT', 'MBTC', 'METH', 'GLCW'])) { if (in_array(strtoupper($tag), ['FOLI', 'CIC', 'KPC8', 'BVA', 'DAG', 'BNC', 'GHP', 'DRA', 'ETC', 'PAX', 'STH', 'XJH', 'SFT', 'TSC', 'SUM', 'USDW', 'FUT', 'MBTC', 'METH', 'GLCW', 'HDC'])) {
$quotation['usd'] = (float)sprintf("%0.4f", $quotation['last']); $quotation['usd'] = (float)sprintf("%0.4f", $quotation['last']);
$quotation['rmb'] = (float)sprintf("%0.4f", $quotation['last'] / $cny_usd_rate); $quotation['rmb'] = (float)sprintf("%0.4f", $quotation['last'] / $cny_usd_rate);
$quotation['low'] = (float)sprintf("%0.4f", $quotation['low']); $quotation['low'] = (float)sprintf("%0.4f", $quotation['low']);
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Hd extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_hd';
protected $quotation_prefix = 'quotation_hd_';
protected $base_url = 'https://app.honordecent.com/exchange/getHdcCurrPrice';
public function symbolExists($tag = 'HD', $aim = "USDT")
{
$supported = $this->redis->smembers($this->supported_symbol);
if (is_array($supported) && in_array($this->formatSymbol($tag, $aim), $supported)) {
return true;
}
return false;
}
/**
* 转化交易对为请求变量
*
* @param string $tag
* @param string $aim
* @return mixed
*/
public function formatSymbol($tag = 'HD', $aim = 'USDT')
{
return strtoupper($tag . $aim);
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public function setSupportedSymbol()
{
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public function setQuotation()
{
$curl = new Curl();
$res = $curl->get($this->base_url, false);
if (is_array($res) && 1 == $res['code']) {
$key = $this->quotation_prefix . 'HDUSDT';
$this->redis->hmset($key, 'low', $res['data'], 'high', $res['data'], 'last', $res['data']);
if (!$this->redis->sismember($this->supported_symbol, 'HDUSDT')) {
$this->redis->sadd($this->supported_symbol, 'HDUSDT');
}
}
}
}
\ 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