Commit df4639b1 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/ticker' into 'master'

Feature/ticker See merge request !289
parents 7dce0747 5a279562
...@@ -230,8 +230,7 @@ class ExchangeBusiness ...@@ -230,8 +230,7 @@ class ExchangeBusiness
if (in_array(strtoupper($tag), ['TSC'])) { if (in_array(strtoupper($tag), ['TSC'])) {
$exchange = ExchangeFactory::createExchange("Tsc"); $exchange = ExchangeFactory::createExchange("Tsc");
$quotation = $exchange->getTicker('TSC', 'CNDT'); $quotation = $exchange->getTicker('TSC', 'USDT');
$quotation['rmb'] = (float)sprintf("%0.4f", $quotation['last']);
goto doEnd; goto doEnd;
} }
...@@ -329,7 +328,7 @@ class ExchangeBusiness ...@@ -329,7 +328,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', 'KPC8', 'BVA', 'DAG', 'BNC', 'GHP', 'DRA', 'ETC', 'PAX', 'STH', 'XJH', 'SFT'])) { if (in_array(strtoupper($tag), ['FOLI', 'CIC', 'KPC8', 'BVA', 'DAG', 'BNC', 'GHP', 'DRA', 'ETC', 'PAX', 'STH', 'XJH', 'SFT', 'TSC'])) {
$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);
} else if (in_array(strtoupper($tag), ['SUSD'])) { } else if (in_array(strtoupper($tag), ['SUSD'])) {
......
...@@ -54,7 +54,8 @@ class WalletChain extends BaseActiveRecord ...@@ -54,7 +54,8 @@ class WalletChain extends BaseActiveRecord
[['platform', 'address', 'private_key', 'execer', 'brower_url', 'token', 'host', 'wallet_address', 'hash'], 'string'], [['platform', 'address', 'private_key', 'execer', 'brower_url', 'token', 'host', 'wallet_address', 'hash'], 'string'],
[['platform'], 'string', 'length' => [1, 30]], [['platform'], 'string', 'length' => [1, 30]],
[['token'], 'string', 'length' => [1, 10]], [['token'], 'string', 'length' => [1, 10]],
[['port', 'status', 'origin'], 'integer'] [['port', 'status', 'origin'], 'integer'],
['host', 'verfiyIp']
]; ];
} }
...@@ -66,4 +67,12 @@ class WalletChain extends BaseActiveRecord ...@@ -66,4 +67,12 @@ class WalletChain extends BaseActiveRecord
]; ];
return array_merge(parent:: scenarios(), $scenarios); return array_merge(parent:: scenarios(), $scenarios);
} }
public function verfiyIp($attribute, $params)
{
if (!preg_match('/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/', $this->host)) {
$this->addError($attribute, '错误的Ip地址');
return false;
}
}
} }
\ No newline at end of file
...@@ -16,7 +16,7 @@ class Tsc extends Exchange implements ExchangeInterface ...@@ -16,7 +16,7 @@ class Tsc extends Exchange implements ExchangeInterface
protected $quotation_prefix = 'quotation_tsc_'; protected $quotation_prefix = 'quotation_tsc_';
protected $base_url = 'https://api.tsc100.vip/openapi/quote/v1/ticker/24hr'; protected $base_url = 'https://api.tsc100.vip/openapi/quote/v1/ticker/24hr';
public function symbolExists($tag = 'TSC', $aim = "CNDT") public function symbolExists($tag = 'TSC', $aim = "USDT")
{ {
$supported = $this->redis->smembers($this->supported_symbol); $supported = $this->redis->smembers($this->supported_symbol);
if (is_array($supported) && in_array($this->formatSymbol($tag, $aim), $supported)) { if (is_array($supported) && in_array($this->formatSymbol($tag, $aim), $supported)) {
...@@ -31,9 +31,9 @@ class Tsc extends Exchange implements ExchangeInterface ...@@ -31,9 +31,9 @@ class Tsc extends Exchange implements ExchangeInterface
* @param string $aim * @param string $aim
* @return mixed * @return mixed
*/ */
public function formatSymbol($tag = 'TSC', $aim = 'CNDT') public function formatSymbol($tag = 'TSC', $aim = 'USDT')
{ {
return strtoupper($tag .'_'. $aim); return strtoupper($tag . $aim);
} }
/** /**
...@@ -43,7 +43,7 @@ class Tsc extends Exchange implements ExchangeInterface ...@@ -43,7 +43,7 @@ class Tsc extends Exchange implements ExchangeInterface
*/ */
public function setSupportedSymbol() public function setSupportedSymbol()
{ {
$this->redis->sadd($this->supported_symbol, 'TSC_CNDT');
} }
/** /**
...@@ -57,11 +57,10 @@ class Tsc extends Exchange implements ExchangeInterface ...@@ -57,11 +57,10 @@ class Tsc extends Exchange implements ExchangeInterface
$content = $curl->get($this->base_url, false); $content = $curl->get($this->base_url, false);
if (is_array($content)) { if (is_array($content)) {
foreach ($content as $item) { foreach ($content as $item) {
if (in_array($item['symbol'], ['TSCCNDT'])) { $key = $this->quotation_prefix . strtoupper($item['symbol']);
$data = $item; $this->redis->hmset($key, 'low', $item['lowPrice'], 'high', $item['highPrice'], 'last', $item['lastPrice']);
$key = $this->quotation_prefix .'TSC_CNDT'; if (!$this->redis->sismember($this->supported_symbol, strtoupper($item['symbol']))){
$this->redis->hmset($key, 'low', $data['lowPrice'], 'high', $data['highPrice'], 'last', $data['lastPrice']); $this->redis->sadd($this->supported_symbol, strtoupper($item['symbol']));
$this->redis->sadd($this->supported_symbol, $item['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