Commit 4a5e6f8d authored by shajiaiming's avatar shajiaiming

加入人民币价格

parent 96a8808d
......@@ -8,6 +8,7 @@
namespace common\service\exchange\factory;
use common\service\exchange\ExchangeFactory;
use linslin\yii2\curl\Curl;
class BinanceBuilder
......@@ -29,6 +30,9 @@ class BinanceBuilder
$ticker = [];
if (is_array($res)) {
$code = 0;
$exchange = ExchangeFactory::createExchange("Go");
$rate = $exchange->getTicker("CNY", "USD");
$cny_usd_rate = 1 / $rate['last'];
foreach ($res as $val) {
foreach ($this->base_coin as $k => $coin) {
$explode_arr = explode($coin, $val['symbol']);
......@@ -36,6 +40,7 @@ class BinanceBuilder
$temp = [];
$temp['symbol'] = $explode_arr[0] . '/' . $coin;
$temp['close'] = (float)sprintf("%0.4f", $val['lastPrice']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $val['lastPrice'] / $cny_usd_rate);
$temp['change'] = (float)sprintf("%0.4f", $val['priceChangePercent']);
$temp['high'] = (float)sprintf("%0.4f", $val['highPrice']);
$temp['low'] = (float)sprintf("%0.4f", $val['lowPrice']);
......
......@@ -8,6 +8,7 @@
namespace common\service\exchange\factory;
use common\service\exchange\ExchangeFactory;
use linslin\yii2\curl\Curl;
class HuobiBuilder
......@@ -29,6 +30,9 @@ class HuobiBuilder
$ticker = [];
if (isset($res['status']) && 'ok' == $res['status']) {
$code = 0;
$exchange = ExchangeFactory::createExchange("Go");
$rate = $exchange->getTicker("CNY", "USD");
$cny_usd_rate = 1 / $rate['last'];
foreach ($res['data'] as $val) {
foreach ($this->base_coin as $k => $coin) {
$explode_arr = explode(strtolower($coin), $val['symbol']);
......@@ -36,6 +40,7 @@ class HuobiBuilder
$temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/' . $coin;
$temp['close'] = (float)sprintf("%0.4f", $val['close']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $val['close'] / $cny_usd_rate);
$temp['change'] = (float)sprintf("%0.4f", ($val['close'] - $val['open']) / $val['open'] * 100);
$temp['high'] = (float)sprintf("%0.4f", $val['high']);
$temp['low'] = (float)sprintf("%0.4f", $val['low']);
......
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