Commit 63e0d6f5 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/ticker' into 'master'

add cic ticker See merge request !90
parents a1b6444b 340e3106
......@@ -39,7 +39,8 @@ class ExchangeBusiness
10 => 'Zhaobi',
11 => 'Gdpro',
12 => 'Boc',
13 => 'Ex'
13 => 'Ex',
14 => 'Zt'
];
/**
......@@ -82,7 +83,7 @@ class ExchangeBusiness
goto doEnd;
}
if (strtoupper($tag) == 'CIC' || strtoupper($tag) == 'RYH' || strtoupper($tag) == 'TSC' || strtoupper($tag) == 'WL' || strtoupper($tag) == 'ETS' || strtoupper($tag) == 'LIMS' || strtoupper($tag) == 'AT' || strtoupper($tag) == 'BTJ') {
if (strtoupper($tag) == 'RYH' || strtoupper($tag) == 'TSC' || strtoupper($tag) == 'WL' || strtoupper($tag) == 'ETS' || strtoupper($tag) == 'LIMS' || strtoupper($tag) == 'AT' || strtoupper($tag) == 'BTJ') {
$quotation = [
'low' => 0,
'high' => 0,
......@@ -157,6 +158,13 @@ class ExchangeBusiness
goto doEnd;
}
if (in_array(strtoupper($tag), ['CIC'])) {
$exchange = ExchangeFactory::createExchange("Zt");
$quotation = $exchange->getTicker('CIC', 'USDT');
$quotation['rmb'] = (float)sprintf("%0.2f", $quotation['last']);
goto doEnd;
}
if (in_array(strtoupper($tag), ['SJPY'])) {
$exchange = ExchangeFactory::createExchange("Boc");
$quotation = $exchange->getTicker('CNY', 'JPY');
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Zt extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_zt';
protected $quotation_prefix = 'quotation_zt_';
protected $base_url = 'https://www.zt.com/api/v1/tickers';
public function symbolExists($tag = 'CIC', $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 = 'CIC', $aim = 'USDT')
{
return strtoupper($tag .'_'. $aim);
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public function setSupportedSymbol()
{
$this->redis->sadd($this->supported_symbol, 'CICUSDT');
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public function setQuotation()
{
$curl = new Curl();
$content = $curl->get($this->base_url, false);
if (is_array($content) && isset($content['date']) && isset($content['ticker'])) {
$data = $content['ticker'];
foreach ($data as $item) {
if (in_array($item['symbol'], ['CIC_USDT'])) {
$data = $item;
$key = $this->quotation_prefix . $item['symbol'];
$this->redis->hmset($key, 'low', $data['low'], 'high', $data['high'], 'last', $data['last']);
$this->redis->sadd($this->supported_symbol, $item['symbol']);
}
}
}
}
}
\ 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