Commit cc0863b0 authored by shajiaiming's avatar shajiaiming

fix

parent 1c395bc1
...@@ -94,11 +94,61 @@ class WorkermanWebSocketController extends Controller ...@@ -94,11 +94,61 @@ class WorkermanWebSocketController extends Controller
} }
} }
} }
$connection->send(date("Y-m-d H:i:s") . ' : ' . json_encode($ticker)); $connection->send('binance : ' . json_encode($ticker));
}; };
$con->connect(); $con->connect();
} elseif ('huobi' == $data) { } elseif ('huobi' == $data) {
$connection->send('huobi'); //$connection->websocketType = Websocket::BINARY_TYPE_ARRAYBUFFER;
// ssl需要访问443端口
$con = new \Workerman\Connection\AsyncTcpConnection('ws://api.huobi.pro:443/ws');
// 设置以ssl加密方式访问,使之成为wss
$con->transport = 'ssl';
$con->onConnect = function($con) {
$data = json_encode([
#'sub' => 'market.btcusdt.kline.1min',
#'id' => 'depth' . time(),
'sub' => 'market.overview'
]);
$con->send($data);
};
$con->onMessage = function($con, $data) use ($connection) {
$data = gzdecode($data);
$data = json_decode($data, true);
if(isset($data['ping'])) {
$con->send(json_encode([
"pong" => $data['ping']
]));
}else if (isset($data['ch']) && 'market.overview' == $data['ch']){
$base_coin = [
'ETH', 'BTC', 'USDT', 'BTY'
];
$ticker = [];
foreach ($data['data'] as $val) {
foreach ($base_coin as $k => $coin) {
$explode_arr = explode($coin, strtoupper($val['symbol']));
if (2 == count($explode_arr) && empty($explode_arr[1])) {
$temp = [];
$temp['symbol'] = $explode_arr[0] . '/' . $coin;
$temp['close'] = (float)sprintf("%0.4f", $val['close']);
$temp['change'] = (float)sprintf("%0.4f", ($val['close'] - $val['open']) / $val['open'] * 100);
$temp['high'] = (float)sprintf("%0.4f", $val['high']);
$temp['low'] = (float)sprintf("%0.4f", $val['low']);
$temp['vol'] = (float)sprintf("%0.4f", $val['vol']);
array_push($ticker, $temp);
break;
}
}
}
$connection->send('huobi : ' . json_encode($ticker));
} else {}
};
$con->onClose = function ($con){
echo "connection closed\n";
};
$con->onError = function($con, $code, $msg){
echo "Error code:$code msg:$msg\n";
};
$con->connect();
} elseif ('okex' == $data) { } elseif ('okex' == $data) {
$connection->websocketType = Websocket::BINARY_TYPE_ARRAYBUFFER; $connection->websocketType = Websocket::BINARY_TYPE_ARRAYBUFFER;
$con = new \Workerman\Connection\AsyncTcpConnection("ws://real.okex.com:8443/ws/v3"); $con = new \Workerman\Connection\AsyncTcpConnection("ws://real.okex.com:8443/ws/v3");
......
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