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

FIX: [bitget] batch subscribe channel #1544

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
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
22 changes: 16 additions & 6 deletions pkg/exchange/bitget/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,22 @@ func (s *Stream) syncSubscriptions(opType WsEventType) error {
}

logger.Infof("%s channels: %+v", opType, args)
if err := s.Conn.WriteJSON(WsOp{
Op: opType,
Args: args,
}); err != nil {
logger.WithError(err).Error("failed to send request")
return err

batchSize := 10
lenArgs := len(args)
for begin := 0; begin < lenArgs; begin += batchSize {
end := begin + batchSize
if end > lenArgs {
end = lenArgs
}

if err := s.Conn.WriteJSON(WsOp{
Op: opType,
Args: args[begin:end],
}); err != nil {
logger.WithError(err).Error("failed to send request")
return err
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this part a function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do it in the next PR


return nil
Expand Down
42 changes: 34 additions & 8 deletions pkg/exchange/bitget/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,43 @@ func TestStream(t *testing.T) {
s := getTestClientOrSkip(t)

symbols := []string{
"BTCUSDT",
"ETHUSDT",
"DOTUSDT",
"ADAUSDT",
"AAVEUSDT",
"APTUSDT",
"ATOMUSDT",
"ADAUSDT",
"ALICEUSDT",
"AXSUSDT",
"BNBUSDT",
"SOLUSDT",
"BTCUSDT",
"COMPUSDT",
"DAIUSDT",
"DOGEUSDT",
"DOTUSDT",
"ETHUSDT",
"FILUSDT",
"GALAUSDT",
"GRTUSDT",
"LINKUSDT",
"LTCUSDT",
"MANAUSDT",
"MATICUSDT",
"PAXGUSDT",
"SANDUSDT",
"SLPUSDT",
"SOLUSDT",
"UNIUSDT",
"XLMUSDT",
"YFIUSDT",
"APEUSDT",
"ARUSDT",
"BNBUSDT",
"CHZUSDT",
"ENSUSDT",
"ETCUSDT",
"FTMUSDT",
"GMTUSDT",
"LOOKSUSDT",
"XTZUSDT",
"ARBUSDT",
"LDOUSDT",
"TRXUSDT",
}

t.Run("book test", func(t *testing.T) {
Expand Down
Loading