Commit 6575d4c5 authored by shajiaiming's avatar shajiaiming

okex ticker

parent 757ee175
......@@ -5,6 +5,7 @@ namespace console\controllers;
use Workerman\Worker;
use yii\helpers\Console;
use yii\console\Controller;
use Workerman\Protocols\Websocket;
class WorkermanWebSocketController extends Controller
{
......@@ -96,7 +97,26 @@ class WorkermanWebSocketController extends Controller
} elseif ('huobi' == $data) {
$connection->send('huobi');
} elseif ('okex' == $data) {
$connection->send('okex');
$connection->websocketType = Websocket::BINARY_TYPE_ARRAYBUFFER;
$con = new \Workerman\Connection\AsyncTcpConnection("ws://real.okex.com:8443/ws/v3");
$con->transport = 'ssl';
$con->onConnect = function($con) {
$data = json_encode([
'op' => 'subscribe',
'args' => [
'spot/all_ticker_3s',
'futures/all_ticker_3s',
'index/all_ticker_3s',
'futures/delivery:BTC'
]
]);
$con->send("{\"op\":\"subscribe\",\"args\":[\"spot/all_ticker_3s\",\"futures/all_ticker_3s\",\"index/all_ticker_3s\",\"futures/delivery:BTC\"]}");
};
$con->onMessage = function ($con, $data) use ($connection) {
$data = gzdecode($data);
$connection->send(date("Y-m-d H:i:s") . ' : ' . json_encode($data));
};
$con->connect();
} else {
$connection->send('other');
}
......
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