Commit 99c5b3db authored by shajiaming's avatar shajiaming

Merge branch 'feature/optimize' into develop

parents e03bbbc0 2a0ad4fc
...@@ -34,6 +34,13 @@ class MarketController extends BaseController ...@@ -34,6 +34,13 @@ class MarketController extends BaseController
return ['code' => $code, 'msg' => $msg, 'tick' => $ticker ?? []]; return ['code' => $code, 'msg' => $msg, 'tick' => $ticker ?? []];
} }
public function actionExchange()
{
$exchanges = Yii::$app->params['exchange'];
return ['code' => $this->code, 'msg' => $this->msg, 'data' => $exchanges];
}
public function actionIndex() public function actionIndex()
{ {
$currency = Yii::$app->request->post('currency', ''); $currency = Yii::$app->request->post('currency', '');
...@@ -45,6 +52,12 @@ class MarketController extends BaseController ...@@ -45,6 +52,12 @@ class MarketController extends BaseController
goto doEnd; goto doEnd;
} }
if (false == $exchange || !in_array($exchange, Yii::$app->params['exchange'])) {
$this->msg = 'invalid exchange';
$this->code = -1;
goto doEnd;
}
$exchange = ExchangeFactory::createExchange($exchange); $exchange = ExchangeFactory::createExchange($exchange);
$currency_ticker = $exchange->getTicker($currency, 'USDT'); $currency_ticker = $exchange->getTicker($currency, 'USDT');
$base_currency_ticker = $exchange->getTicker($base_currency, 'USDT'); $base_currency_ticker = $exchange->getTicker($base_currency, 'USDT');
...@@ -67,10 +80,11 @@ class MarketController extends BaseController ...@@ -67,10 +80,11 @@ class MarketController extends BaseController
'rmb' => (float)sprintf("%0.2f", $base_currency_ticker['last']), 'rmb' => (float)sprintf("%0.2f", $base_currency_ticker['last']),
]; ];
$this->data = (float)sprintf("%0.4f",$currency_quotation['last'] / $base_currency_quotation['last']); $this->data = rtrim(sprintf('%.6f',$currency_quotation['last'] / $base_currency_quotation['last']), '0');
doEnd : doEnd :
return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data]; return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data];
} }
} }
\ 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