Commit fe203395 authored by rlgy's avatar rlgy

BTY行情

parent c01d0568
......@@ -8,6 +8,9 @@
namespace common\service\coin;
use common\helpers\Curl;
use Yii;
class CoinBTYService extends Coin implements CoinInterface
{
public function exchange()
......@@ -67,37 +70,56 @@ class CoinBTYService extends Coin implements CoinInterface
public function __construct($id, $sid)
{
$this->id = $id;
$this->sid = $sid;
}
public function init()
{
// TODO: Implement init() method.
$url = 'https://kdata.zhaobi.com:4062/kdata?datafile=db&c=BTYUSDT&p=H1&action=init&count=24&ind=volumes&out=json';
$ch = new Curl();
$content = $ch->get($url, false);
$this->content = $content;
}
public function __destruct()
{
// TODO: Implement __destruct() method.
unset($this->content);
}
public function getPrice()
{
return parent::getPrice(); // TODO: Change the autogenerated stub
return 0;
}
public function setPrice($price)
{
parent::setPrice($price); // TODO: Change the autogenerated stub
return 0;
}
public function getDollar()
{
return parent::getDollar(); // TODO: Change the autogenerated stub
$key = $this->cache_key_prifx . $this->sid . '_usd';
$result = Yii::$app->cache->get($key);
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 {
return $result;
}
return $this->dollar;
}
public function setDollar($dollar)
{
parent::setDollar($dollar); // TODO: Change the autogenerated stub
$this->dollar = "≈\$$dollar";
}
}
\ 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