Commit 5e778b6b authored by shajiaiming's avatar shajiaiming

usd ticker

parent ca5ac7bc
......@@ -121,6 +121,13 @@ class ExchangeBusiness
return $quotation;
}
if(in_array(strtoupper($tag),['USDT'])){
$exchange = ExchangeFactory::createExchange("Go");
$quotation = $exchange->getTicker('CNY', 'USD');
$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 Boc extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_boc';
protected $quotation_prefix = 'boc';
protected $base_url = 'http://srh.bankofchina.com/search/whpj/search.jsp';
public function symbolExists($tag = 'CNY', $aim = "JPY")
{
$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 = 'CNY', $aim = 'JPY')
{
return strtoupper($tag .'_'. $aim);
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public function setSupportedSymbol()
{
$this->redis->sadd($this->supported_symbol, 'CNYJPY');
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public function setQuotation()
{
$curl = new Curl();
$response = $curl->setPostParams([
'erectDate' => '',
'nothing' => '',
'pjname' => 1323
])->post('http://srh.bankofchina.com/search/whpj/search.jsp');
var_dump($response);exit;
if (is_array($content) && isset($content['data']) && 200 == $content['code']) {
$data = $content['data'];
$key = $this->quotation_prefix . 'CNY_JPY';
$this->redis->hmset($key, 'low', $data['low'], 'high', $data['high'], 'last', $data['last']);
$this->redis->sadd($this->supported_symbol, 'CNYJPY');
}
}
}
\ 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