Commit dfd28bfe authored by shajiaming's avatar shajiaming

fix

parent 42b42f41
......@@ -2,6 +2,7 @@
namespace api\controllers;
use common\service\exchange\ExchangeFactory;
use Yii;
use api\base\BaseController;
use common\service\exchange\ExchangeBuilderFactory;
......@@ -32,4 +33,37 @@ class MarketController extends BaseController
return ['code' => $code, 'msg' => $msg, 'tick' => $ticker ?? []];
}
public function actionIndex()
{
$currency = Yii::$app->request->post('currency', '');
$base_currency = Yii::$app->request->post('base_currency', '');
$exchange = Yii::$app->request->post("exchange", 'Zhaobi');
if (false == $currency || false == $base_currency) {
$this->msg = 'invalid symbol';
$this->code = -1;
goto doEnd;
}
if (!in_array($exchange, Yii::$app->params['exchange'])) {
$this->msg = 'invalid exchange';
$this->code = -1;
goto doEnd;
}
$exchange = ExchangeFactory::createExchange($exchange);
$quotation = $exchange->getTicker($currency, 'USDT');
$quotation = [
'low' => (float)sprintf("%0.4f", $quotation['low'] / 100),
'high' => (float)sprintf("%0.4f", $quotation['high'] / 100),
'last' => (float)sprintf("%0.4f", $quotation['last'] / 100),
'rmb' => (float)sprintf("%0.2f", $quotation['last'] / 100),
];
echo json_encode($quotation);exit;
doEnd :
return ['code' => $this->code, 'msg' => $this->msg, 'tick' => $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