Commit 16826dc3 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/ticker' into 'master'

Feature/ticker See merge request !473
parents e6a2f160 112a644f
...@@ -386,6 +386,22 @@ class TickerController extends BaseController ...@@ -386,6 +386,22 @@ class TickerController extends BaseController
] ]
]; ];
} }
if (64 == $platform_id) {
$datas = [
[
'exchange' => 'huobi',
'symbol' => [
'btcusdt',
'ethusdt'
],
], [
'exchange' => 'gwa',
'symbol' => [
'gwausdt'
],
]
];
}
$ticker = []; $ticker = [];
foreach ($datas as $data) { foreach ($datas as $data) {
$builder = ExchangeBuilderFactory::create($data['exchange']); $builder = ExchangeBuilderFactory::create($data['exchange']);
......
...@@ -42,7 +42,8 @@ class ExchangeBusiness ...@@ -42,7 +42,8 @@ class ExchangeBusiness
13 => 'Jinwang', 13 => 'Jinwang',
14 => 'Hd', 14 => 'Hd',
15 => 'Ztb', 15 => 'Ztb',
16 => 'Wbf' 16 => 'Wbf',
17 => 'Gwa'
//1 => 'Hadax', //不需要 //1 => 'Hadax', //不需要
//2 => 'Bitfinex', //不需要 //2 => 'Bitfinex', //不需要
...@@ -411,6 +412,12 @@ class ExchangeBusiness ...@@ -411,6 +412,12 @@ class ExchangeBusiness
goto doEnd; goto doEnd;
} }
if (in_array(strtoupper($tag), ['GWA'])) {
$exchange = ExchangeFactory::createExchange("Gwa");
$quotation = $exchange->getTicker('GWA', '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
...@@ -468,7 +475,7 @@ class ExchangeBusiness ...@@ -468,7 +475,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', 'ZYC', 'MC', 'KPC8', 'BBD', 'BVA', 'DAG', 'BNC', 'BNB', 'GHP', 'DRA', 'ETC', 'PAX', 'STH', 'XJH', 'SFT', 'TSC', 'SUM', 'USDW', 'FUT', 'MBTC', 'METH', 'GLCW', 'HDC', 'LELE', 'ZUE'])) { if (in_array(strtoupper($tag), ['FOLI', 'CIC', 'ZYC', 'MC', 'KPC8', 'BBD', 'BVA', 'DAG', 'BNC', 'BNB', 'GHP', 'DRA', 'ETC', 'PAX', 'STH', 'XJH', 'SFT', 'TSC', 'SUM', 'USDW', 'FUT', 'MBTC', 'METH', 'GLCW', 'HDC', 'GWA', 'LELE', 'ZUE'])) {
$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 Gwa extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_gwa';
protected $quotation_prefix = 'quotation_gwa_';
protected $base_url = 'https://api.gwaworld.io/getBalance';
public function symbolExists($tag = 'GWA', $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 = 'GWA', $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 . 'GWAUSDT';
$this->redis->hmset($key, 'low', $res['data']['currPrice'], 'high', $res['data']['currPrice'], 'last', $res['data']['currPrice'], 'change', $res['data']['range']);
if (!$this->redis->sismember($this->supported_symbol, 'GWAUSDT')) {
$this->redis->sadd($this->supported_symbol, 'GWAUSDT');
}
}
}
}
\ 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