mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
ftx: subscribe order update
This commit is contained in:
parent
34ea325499
commit
9c4ccbd6e2
|
@ -21,6 +21,7 @@ func (h *messageHandler) handleMessage(message []byte) {
|
|||
case orderBookChannel:
|
||||
h.handleOrderBook(r)
|
||||
case privateOrdersChannel:
|
||||
h.handlePrivateOrders(r)
|
||||
default:
|
||||
logger.Errorf("unsupported message type: %+v", r.Type)
|
||||
}
|
||||
|
@ -33,7 +34,7 @@ func (h messageHandler) handleSubscribedMessage(response websocketResponse) {
|
|||
logger.WithError(err).Errorf("failed to convert the subscribed message")
|
||||
return
|
||||
}
|
||||
logger.Infof("%s %s is subscribed", r.Market, r.Channel)
|
||||
logger.Info(r)
|
||||
}
|
||||
|
||||
func (h *messageHandler) handleOrderBook(response websocketResponse) {
|
||||
|
@ -68,3 +69,23 @@ func (h *messageHandler) handleOrderBook(response websocketResponse) {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (h *messageHandler) handlePrivateOrders(response websocketResponse) {
|
||||
if response.Type == subscribedRespType {
|
||||
h.handleSubscribedMessage(response)
|
||||
return
|
||||
}
|
||||
|
||||
r, err := response.toOrderUpdateResponse()
|
||||
if err != nil {
|
||||
logger.WithError(err).Errorf("failed to convert the order update response")
|
||||
return
|
||||
}
|
||||
|
||||
globalOrder, err := toGlobalOrder(r.Data)
|
||||
if err != nil {
|
||||
logger.WithError(err).Errorf("failed to convert order update to global order")
|
||||
return
|
||||
}
|
||||
h.EmitOrderUpdate(globalOrder)
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ type orderUpdateResponse struct {
|
|||
}
|
||||
|
||||
func (r websocketResponse) toOrderUpdateResponse() (orderUpdateResponse, error) {
|
||||
if r.Type != subscribedRespType || r.Channel != privateOrdersChannel {
|
||||
if r.Channel != privateOrdersChannel {
|
||||
return orderUpdateResponse{}, fmt.Errorf("type %s, channel %s: %w", r.Type, r.Channel, errUnsupportedConversion)
|
||||
}
|
||||
var o orderUpdateResponse
|
||||
|
@ -138,6 +138,10 @@ type subscribedResponse struct {
|
|||
Market string `json:"market"`
|
||||
}
|
||||
|
||||
func (s subscribedResponse) String() string {
|
||||
return fmt.Sprintf("`%s` channel is subsribed", strings.TrimSpace(fmt.Sprintf("%s %s", s.Market, s.Channel)))
|
||||
}
|
||||
|
||||
// {"type": "subscribed", "channel": "orderbook", "market": "BTC/USDT"}
|
||||
func (r websocketResponse) toSubscribedResponse() (subscribedResponse, error) {
|
||||
if r.Type != subscribedRespType {
|
||||
|
|
Loading…
Reference in New Issue
Block a user