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

参数扩展,支持订阅同一symbol的多条k线 #538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion v2/websocket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,22 @@ type WsKlineHandler func(event *WsKlineEvent)

// WsCombinedKlineServe is similar to WsKlineServe, but it handles multiple symbols with it interval
func WsCombinedKlineServe(symbolIntervalPair map[string]string, handler WsKlineHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error) {
endpoint := getCombinedEndpoint()
symbolIntervalPair2 := make([]string, 0, len(symbolIntervalPair)*2)
for symbol, interval := range symbolIntervalPair {
symbolIntervalPair2 = append(symbolIntervalPair2, symbol, interval)
}
return WsCombinedKlineServe2(symbolIntervalPair2, handler, errHandler)
}

// WsCombinedKlineServe2 .
func WsCombinedKlineServe2(symbolIntervalPair []string, handler WsKlineHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error) {
if len(symbolIntervalPair)%2 != 0 {
return nil, nil, fmt.Errorf("symbolIntervalPair must be a multiple of 2")
}
endpoint := getCombinedEndpoint()
for i := 0; i < len(symbolIntervalPair); i += 2 {
symbol := symbolIntervalPair[i]
interval := symbolIntervalPair[i+1]
endpoint += fmt.Sprintf("%s@kline_%s", strings.ToLower(symbol), interval) + "/"
}
endpoint = endpoint[:len(endpoint)-1]
Expand Down