Commit 6784b098 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/ws_ticker' into 'master'

自选行情加分页 See merge request !128
parents e8227176 1474ccf7
......@@ -2,11 +2,10 @@
namespace api\controllers;
use common\business\Chain33Business;
use common\models\psources\CoinGameBet;
use Yii;
use api\base\BaseController;
use yii\data\Pagination;
use api\base\BaseController;
use common\models\psources\CoinGameBet;
class GameBetController extends BaseController
{
......
......@@ -2,13 +2,14 @@
namespace api\controllers;
use linslin\yii2\curl\Curl;
use Yii;
use yii\data\Pagination;
use linslin\yii2\curl\Curl;
use yii\helpers\ArrayHelper;
use api\base\BaseController;
use common\models\psources\CoinOptional;
use common\service\exchange\ExchangeFactory;
use common\service\exchange\ExchangeBuilderFactory;
use yii\helpers\ArrayHelper;
class TickerController extends BaseController
{
......@@ -102,14 +103,30 @@ class TickerController extends BaseController
if ($request->isGet) {
$device_code = $request->get('device_code', '');
$page = Yii::$app->request->get('page', 1);
if (empty($device_code)) {
$msg = '参数错误';
goto doEnd;
}
$data = $temp = [];
$model = CoinOptional::find()->select('symbol, platform')->where(['device_code' => $device_code])->asArray()->all();
foreach ($model as $val) {
$temp = [];
$query = CoinOptional::find()->select('symbol, platform')
->where(['device_code' => $device_code])
->orderBy('update_time desc');
$data = $query->offset(($page - 1) * 50)->limit(50)->asArray()->all();
if (false == $data) {
$msg = 'success';
$code = 0;
$data = [
'ticker' => [],
'page' => [
'pageSize' => 50,
'currentPage' => (int)$page,
]
];
goto doEnd;
}
$ticker = [];
foreach ($data as $val) {
if ('huobi' == $val['platform']) {
$exchange = 'HuoBi';
} else if ('binance' == $val['platform']) {
......@@ -129,7 +146,7 @@ class TickerController extends BaseController
$temp['symbol'] = $val['symbol'];
$temp['currency'] = strtoupper($tag_first);
$temp['base_currency'] = strtoupper($tag_second);
$temp['close'] = (float)sprintf("%0.6f", $quotation['last']);
$temp['close'] = number_format($quotation['last'], 6, '.', '');
$temp['close_usd'] = (float)sprintf("%0.6f", $quotation['last'] * $this->basic_price[$tag_second]['usd']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $quotation['last'] * $this->basic_price[$tag_second]['rmb']);
$temp['change'] = (0 == $quotation['open']) ? 0 : (float)sprintf("%0.4f", ($quotation['last'] - $quotation['open']) / $quotation['open'] * 100);
......@@ -150,11 +167,20 @@ class TickerController extends BaseController
$temp['platform_zh'] = '币安';
$temp['platform_us'] = 'binance';
}
array_push($data, $temp);
array_push($ticker, $temp);
}
}
$data = [
'ticker' => $ticker,
'page' => [
'pageSize' => 50,
'currentPage' => (int)$page,
]
];
$msg = 'success';
$code = 0;
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
......
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