diff --git a/pkg/exchange/okex/parse.go b/pkg/exchange/okex/parse.go index 2baa35fd5..54ea2a2ff 100644 --- a/pkg/exchange/okex/parse.go +++ b/pkg/exchange/okex/parse.go @@ -99,10 +99,12 @@ func parseWebSocketEvent(in []byte) (interface{}, error) { type WsEventType string const ( - WsEventTypeLogin = "login" - WsEventTypeError = "error" - WsEventTypeSubscribe = "subscribe" - WsEventTypeUnsubscribe = "unsubscribe" + WsEventTypeLogin WsEventType = "login" + WsEventTypeError WsEventType = "error" + WsEventTypeSubscribe WsEventType = "subscribe" + WsEventTypeUnsubscribe WsEventType = "unsubscribe" + WsEventTypeConnectionInfo WsEventType = "channel-conn-count" + WsEventTypeConnectionError WsEventType = "channel-conn-count-error" ) type WebSocketEvent struct { @@ -115,6 +117,8 @@ type WebSocketEvent struct { } `json:"arg,omitempty"` Data json.RawMessage `json:"data"` ActionType ActionType `json:"action"` + Channel Channel `json:"channel"` + ConnCount string `json:"connCount"` } func (w *WebSocketEvent) IsValid() error { @@ -133,6 +137,12 @@ func (w *WebSocketEvent) IsValid() error { } return nil + case WsEventTypeConnectionInfo: + return nil + + case WsEventTypeConnectionError: + return fmt.Errorf("connection rate limit exceeded, channel: %s, connCount: %s", w.Channel, w.ConnCount) + default: return fmt.Errorf("unexpected event type: %+v", w) } @@ -401,3 +411,10 @@ func (m *MarketTradeEvent) toGlobalTrade() (types.Trade, error) { FeeCurrency: "", // not supported }, nil } + +type ConnectionInfoEvent struct { + Event string `json:"event"` + Channel Channel `json:"channel"` + ConnCount string `json:"connCount"` + ConnId string `json:"connId"` +} diff --git a/pkg/exchange/okex/parse_test.go b/pkg/exchange/okex/parse_test.go index 6877691ec..a9bfb15db 100644 --- a/pkg/exchange/okex/parse_test.go +++ b/pkg/exchange/okex/parse_test.go @@ -849,6 +849,46 @@ func TestWebSocketEvent_IsValid(t *testing.T) { assert.ErrorContains(t, opEvent.IsValid(), "unexpected event type") }) + + t.Run("conn count info", func(t *testing.T) { + input := `{ + "event":"channel-conn-count", + "channel":"orders", + "connCount": "2", + "connId":"abcd1234" +}` + res, err := parseWebSocketEvent([]byte(input)) + assert.NoError(t, err) + opEvent, ok := res.(*WebSocketEvent) + assert.True(t, ok) + assert.Equal(t, WebSocketEvent{ + Event: "channel-conn-count", + Channel: "orders", + ConnCount: "2", + }, *opEvent) + + assert.NoError(t, opEvent.IsValid()) + }) + + t.Run("conn count error", func(t *testing.T) { + input := `{ + "event": "channel-conn-count-error", + "channel": "orders", + "connCount": "20", + "connId":"a4d3ae55" +}` + res, err := parseWebSocketEvent([]byte(input)) + assert.NoError(t, err) + opEvent, ok := res.(*WebSocketEvent) + assert.True(t, ok) + assert.Equal(t, WebSocketEvent{ + Event: "channel-conn-count-error", + Channel: "orders", + ConnCount: "20", + }, *opEvent) + + assert.ErrorContains(t, opEvent.IsValid(), "rate limit") + }) } func TestOrderTradeEvent(t *testing.T) {