Commit cd7dbc65 authored by shajiaiming's avatar shajiaiming

dra ticker

parent 278e6789
...@@ -45,6 +45,7 @@ class ExchangeBusiness ...@@ -45,6 +45,7 @@ class ExchangeBusiness
16 => 'Bitnasdaq', 16 => 'Bitnasdaq',
17 => 'Dag', 17 => 'Dag',
18 => 'Boc', 18 => 'Boc',
19 => 'Draex'
//7 => 'S',//已挂 //7 => 'S',//已挂
//11 => 'Gdpro',//已挂 //11 => 'Gdpro',//已挂
//16 => 'Ceohk', //已挂 //16 => 'Ceohk', //已挂
...@@ -115,6 +116,12 @@ class ExchangeBusiness ...@@ -115,6 +116,12 @@ class ExchangeBusiness
} }
$f = false; $f = false;
$quotation = []; $quotation = [];
if (in_array(strtoupper($tag), ['DRA'])) {
$exchange = ExchangeFactory::createExchange("Draex");
$quotation = $exchange->getTicker($tag, 'USDT');
$quotation['rmb'] = (float)sprintf("%0.4f", $quotation['last']);
goto doEnd;
}
if (in_array(strtoupper($tag), ['FOLI'])) { if (in_array(strtoupper($tag), ['FOLI'])) {
$exchange = ExchangeFactory::createExchange("Ex"); $exchange = ExchangeFactory::createExchange("Ex");
...@@ -296,7 +303,7 @@ class ExchangeBusiness ...@@ -296,7 +303,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'])) { if (in_array(strtoupper($tag), ['FOLI', 'CIC', 'KPC8', 'BVA', 'DAG', 'BNC', 'GHP', 'DRA'])) {
$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-6-26
* Time: 下午7:21
*/
namespace common\service\exchange;
use Yii;
use linslin\yii2\curl\Curl;
class Draex extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_draex';
protected $quotation_prefix = 'quotation_draex_';
protected $base_url = 'https://www.draex.co';
public function formatSymbol($tag = 'DRA', $aim = 'USDT')
{
return strtolower(trim($tag) . trim($aim));
}
public function setSupportedSymbol()
{
$curl = new Curl();
$api = $this->base_url . 'm/symbol';
$res = $curl->get($api, false);//json
if (is_array($res) && isset($res['state']) && 1 == $res['state']) {
foreach ($res as $item) {
$this->redis->sadd($this->supported_symbol, strtolower($item['symbol']));
}
}
}
public function setQuotation()
{
$curl = new Curl();
$api = $this->base_url . '/m/allticker/' . time();
$res = $curl->get($api, false);
if (is_array($res) && isset($res['state']) && 1 == $res['state']) {
$data = $res['data'];
foreach ($data as $key => $item) {
$low = isset($item['low']) ? $item['low'] : 0;
$high = isset($item['high']) ? $item['high'] : 0;
$last = isset($item['close']) ? $item['close'] : 0;
$open = isset($item['open']) ? $item['open'] : 0;
$vol = isset($item['volume']) ? $item['volume'] : 0;
$cache_key = strtolower($this->quotation_prefix . $item['symbol']);
$this->redis->hmset($cache_key, 'low', $low, 'high', $high, 'last', $last, 'open', $open, 'vol', $vol);
$this->redis->sadd($this->supported_symbol, $item['symbol']);
}
}
}
}
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