ftx: handle err response

This commit is contained in:
ycdesu 2021-03-28 10:34:00 +08:00
parent 9c4ccbd6e2
commit f345730778
2 changed files with 23 additions and 2 deletions

View File

@ -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())
}
}

View File

@ -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)