Commit 38057608 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into 'master'

行情 See merge request !490
parents b64c07c7 22e15b07
...@@ -27,21 +27,21 @@ class ExchangeBusiness ...@@ -27,21 +27,21 @@ class ExchangeBusiness
* @var array * @var array
*/ */
private static $exchanges = [ private static $exchanges = [
0 => 'Bty', //0 => 'Bty',
1 => 'HuoBi', 0 => 'HuoBi',
2 => 'Hadax', 1 => 'Hadax',
3 => 'Bittrex', 2 => 'Bittrex',
4 => 'Zb', 3 => 'Zb',
5 => 'Go', 4 => 'Rate',
6 => 'Zhaobi', 5 => 'Superx',
7 => 'Binance', 6 => 'Binance',
8 => 'Bilaxy', 7 => 'Bilaxy',
9 => 'Bitnasdaq', 8 => 'Bitnasdaq',
10 => 'Isummit', 9 => 'Isummit',
11 => 'Boc', 10 => 'Boc',
12 => 'Ztb', 11 => 'Ztb',
13 => 'Wbf', 12 => 'Wbf',
14 => 'Gwa' 13 => 'Gwa'
//1 => 'Hadax', //不需要 //1 => 'Hadax', //不需要
//2 => 'Bitfinex', //不需要 //2 => 'Bitfinex', //不需要
...@@ -61,6 +61,7 @@ class ExchangeBusiness ...@@ -61,6 +61,7 @@ class ExchangeBusiness
//5 => 'Zg',//已挂 //5 => 'Zg',//已挂
//13 => 'Jinwang',//已挂 //13 => 'Jinwang',//已挂
//14 => 'Hd',//已挂 //14 => 'Hd',//已挂
//15 => 'Zhaobi',//已挂
]; ];
/** /**
...@@ -84,21 +85,6 @@ class ExchangeBusiness ...@@ -84,21 +85,6 @@ class ExchangeBusiness
} }
$coin_quotation_disable_items = Yii::$app->params['coin_quotation_disable_items']; $coin_quotation_disable_items = Yii::$app->params['coin_quotation_disable_items'];
if (strtoupper($tag) == 'CCNY' || strtoupper($tag) == 'CNYT' || strtoupper($tag) == 'ETC' || strtoupper($tag) == 'YX') {
$exchange = ExchangeFactory::createExchange("Zhaobi");
if (strtoupper($tag) == 'ETC') {
$quotation = $exchange->getTicker($tag, 'USDT');
$quotation['rmb'] = (float)sprintf("%0.4f", $quotation['last']);
goto doEnd;
}
$rate = $exchange->getTicker("BTY", "USDT");
$rate = (float)$rate['rmb'] / $rate['last'];
$quotation['rmb'] = 1.00;
$quotation['low'] = 1.00;
$quotation['high'] = 1.00;
$quotation['last'] = (float)sprintf("%0.4f", $quotation['rmb'] / $rate);
goto doEnd;
}
if (strtoupper($tag) == 'USAT') { if (strtoupper($tag) == 'USAT') {
$tag = 'USDT'; $tag = 'USDT';
...@@ -300,16 +286,6 @@ class ExchangeBusiness ...@@ -300,16 +286,6 @@ class ExchangeBusiness
goto doEnd; goto doEnd;
} }
if (in_array(strtoupper($tag), ['SFT'])) {
$exchange = ExchangeFactory::createExchange("Zhaobi");
$quotation = $exchange->getTicker($tag, 'USDT');
$quotation['low'] = (float)sprintf("%0.4f", $quotation['low']);
$quotation['high'] = (float)sprintf("%0.4f", $quotation['high']);
$quotation['last'] = (float)sprintf("%0.4f", $quotation['last']);
$quotation['rmb'] = (float)sprintf("%0.4f", $quotation['last']);
goto doEnd;
}
if (in_array(strtoupper($tag), ['CTG'])) { if (in_array(strtoupper($tag), ['CTG'])) {
$exchange = ExchangeFactory::createExchange("Gdpro"); $exchange = ExchangeFactory::createExchange("Gdpro");
$quotation = $exchange->getTicker($tag, 'CNY'); $quotation = $exchange->getTicker($tag, 'CNY');
...@@ -317,19 +293,19 @@ class ExchangeBusiness ...@@ -317,19 +293,19 @@ class ExchangeBusiness
goto doEnd; goto doEnd;
} }
if (in_array(strtoupper($tag), ['USDT'])) { // if (in_array(strtoupper($tag), ['USDT'])) {
$exchange = ExchangeFactory::createExchange("Go"); // $exchange = ExchangeFactory::createExchange("Go");
$quotation = $exchange->getTicker('CNY', 'USD'); // $quotation = $exchange->getTicker('CNY', 'USD');
$quotation['rmb'] = (float)sprintf("%0.4f", $quotation['last']); // $quotation['rmb'] = (float)sprintf("%0.4f", $quotation['last']);
goto doEnd; // goto doEnd;
} // }
//
if (in_array(strtoupper($tag), ['SUSD'])) { // if (in_array(strtoupper($tag), ['SUSD'])) {
$exchange = ExchangeFactory::createExchange("Go"); // $exchange = ExchangeFactory::createExchange("Go");
$quotation = $exchange->getTicker('CNY', 'USD'); // $quotation = $exchange->getTicker('CNY', 'USD');
$quotation['rmb'] = (float)sprintf("%0.4f", $quotation['last']); // $quotation['rmb'] = (float)sprintf("%0.4f", $quotation['last']);
goto doEnd; // goto doEnd;
} // }
if (in_array(strtoupper($tag), ['CIC', 'MC'])) { if (in_array(strtoupper($tag), ['CIC', 'MC'])) {
$exchange = ExchangeFactory::createExchange("Ztb"); $exchange = ExchangeFactory::createExchange("Ztb");
...@@ -442,7 +418,7 @@ class ExchangeBusiness ...@@ -442,7 +418,7 @@ class ExchangeBusiness
goto doEnd; goto doEnd;
} }
if (in_array(strtoupper($tag), ['GWA','KLG'])) { if (in_array(strtoupper($tag), ['GWA', 'KLG'])) {
$exchange = ExchangeFactory::createExchange("Gwa"); $exchange = ExchangeFactory::createExchange("Gwa");
$quotation = $exchange->getTicker(strtoupper($tag), 'USDT'); $quotation = $exchange->getTicker(strtoupper($tag), 'USDT');
goto doEnd; goto doEnd;
...@@ -487,24 +463,12 @@ class ExchangeBusiness ...@@ -487,24 +463,12 @@ class ExchangeBusiness
foreach ($quotation as $key => $item) { foreach ($quotation as $key => $item) {
$quotation[$key] = (float)sprintf("%0.4f", (double)$item); $quotation[$key] = (float)sprintf("%0.4f", (double)$item);
} }
//用YCC计算汇率
/**
* @var $exchange \common\service\exchange\Exchange
*/
$exchange = ExchangeFactory::createExchange("Go");
$rate = $exchange->getTicker("CNY", "USD");
$rate = $rate['last'] ?? '';
if (empty($rate)) {
$exchange = ExchangeFactory::createExchange("Bty");
$rate = $exchange->getTicker("BTY", "USDT");
$rate = (float)$rate['rmb'] / $rate['last'];
}
$quotation['rmb'] = (float)sprintf("%0.4f", $rate * $quotation['last']);
doEnd : doEnd :
$exchange = ExchangeFactory::createExchange("Go"); $exchange = ExchangeFactory::createExchange("Rate");
$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', 'MC', 'KPC8', 'BBD', 'BVA', 'DAG', 'BNC', 'BNB', 'GHP', 'DRA', 'ETC', 'PAX', 'STH', 'XJH', 'SFT', 'TSC', 'SUM', 'USDW', 'FUT', 'MBTC', 'METH', 'GLCW', 'HDC', 'GWA', 'KLG', 'LELE', 'ZUE'])) { if (in_array(strtoupper($tag), ['FOLI', 'CIC', 'MC', 'KPC8', 'BBD', 'BVA', 'DAG', 'BNC', 'BNB', 'GHP', 'DRA', 'ETC', 'PAX', 'STH', 'XJH', 'SFT', 'TSC', 'SUM', 'USDW', 'FUT', 'MBTC', 'METH', 'GLCW', 'HDC', 'GWA', 'KLG', '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);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace common\service\coin; namespace common\service\coin;
use common\helpers\Curl; use linslin\yii2\curl\Curl;
use Yii; use Yii;
class CoinBTYService extends Coin implements CoinInterface class CoinBTYService extends Coin implements CoinInterface
......
...@@ -10,11 +10,11 @@ namespace common\service\exchange; ...@@ -10,11 +10,11 @@ namespace common\service\exchange;
use linslin\yii2\curl\Curl; use linslin\yii2\curl\Curl;
class Go extends Exchange implements ExchangeInterface class Rate extends Exchange implements ExchangeInterface
{ {
protected $supported_symbol = 'supported_symbol_go'; protected $supported_symbol = 'supported_symbol_rate';
protected $quotation_prefix = 'quotation_go_'; protected $quotation_prefix = 'quotation_rate_';
protected $base_url = 'https://otc-api.eiijo.cn/v1/data/trade-market?country=37&currency=1&payMethod=0&currPage=1&coinId=2&tradeType=sell&blockType=general&online=1'; protected $base_url = 'https://ticker-api.cointelegraph.com/history/USDT/CNY/?coin=USDT&currency=CNY&limit=1';
public function symbolExists($tag = 'CNY', $aim = "USD") public function symbolExists($tag = 'CNY', $aim = "USD")
{ {
...@@ -55,11 +55,11 @@ class Go extends Exchange implements ExchangeInterface ...@@ -55,11 +55,11 @@ class Go extends Exchange implements ExchangeInterface
{ {
$curl = new Curl(); $curl = new Curl();
$content = $curl->get($this->base_url, false); $content = $curl->get($this->base_url, false);
if (is_array($content) && isset($content['code']) && (200 == $content['code'])) { if (is_array($content)) {
$data = $content['data']; $data = $content['data'];
foreach ($data as $item) { foreach ($data as $item) {
$key = $this->quotation_prefix . 'CNY_USD'; $key = $this->quotation_prefix . 'CNY_USD';
$this->redis->hmset($key, 'low', $item['price'], 'high', $item['price'], 'last', $item['price']); $this->redis->hmset($key, 'low', $item['p'], 'high', $item['p'], 'last', $item['p']);
$this->redis->sadd($this->supported_symbol, 'CNY_USD'); $this->redis->sadd($this->supported_symbol, 'CNY_USD');
break; break;
} }
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Superx extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_superx';
protected $quotation_prefix = 'quotation_superx_';
protected $base_url = 'http://18.181.255.33:8091';
public function symbolExists($tag = 'bty', $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 = 'bty', $aim = 'usdt')
{
return strtolower(trim($tag) . trim($aim));
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public function setSupportedSymbol()
{
$this->redis->sadd($this->supported_symbol, 'btyusdt');
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public function setQuotation()
{
$curl = new Curl();
$api = $this->base_url . '/api/ticker';
$content = $curl->get($api, false);
if (isset($content['msg']) && 'succeed' == $content['msg']) {
$ticker = isset($content['data']['data']['USDT']) ? $content['data']['data']['USDT'] : null;
if (false != $ticker) {
foreach ($ticker as $key => $val) {
$key = $this->quotation_prefix . strtolower($key) . "usdt";
$this->redis->hmset($key, 'low', $val['low'], 'high', $val['high'], 'last', $val['last'], 'open', $val['open'], 'vol', $val['vol'], 'range', str_replace('%', '', $val['range']));
$this->redis->sadd($this->supported_symbol, $val['symbol']);
}
}
}
}
}
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