Merge pull request #1544 from c9s/edwin/bitget/batch-subscribe

FIX: [bitget] batch subscribe channel
This commit is contained in:
bailantaotao 2024-02-23 16:07:49 +08:00 committed by GitHub
commit d0ed34c4e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 50 additions and 14 deletions

View File

@ -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
}
}
return nil

View File

@ -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) {