Commit 7c8ae3b7 authored by rlgy's avatar rlgy

接口更新

parent 20e6e1a8
...@@ -31,12 +31,12 @@ class CoinBTYService extends Coin implements CoinInterface ...@@ -31,12 +31,12 @@ class CoinBTYService extends Coin implements CoinInterface
public function quotation() public function quotation()
{ {
$result = [ $result = [
'price' => '',//价格 'price' => $this->getPrice(),//价格
'dollar' => '',//价格美元 'dollar' => $this->getDollar(),//价格美元
'btc' => '',//价格btc 'btc' => '',//价格btc
'high' => '',//最高价 'high' => $this->getHigh(),//最高价
'low' => '',//最低价 'low' => $this->getLow(),//最低价
'change' => '',//涨幅(跌幅) 'change' => $this->getChange(),//涨幅(跌幅)
'rank' => '',//流通市值排名 'rank' => '',//流通市值排名
'circulate_value_rmb' => '',//流通市值人民币 'circulate_value_rmb' => '',//流通市值人民币
'circulate_value_usd' => '',//流通市值美元 'circulate_value_usd' => '',//流通市值美元
...@@ -44,27 +44,6 @@ class CoinBTYService extends Coin implements CoinInterface ...@@ -44,27 +44,6 @@ class CoinBTYService extends Coin implements CoinInterface
'publish_count' => '',//发行总量 'publish_count' => '',//发行总量
'circulate_count' => '',//流通总量 'circulate_count' => '',//流通总量
]; ];
$ch = curl_init('https://kdata.zhaobi.com:4062/kdata?datafile=db&c=BTYUSDT&p=H1&action=init&count=24&ind=volumes&out=json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$content = curl_exec($ch);
$content = json_decode($content, true);
$content = $content['main']['y'];
$min = 10e9;
$max = 0;
foreach ($content as $item) {
for ($i = 0; $i < 4; $i++) {
$min = min($min, $item[$i]);
$max = max($max, $item[$i]);
}
}
$change = ($content[23][3] - $content[0][0]) / $content[0][0] * 100;
$result['dollar'] = $content[23][3];
$result['low'] = $min;
$result['high'] = $max;
$result['change'] = sprintf("%0.2f%%", $change);
return $result; return $result;
} }
...@@ -72,14 +51,31 @@ class CoinBTYService extends Coin implements CoinInterface ...@@ -72,14 +51,31 @@ class CoinBTYService extends Coin implements CoinInterface
{ {
$this->id = $id; $this->id = $id;
$this->sid = $sid; $this->sid = $sid;
$this->init();
} }
public function init() public function init()
{ {
$url = 'https://kdata.zhaobi.com:4062/kdata?datafile=db&c=BTYUSDT&p=H1&action=init&count=24&ind=volumes&out=json'; $key = $this->cache_key_prifx . $this->sid . 'all';
$ch = new Curl(); $result = Yii::$app->cache->get($key);
$content = $ch->get($url, false); if ($result === false) {
$this->content = $content; $url = 'https://zb2api.licai.cn/api/data/Ticker?sort=cname';
$ch = new Curl();
$content = $ch->get($url, false);
if (is_array($content) && isset($content['code']) && $content['code'] == 200) {
$data = $content['data']['USDT'];
foreach ($data as $item) {
if ($item['symbol'] == 'BTYUSDT') {
$data = $item;
break;
}
}
$this->content = $data;
Yii::$app->cache->set($key, $data, Yii::$app->params['curl_cache_time']['quotation']);
}
} else {
$this->content = $result;
}
} }
public function __destruct() public function __destruct()
...@@ -89,30 +85,25 @@ class CoinBTYService extends Coin implements CoinInterface ...@@ -89,30 +85,25 @@ class CoinBTYService extends Coin implements CoinInterface
public function getPrice() public function getPrice()
{ {
return 0; if ($this->content) {
$this->setPrice($this->content['lastrmb']);
} else {
return 0;
}
return $this->price;
} }
public function setPrice($price) public function setPrice($price)
{ {
return 0; return $this->price = "¥$price";
} }
public function getDollar() public function getDollar()
{ {
$key = $this->cache_key_prifx . $this->sid . '_usd'; if ($this->content) {
$result = Yii::$app->cache->get($key); $this->setDollar($this->content['last']);
if (!$result) {
if (empty($this->content)) {
$this->init();
}
if (is_array($this->content) && isset($this->content['main']['y'][23][3])) {
$this->setDollar($this->content['main']['y'][23][3]);
Yii::$app->cache->set($key, $this->dollar, Yii::$app->params['curl_cache_time']['quotation']);
} else {
$this->setDollar(0);
}
} else { } else {
return $result; return 0;
} }
return $this->dollar; return $this->dollar;
} }
...@@ -122,4 +113,50 @@ class CoinBTYService extends Coin implements CoinInterface ...@@ -122,4 +113,50 @@ class CoinBTYService extends Coin implements CoinInterface
$this->dollar = "≈\$$dollar"; $this->dollar = "≈\$$dollar";
} }
public function getHigh()
{
if ($this->content) {
$this->setHigh($this->content['high']);
} else {
return 0;
}
return $this->high;
}
public function setHigh($high)
{
return $this->high = "\$$high";
}
public function getLow()
{
if ($this->content) {
$this->setLow($this->content['low']);
} else {
return 0;
}
return $this->low;
}
public function setLow($low)
{
$this->low = "\$$low";
}
public function getChange()
{
if ($this->content) {
$this->setChange($this->content['range']);
} else {
return 0;
}
return $this->change;
}
public function setChange($change)
{
$this->change = "$change%";
}
} }
\ No newline at end of file
...@@ -66,7 +66,7 @@ class CoinYCCService extends Coin implements CoinInterface ...@@ -66,7 +66,7 @@ class CoinYCCService extends Coin implements CoinInterface
public function getPrice() public function getPrice()
{ {
return 0; return "¥0.2";
} }
public function setPrice($price) public function setPrice($price)
......
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