hirokisan / bybit

Bybit client library for Go
https://pkg.go.dev/github.com/hirokisan/bybit/v2
MIT License
95 stars 61 forks source link

Subscribe to multiple symbols as in Pybit #181

Closed austymenko closed 2 weeks ago

austymenko commented 3 weeks ago

Hello, can somebody suggest how (if) possible to subscribe to ticket_stream with the list of symbols as it's done in Pybit ?

hirokisan commented 2 weeks ago

ticket_stream

📝 It's ticker_stream, not ticket_stream

https://bybit-exchange.github.io/docs/v5/websocket/public/ticker

hirokisan commented 2 weeks ago

@austymenko

The function is already available.

https://github.com/hirokisan/bybit/blob/5c7e0bdb8ab8fbc82e66e162c8f6b0c7f3d8c974/v5_ws_public.go#L33-L36

Here is an example of use.

https://github.com/hirokisan/bybit/blob/5c7e0bdb8ab8fbc82e66e162c8f6b0c7f3d8c974/v5_ws_public_ticker_test.go#L59-L68

austymenko commented 2 weeks ago

@hirokisan yeah, ticker_stream, my typo. In this example only one symbol SymbolV5BTCUSDT is used. Do you have example of the ticker_stream to listen for multiple symbols?

hirokisan commented 2 weeks ago

@austymenko

listen for multiple symbols

I understand what you are saying.

Now it supports a single Ticker in the form of a SubscribeTicker, but not multiple Tickers.

https://github.com/hirokisan/bybit/blob/5c7e0bdb8ab8fbc82e66e162c8f6b0c7f3d8c974/v5_ws_public.go#L33-L36

For example, it could be implemented this way.

yourFunc := func(response V5WebsocketPublicTickerResponse) error {
  assert.Equal(t, respBody["topic"], response.Topic)
  testhelper.Compare(t, respBody["data"], response.Data.LinearInverse)
  return nil
}
symbols := []SymbolV5{SymbolV5BTCUSDT, SymbolV5ETHUSDT}
for _, symbol := range symbols {
  _, err := svc.SubscribeTicker(
    V5WebsocketPublicTickerParamKey{
      Symbol: symbol,
    },
    yourFunc,
  )
  require.NoError(t, err)
}
austymenko commented 2 weeks ago

@hirokisan thank you!, I will try.