Commit 41e20e62 authored by shajiaiming's avatar shajiaiming

zhaobi ticker

parent 4a5e6f8d
<?php <?php
namespace common\service\exchange\factory;
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: jiaming * User: jiaming
...@@ -8,7 +6,52 @@ namespace common\service\exchange\factory; ...@@ -8,7 +6,52 @@ namespace common\service\exchange\factory;
* Time: 10:10 * Time: 10:10
*/ */
class Zhaobi namespace common\service\exchange\factory;
use common\service\exchange\ExchangeFactory;
use linslin\yii2\curl\Curl;
class ZhaobiBuilder
{ {
protected $base_url = 'https://api.biqianbao.top';
protected $base_coin = ['ETH', 'BTC', 'USDT', 'BTC', 'BTY'];
public function __construct()
{
}
public function getTicker()
{
$curl = new Curl();
$api = $this->base_url . '/api/data/Ticker?sort=cname';
$res = $curl->get($api, false);
$code = -1;
$ticker = [];
if (isset($res['message']) && 'OK' == $res['message']) {
$code = 0;
$ticker_temp = [];
foreach ($res['data'] as $val) {
$ticker_temp = array_merge($ticker_temp, $val);
}
foreach ($ticker_temp as $val) {
foreach ($this->base_coin as $k => $coin) {
$explode_arr = explode($coin, $val['symbol']);
if (2 == count($explode_arr) && empty($explode_arr[1])) {
$temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/' . $coin;
$temp['close'] = (float)sprintf("%0.4f", $val['last']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $val['lastrmb']);
$temp['change'] = (float)sprintf("%0.4f", ($val['last'] - $val['open']) / $val['open'] * 100);
$temp['high'] = (float)sprintf("%0.4f", $val['high']);
$temp['low'] = (float)sprintf("%0.4f", $val['low']);
$temp['vol'] = (float)sprintf("%0.4f", $val['vol']);
array_push($ticker, $temp);
break;
}
}
}
}
return ['code' => $code, 'ticker' => $ticker];
}
} }
\ 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