|
...
|
...
|
@@ -23,6 +23,8 @@ class ExBroker |
|
|
|
private OkxApi $api;
|
|
|
|
private ?Websocket $wsAcc;
|
|
|
|
private ?Websocket $wsKline;
|
|
|
|
private $timerAccPing = 0;
|
|
|
|
private $timerKlinePing = 0;
|
|
|
|
|
|
|
|
public function __construct($apiInfo)
|
|
|
|
{
|
|
...
|
...
|
@@ -47,12 +49,15 @@ class ExBroker |
|
|
|
$this->wsAcc->connect(
|
|
|
|
$onOpen = function () {
|
|
|
|
$this->wsLogin();
|
|
|
|
//开始定时ping
|
|
|
|
$this->wsAccPing();
|
|
|
|
},
|
|
|
|
$onMessage = function ($data) use ($onWsData) {
|
|
|
|
$this->onWsDataPre($data, $onWsData);
|
|
|
|
},
|
|
|
|
$onClose = function () {
|
|
|
|
// 关闭链接
|
|
|
|
swoole_timer_clear($this->timerAccPing);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
...
|
...
|
@@ -74,6 +79,8 @@ class ExBroker |
|
|
|
];
|
|
|
|
output("订阅", $subData);
|
|
|
|
$this->wsKline->push(json_encode($subData));
|
|
|
|
//开始定时ping
|
|
|
|
$this->wsKlinePing();
|
|
|
|
},
|
|
|
|
$onMessage = function ($data) use ($onData) {
|
|
|
|
$data = json_decode($data, true);
|
|
...
|
...
|
@@ -84,10 +91,23 @@ class ExBroker |
|
|
|
$onData($data);
|
|
|
|
},
|
|
|
|
$onClose = function () {
|
|
|
|
// 关闭链接
|
|
|
|
// 关闭链接 关闭定时ping
|
|
|
|
swoole_timer_clear($this->timerKlinePing);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
private function wsKlinePing()
|
|
|
|
{
|
|
|
|
$this->timerKlinePing = swoole_timer_tick(1000 * 20, function () {
|
|
|
|
$this->wsKline->push("ping");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
private function wsAccPing()
|
|
|
|
{
|
|
|
|
$this->timerAccPing = swoole_timer_tick(1000 * 20, function () {
|
|
|
|
$this->wsAcc->push("ping");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
private function crateWsSign($timeStamp)
|
|
|
|
{
|
|
|
|
$method = 'GET';
|
...
|
...
|
|