From f345730778941a0a2ac8c95ac52db8084f0828dd Mon Sep 17 00:00:00 2001 From: ycdesu Date: Sun, 28 Mar 2021 10:34:00 +0800 Subject: [PATCH] ftx: handle err response --- pkg/exchange/ftx/stream_message_handler.go | 6 +++++- pkg/exchange/ftx/websocket_messages.go | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pkg/exchange/ftx/stream_message_handler.go b/pkg/exchange/ftx/stream_message_handler.go index a5b308681..352d73cfc 100644 --- a/pkg/exchange/ftx/stream_message_handler.go +++ b/pkg/exchange/ftx/stream_message_handler.go @@ -23,7 +23,11 @@ func (h *messageHandler) handleMessage(message []byte) { case privateOrdersChannel: h.handlePrivateOrders(r) default: - logger.Errorf("unsupported message type: %+v", r.Type) + if r.Type != errRespType { + logger.Errorf("unsupported message type: %+v", r.Type) + return + } + logger.Errorf("received err: %s", r.toErrResponse()) } } diff --git a/pkg/exchange/ftx/websocket_messages.go b/pkg/exchange/ftx/websocket_messages.go index b263447d8..23e4ed896 100644 --- a/pkg/exchange/ftx/websocket_messages.go +++ b/pkg/exchange/ftx/websocket_messages.go @@ -129,7 +129,7 @@ Private: order: {"type": "subscribed", "channel": "orders"} Public - ordeerbook: {"type": "subscribed", "channel": "orderbook", "market": "BTC/USDT"} + orderbook: {"type": "subscribed", "channel": "orderbook", "market": "BTC/USDT"} */ type subscribedResponse struct { @@ -154,6 +154,23 @@ func (r websocketResponse) toSubscribedResponse() (subscribedResponse, error) { }, nil } +// {"type": "error", "code": 400, "msg": "Already logged in"} +type errResponse struct { + Code int64 `json:"code"` + Message string `json:"msg"` +} + +func (e errResponse) String() string { + return fmt.Sprintf("%d: %s", e.Code, e.Message) +} + +func (r websocketResponse) toErrResponse() errResponse { + return errResponse{ + Code: r.Code, + Message: r.Message, + } +} + func (r websocketResponse) toPublicOrderBookResponse() (orderBookResponse, error) { if r.Channel != orderBookChannel { return orderBookResponse{}, fmt.Errorf("type %s, channel %s: %w", r.Type, r.Channel, errUnsupportedConversion)