mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Okx: Fix ping handler (#1203)
Ping handler for okx is not the RFC compat version gorilla would support. Even if it was, I think the UseGorillaHandler is broken/misconceived because it does not send keepalive pings, it responds to them. This also increases the delay to 27, in keeping with the 30 second timeout documented. I think this issue was hidden by the noisy default subs. When just using funding-rates, it showed straight away.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package okx
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -40,6 +41,11 @@ var (
|
||||
candlesticksIndexPriceMap = map[string]bool{okxChannelIndexCandle1Y: true, okxChannelIndexCandle6M: true, okxChannelIndexCandle3M: true, okxChannelIndexCandle1M: true, okxChannelIndexCandle1W: true, okxChannelIndexCandle1D: true, okxChannelIndexCandle2D: true, okxChannelIndexCandle3D: true, okxChannelIndexCandle5D: true, okxChannelIndexCandle12H: true, okxChannelIndexCandle6H: true, okxChannelIndexCandle4H: true, okxChannelIndexCandle2H: true, okxChannelIndexCandle1H: true, okxChannelIndexCandle30m: true, okxChannelIndexCandle15m: true, okxChannelIndexCandle5m: true, okxChannelIndexCandle3m: true, okxChannelIndexCandle1m: true, okxChannelIndexCandle1Yutc: true, okxChannelIndexCandle3Mutc: true, okxChannelIndexCandle1Mutc: true, okxChannelIndexCandle1Wutc: true, okxChannelIndexCandle1Dutc: true, okxChannelIndexCandle2Dutc: true, okxChannelIndexCandle3Dutc: true, okxChannelIndexCandle5Dutc: true, okxChannelIndexCandle12Hutc: true, okxChannelIndexCandle6Hutc: true}
|
||||
)
|
||||
|
||||
var (
|
||||
pingMsg = []byte("ping")
|
||||
pongMsg = []byte("pong")
|
||||
)
|
||||
|
||||
const (
|
||||
// allowableIterations use the first 25 bids and asks in the full load to form a string
|
||||
allowableIterations = 25
|
||||
@@ -52,7 +58,7 @@ const (
|
||||
// ColonDelimiter to be used in validating checksum
|
||||
ColonDelimiter = ":"
|
||||
|
||||
// maxConnByteLen otal length of multiple channels cannot exceed 4096 bytes.
|
||||
// maxConnByteLen total length of multiple channels cannot exceed 4096 bytes.
|
||||
maxConnByteLen = 4096
|
||||
|
||||
// Candlestick channels
|
||||
@@ -224,9 +230,9 @@ func (ok *Okx) WsConnect() error {
|
||||
ok.Websocket.GetWebsocketURL())
|
||||
}
|
||||
ok.Websocket.Conn.SetupPingHandler(stream.PingHandler{
|
||||
UseGorillaHandler: true,
|
||||
MessageType: websocket.PingMessage,
|
||||
Delay: time.Second * 10,
|
||||
MessageType: websocket.TextMessage,
|
||||
Message: pingMsg,
|
||||
Delay: time.Second * 27,
|
||||
})
|
||||
if ok.IsWebsocketAuthenticationSupported() {
|
||||
var authDialer websocket.Dialer
|
||||
@@ -252,9 +258,9 @@ func (ok *Okx) WsAuth(ctx context.Context, dialer *websocket.Dialer) error {
|
||||
ok.Websocket.Wg.Add(1)
|
||||
go ok.wsFunnelConnectionData(ok.Websocket.AuthConn)
|
||||
ok.Websocket.AuthConn.SetupPingHandler(stream.PingHandler{
|
||||
UseGorillaHandler: true,
|
||||
MessageType: websocket.PingMessage,
|
||||
Delay: time.Second * 5,
|
||||
MessageType: websocket.TextMessage,
|
||||
Message: pingMsg,
|
||||
Delay: time.Second * 27,
|
||||
})
|
||||
creds, err := ok.GetCredentials(ctx)
|
||||
if err != nil {
|
||||
@@ -552,6 +558,9 @@ func (ok *Okx) WsHandleData(respRaw []byte) error {
|
||||
var resp wsIncomingData
|
||||
err := json.Unmarshal(respRaw, &resp)
|
||||
if err != nil {
|
||||
if bytes.Equal(respRaw, pongMsg) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
if (resp.Event != "" && (resp.Event == "login" || resp.Event == "error")) || resp.Operation != "" {
|
||||
|
||||
Reference in New Issue
Block a user