Commit f870841c authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/ticker' into 'master'

add new tsc ticker See merge request !94
parents dc3d70cb bb2ed89b
......@@ -40,7 +40,8 @@ class ExchangeBusiness
11 => 'Gdpro',
12 => 'Boc',
13 => 'Ex',
14 => 'Zt'
14 => 'Zt',
15 => 'Tsc'
];
/**
......@@ -83,7 +84,7 @@ class ExchangeBusiness
goto doEnd;
}
if (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) == 'WL' || strtoupper($tag) == 'ETS' || strtoupper($tag) == 'LIMS' || strtoupper($tag) == 'AT' || strtoupper($tag) == 'BTJ') {
$quotation = [
'low' => 0,
'high' => 0,
......@@ -164,6 +165,13 @@ class ExchangeBusiness
goto doEnd;
}
if (in_array(strtoupper($tag), ['TSC'])) {
$exchange = ExchangeFactory::createExchange("Tsc");
$quotation = $exchange->getTicker('TSC', 'CNDT');
$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 Tsc extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_tsc';
protected $quotation_prefix = 'quotation_tsc_';
protected $base_url = 'https://api.tsc100.vip/openapi/quote/v1/ticker/24hr';
public function symbolExists($tag = 'TSC', $aim = "CNDT")
{
$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 = 'TSC', $aim = 'CNDT')
{
return strtoupper($tag .'_'. $aim);
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public function setSupportedSymbol()
{
$this->redis->sadd($this->supported_symbol, 'TSCCNDT');
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public function setQuotation()
{
$curl = new Curl();
$content = $curl->get($this->base_url, false);
if (is_array($content)) {
foreach ($content as $item) {
if (in_array($item['symbol'], ['TSCCNDT'])) {
$data = $item;
$key = $this->quotation_prefix . $item['symbol'];
$this->redis->hmset($key, 'low', $data['lowPrice'], 'high', $data['highPrice'], 'last', $data['lastPrice']);
$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