Commit 0e16c28d authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/ticker' into 'master'

sth See merge request !275
parents 909a6268 cdc1b476
...@@ -44,7 +44,8 @@ class ExchangeBusiness ...@@ -44,7 +44,8 @@ class ExchangeBusiness
15 => 'Bilaxy', 15 => 'Bilaxy',
16 => 'Bitnasdaq', 16 => 'Bitnasdaq',
17 => 'Dag', 17 => 'Dag',
18 => 'Boc', 18 => 'Coinka',
19 => 'Boc',
//1 => 'Hadax', //不需要 //1 => 'Hadax', //不需要
//2 => 'Bitfinex', //不需要 //2 => 'Bitfinex', //不需要
...@@ -219,6 +220,12 @@ class ExchangeBusiness ...@@ -219,6 +220,12 @@ class ExchangeBusiness
goto doEnd; goto doEnd;
} }
if (in_array(strtoupper($tag), ['STH'])) {
$exchange = ExchangeFactory::createExchange("Coinka");
$quotation = $exchange->getTicker('sth', 'usdt');
goto doEnd;
}
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', 'CNDT');
...@@ -320,7 +327,7 @@ class ExchangeBusiness ...@@ -320,7 +327,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'])) { if (in_array(strtoupper($tag), ['FOLI', 'CIC', 'KPC8', 'BVA', 'DAG', 'BNC', 'GHP', 'DRA', 'ETC', 'PAX', 'STH'])) {
$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'])) {
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Coinka extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_coinka';
protected $quotation_prefix = 'quotation_coinka_';
protected $base_url = 'https://app.coinka.com.cn/api/v1/allticker';
public function symbolExists($tag = 'STH', $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 = 'STH', $aim = 'USDT')
{
return $tag . '_' . $aim;
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public function setSupportedSymbol()
{
$this->redis->sadd($this->supported_symbol, 'STHUSDT');
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public function setQuotation()
{
$curl = new Curl();
$content = $curl->get($this->base_url, false);
if (is_array($content) && isset($content['ticker'])) {
$data = $content['ticker'];
foreach ($data as $item) {
if (in_array(strtoupper($item['symbol']), ['STH_USDT'])) {
$data = $item;
$key = $this->quotation_prefix . $item['symbol'];
$this->redis->hmset($key, 'low', $data['low'], 'high', $data['high'], 'last', $data['last'], 'change', $data['change'], 'vol', $data['vol']);
$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