Commit 01ec0d92 authored by shajiaiming's avatar shajiaiming

找币行情单独获取

parent 7902a899
<?php
namespace api\controllers;
use Yii;
use api\base\BaseController;
use common\service\exchange\ExchangeBuilderFactory;
class MarketController extends BaseController
{
public function actionDetail()
{
$symbol = Yii::$app->request->get('symbol', '');
if (false == $symbol) {
$msg = 'invalid symbol';
$code = -1;
goto doEnd;
}
$builder = ExchangeBuilderFactory::create('Zhaobi');
$result = $builder->getDetail($symbol);
if (-1 == $result['code']){
$msg = 'invalid symbol';
$code = -1;
goto doEnd;
}
$code = 0;
$msg = 'ok';
$ticker = $result['ticker'];
doEnd :
return ['code' => $code, 'msg' => $msg, 'tick' => $ticker ?? []];
}
}
\ No newline at end of file
......@@ -344,6 +344,7 @@ class ExchangeBusiness
public static function setQuotation()
{
foreach (self::$exchanges as $exchange) {
if ('ZHAOBI' == strtoupper($exchange)) continue;
/**
* @var $exchange \common\service\exchange\ExchangeInterface
*/
......
......@@ -167,6 +167,22 @@ class ZhaobiBuilder extends FactoryService
return ['code' => $this->code, 'notice' => $data];
}
public function getDetail($symbol)
{
list($low, $high, $close, $open, $vol) = $this->redis->hmget($this->quotation_prefix . strtolower($symbol), 'low', 'high', 'last', 'open', 'vol');
if (empty($low) && empty($high) && empty($close) && empty($open) && empty($vol)) {
return ['code' => $this->code, 'ticker' => []];
}
$ticker = [
'vol' => $vol,
'low' => $low,
'open' => $open,
'high' => $high,
'close' => $close
];
return ['code' => 0, 'ticker' => $ticker];
}
public function getHotTicker($symbol = [])
{
if (empty($symbol)) {
......
......@@ -2,6 +2,7 @@
namespace console\controllers;
use common\service\exchange\ExchangeFactory;
use Yii;
use linslin\yii2\curl\Curl;
use yii\console\Controller;
......@@ -33,6 +34,14 @@ class TickerController extends Controller
return 0;
}
public function actionExchange($exchange)
{
$ticker_builder = ExchangeFactory::createExchange($exchange);
$ticker_builder->setQuotation();
echo date('Y-m-d H:i:s') . $exchange. '更新成功' . PHP_EOL;
return 0;
}
public function actionCurrency()
{
$currency_model = CoinSupportedCurrency::find()->groupBy('currency_id')->all();
......
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