Commit 835f3927 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/ticker' into 'master'

add zhaobi ticker See merge request !28
parents 8af554af 867de7a8
......@@ -35,7 +35,8 @@ class ExchangeBusiness
6 => 'Token7',
7 => 'S',
8 => 'Zg',
9 => 'Go'
9 => 'Go',
10 => 'Zhaobi'
];
/**
......@@ -105,6 +106,13 @@ class ExchangeBusiness
return $quotation;
}
if(in_array(strtoupper($tag),['SFT'])){
$exchange = ExchangeFactory::createExchange("Zhaobi");
$quotation = $exchange->getTicker($tag, 'CNY');
$quotation['rmb'] = (float)sprintf("%0.2f", $quotation['last']);
return $quotation;
}
foreach (self::$exchanges as $exchange) {
/**
* @var $exchange \common\service\exchange\Exchange
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Zhaobi extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_zhaobi';
protected $quotation_prefix = 'quotation_zhaobi_';
protected $base_url = 'https://api.biqianbao.top/api/data/basecoinprice?base=CNY&coin=SFT&platform=zhaobi';
public function symbolExists($tag = 'SFT', $aim = "CNY")
{
$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 = 'SFT', $aim = 'CNY')
{
return strtoupper($tag .'_'. $aim);
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public function setSupportedSymbol()
{
$this->redis->sadd($this->supported_symbol, 'SFT_CNY');
}
/**
* 更新交易对行情保存到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'][0];
$key = $this->quotation_prefix . 'SFT_CNY';
$this->redis->hmset($key, 'low', $data['value'], 'high', $data['value'], 'last', $data['value']);
$this->redis->sadd($this->supported_symbol, 'SFT_CNY');
}
}
}
\ 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