Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support combined futures bookticker ws event #616

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions v2/futures/websocket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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())
Expand Down
Loading