Commit 9b47be1f authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/trade-node' into 'master'

Feature/trade node See merge request !25
parents a3f14e6b 173b724c
...@@ -34,7 +34,8 @@ class ExchangeBusiness ...@@ -34,7 +34,8 @@ class ExchangeBusiness
5 => 'Zb', 5 => 'Zb',
6 => 'Token7', 6 => 'Token7',
7 => 'S', 7 => 'S',
8 => 'Zg' 8 => 'Zg',
// 9 => 'Go'
]; ];
/** /**
...@@ -147,10 +148,14 @@ class ExchangeBusiness ...@@ -147,10 +148,14 @@ class ExchangeBusiness
/** /**
* @var $exchange \common\service\exchange\Exchange * @var $exchange \common\service\exchange\Exchange
*/ */
$exchange = ExchangeFactory::createExchange("Go");
$exchange = ExchangeFactory::createExchange("Bty"); $rate = $exchange->getTicker("CNY", "USD");
$rate = $exchange->getTicker("BTY", "USDT"); $rate = $rate['last'] ?? '';
$rate = (float)$rate['rmb'] / $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.2f", $rate * $quotation['last']); $quotation['rmb'] = (float)sprintf("%0.2f", $rate * $quotation['last']);
return $quotation; return $quotation;
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Go extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_go';
protected $quotation_prefix = 'quotation_go_';
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';
public function symbolExists($tag = 'CNY', $aim = "USD")
{
$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 = 'CNY', $aim = 'USD')
{
return strtoupper($tag .'_'. $aim);
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public function setSupportedSymbol()
{
$this->redis->sadd($this->supported_symbol, 'CNY_USD');
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public function setQuotation()
{
$curl = new Curl();
$content = $curl->get($this->base_url, false);
if (is_array($content) && isset($content['code']) && (200 == $content['code'])) {
$data = $content['data'];
foreach ($data as $item) {
$key = $this->quotation_prefix . 'CNY_USD';
$this->redis->hmset($key, 'low', $item['price'], 'high', $item['price'], 'last', $item['price']);
$this->redis->sadd($this->supported_symbol, 'CNY_USD');
break;
}
}
}
}
\ 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