Commit 059787da authored by shajiaiming's avatar shajiaiming

修复已知问题

parent 6f124e09
...@@ -76,8 +76,8 @@ class BinanceBuilder extends FactoryService ...@@ -76,8 +76,8 @@ class BinanceBuilder extends FactoryService
$temp['symbol'] = strtoupper($explode_arr[0]) . '/' . $coin; $temp['symbol'] = strtoupper($explode_arr[0]) . '/' . $coin;
$temp['currency'] = strtoupper($explode_arr[0]); $temp['currency'] = strtoupper($explode_arr[0]);
$temp['base_currency'] = strtoupper($coin); $temp['base_currency'] = strtoupper($coin);
$temp['close'] = $this->sctonum($close, 8); $temp['close'] = rtrim(sprintf('%.8f', floatval($close)),'0');
$temp['close_usd'] = (float)sprintf("%0.6f", $close * $this->basic_price[$coin]['usd']); $temp['close_usd'] = rtrim(sprintf('%.6f', floatval($close * $this->basic_price[$coin]['usd'])),'0');
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']); $temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']);
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100); $temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['usd']); $temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['usd']);
...@@ -110,9 +110,10 @@ class BinanceBuilder extends FactoryService ...@@ -110,9 +110,10 @@ class BinanceBuilder extends FactoryService
for ($i = 0; $i < $len; $i++) { for ($i = 0; $i < $len; $i++) {
$symbol = $this->redis->lindex($this->supported_symbol_list, $i); $symbol = $this->redis->lindex($this->supported_symbol_list, $i);
list($close, $open, $low, $high, $vol) = $this->redis->hmget($this->quotation_prefix . strtolower($symbol), 'last', 'open', 'low', 'high', 'vol'); list($close, $open, $low, $high, $vol) = $this->redis->hmget($this->quotation_prefix . strtolower($symbol), 'last', 'open', 'low', 'high', 'vol');
if ('0.00000000' == $close) continue;
$temp = []; $temp = [];
$temp['symbol'] = strtoupper($symbol); $temp['symbol'] = strtoupper($symbol);
$temp['close'] = number_format($close, 6, '.', ''); $temp['close'] = $close;
$temp['low'] = $low; $temp['low'] = $low;
$temp['high'] = $high; $temp['high'] = $high;
$temp['open'] = $open; $temp['open'] = $open;
...@@ -139,14 +140,4 @@ class BinanceBuilder extends FactoryService ...@@ -139,14 +140,4 @@ class BinanceBuilder extends FactoryService
$this->redis_ticker->rpush($this->supported_symbol_change_desc, strtoupper($val['symbol'])); $this->redis_ticker->rpush($this->supported_symbol_change_desc, strtoupper($val['symbol']));
} }
} }
protected function sctonum($num, $double = 5)
{
if (false !== strpos($num, "e")) {
$a = explode("e", strtolower($num));
return bcmul($a[0], bcpow(10, $a[1], $double), $double);
} else {
return number_format($num, 6, '.', '');
}
}
} }
\ No newline at end of file
...@@ -97,8 +97,8 @@ class HuobiBuilder extends FactoryService ...@@ -97,8 +97,8 @@ class HuobiBuilder extends FactoryService
$temp['symbol'] = strtoupper($explode_arr[0]) . '/' . $coin; $temp['symbol'] = strtoupper($explode_arr[0]) . '/' . $coin;
$temp['currency'] = strtoupper($explode_arr[0]); $temp['currency'] = strtoupper($explode_arr[0]);
$temp['base_currency'] = strtoupper($coin); $temp['base_currency'] = strtoupper($coin);
$temp['close'] = $this->sctonum($close, 8); $temp['close'] = rtrim(sprintf('%.8f', floatval($close)),'0');
$temp['close_usd'] = (float)sprintf("%0.6f", $close * $this->basic_price[$coin]['usd']); $temp['close_usd'] = rtrim(sprintf('%.6f', floatval($close * $this->basic_price[$coin]['usd'])),'0');
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']); $temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']);
$temp['change'] = (false == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100); $temp['change'] = (false == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['usd']); $temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['usd']);
...@@ -131,9 +131,10 @@ class HuobiBuilder extends FactoryService ...@@ -131,9 +131,10 @@ class HuobiBuilder extends FactoryService
for ($i = 0; $i < $len; $i++) { for ($i = 0; $i < $len; $i++) {
$symbol = $this->redis->lindex($this->supported_symbol_list, $i); $symbol = $this->redis->lindex($this->supported_symbol_list, $i);
list($close, $open, $low, $high, $vol) = $this->redis->hmget($this->quotation_prefix . strtolower($symbol), 'last', 'open', 'low', 'high', 'vol'); list($close, $open, $low, $high, $vol) = $this->redis->hmget($this->quotation_prefix . strtolower($symbol), 'last', 'open', 'low', 'high', 'vol');
if ('0.00000000' == $close) continue;
$temp = []; $temp = [];
$temp['symbol'] = strtoupper($symbol); $temp['symbol'] = strtoupper($symbol);
$temp['close'] = number_format($close, 6, '.', ''); $temp['close'] = $close;
$temp['low'] = $low; $temp['low'] = $low;
$temp['high'] = $high; $temp['high'] = $high;
$temp['open'] = $open; $temp['open'] = $open;
...@@ -192,14 +193,4 @@ class HuobiBuilder extends FactoryService ...@@ -192,14 +193,4 @@ class HuobiBuilder extends FactoryService
} }
return ['code' => $this->code, 'ticker' => $ticker]; return ['code' => $this->code, 'ticker' => $ticker];
} }
protected function sctonum($num, $double = 5)
{
if (false !== stripos($num, "e")) {
$a = explode("e", strtolower($num));
return bcmul($a[0], bcpow(10, $a[1], $double), $double);
} else {
return number_format($num, 6, '.', '');
}
}
} }
...@@ -14,7 +14,7 @@ class TickerController extends Controller ...@@ -14,7 +14,7 @@ class TickerController extends Controller
{ {
public function actionSort() public function actionSort()
{ {
$class = ['Binance', 'Huobi', 'Zhaobi']; $class = ['Binance'];
foreach ($class as $val) { foreach ($class as $val) {
go(function () use ($val) { go(function () use ($val) {
\Co::sleep(0.5); \Co::sleep(0.5);
......
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