Commit 757ee175 authored by shajiaiming's avatar shajiaiming

test

parent 42b54414
...@@ -71,28 +71,24 @@ class WorkermanWebSocketController extends Controller ...@@ -71,28 +71,24 @@ class WorkermanWebSocketController extends Controller
if ('binance' == $data) { if ('binance' == $data) {
$con = new \Workerman\Connection\AsyncTcpConnection("ws://stream.binance.com:9443/ws/!ticker@arr"); $con = new \Workerman\Connection\AsyncTcpConnection("ws://stream.binance.com:9443/ws/!ticker@arr");
$con->transport = 'ssl'; $con->transport = 'ssl';
$con->onMessage = function($con, $data) use($connection) { $con->onMessage = function ($con, $data) use ($connection) {
$base_coin = [ $base_coin = [
'ETH', 'BTC', 'USDT', 'BTC' 'ETH', 'BTC', 'USDT', 'BTC'
]; ];
$result = json_decode($data, true); $result = json_decode($data, true);
$ticker = []; $ticker = [];
foreach ($result as $val) { foreach ($result as $val) {
go(function () use ($val, $base_coin) {
\Co::sleep(0.5);
foreach ($base_coin as $k => $coin) { foreach ($base_coin as $k => $coin) {
$explode_arr = explode($coin, $val['s']); $explode_arr = explode($coin, $val['s']);
if (2 == count($explode_arr) && empty($explode_arr[1])) { if (2 == count($explode_arr) && empty($explode_arr[1])) {
$ticker[$k]['symbol'] = $explode_arr[0] . '/' . $coin; $ticker[$val['s']]['symbol'] = $explode_arr[0] . '/' . $coin;
$ticker[$k]['close'] = (float)sprintf("%0.4f", $val['c']); $ticker[$val['s']]['close'] = (float)sprintf("%0.4f", $val['c']);
$ticker[$k]['change'] = (float)sprintf("%0.4f", $val['p'] * 100); $ticker[$val['s']]['change'] = (float)sprintf("%0.4f", $val['p'] * 100);
$ticker[$k]['high'] = (float)sprintf("%0.4f", $val['h']); $ticker[$val['s']]['high'] = (float)sprintf("%0.4f", $val['h']);
$ticker[$k]['low'] = (float)sprintf("%0.4f", $val['l']); $ticker[$val['s']]['low'] = (float)sprintf("%0.4f", $val['l']);
$ticker[$k]['vol'] = (float)sprintf("%0.4f", $val['v']); $ticker[$val['s']]['vol'] = (float)sprintf("%0.4f", $val['v']);
} }
} }
});
} }
$connection->send(date("Y-m-d H:i:s") . ' : ' . json_encode($ticker)); $connection->send(date("Y-m-d H:i:s") . ' : ' . json_encode($ticker));
}; };
......
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