diff --git a/v2/futures/websocket_service.go b/v2/futures/websocket_service.go index bb276fda..bf97b0c5 100644 --- a/v2/futures/websocket_service.go +++ b/v2/futures/websocket_service.go @@ -572,6 +572,11 @@ type WsBookTickerEvent struct { BestAskQty string `json:"A"` } +type WsCombinedBookTickerEvent struct { + Data *WsBookTickerEvent `json:"data"` + Stream string `json:"stream"` +} + // WsBookTickerHandler handle websocket that pushes updates to the best bid or ask price or quantity in real-time for a specified symbol. type WsBookTickerHandler func(event *WsBookTickerEvent) @@ -591,6 +596,25 @@ func WsBookTickerServe(symbol string, handler WsBookTickerHandler, errHandler Er return wsServe(cfg, wsHandler, errHandler) } +func WsCombinedBookTickerServe(symbols []string, handler WsBookTickerHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error) { + endpoint := getCombinedEndpoint() + for _, s := range symbols { + endpoint += fmt.Sprintf("%s@bookTicker", strings.ToLower(s)) + "/" + } + endpoint = endpoint[:len(endpoint)-1] + cfg := newWsConfig(endpoint) + wsHandler := func(message []byte) { + event := new(WsCombinedBookTickerEvent) + err := json.Unmarshal(message, event) + if err != nil { + errHandler(err) + return + } + handler(event.Data) + } + return wsServe(cfg, wsHandler, errHandler) +} + // WsAllBookTickerServe serve websocket that pushes updates to the best bid or ask price or quantity in real-time for all symbols. func WsAllBookTickerServe(handler WsBookTickerHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error) { endpoint := fmt.Sprintf("%s/!bookTicker", getWsEndpoint())