knowm / XChange

XChange is a Java library providing a streamlined API for interacting with 60+ Bitcoin and Altcoin exchanges providing a consistent interface for trading and accessing market data.
http://knowm.org/open-source/xchange/
MIT License
3.85k stars 1.94k forks source link

[Binance-stream] Confusion about bookTicker usage #4815

Closed gryffus closed 8 months ago

gryffus commented 8 months ago

Hello,

I was looking into implementing "realtime" ticker updates in my app, as opposed to the 1-sec interval ones for Binance ticker, as described here: https://binance-docs.github.io/apidocs/spot/en/#all-market-rolling-window-statistics-streams

reads:

Individual Symbol Book Ticker Streams

    Payload:

{
  "u":400900217,     // order book updateId
  "s":"BNBUSDT",     // symbol
  "b":"25.35190000", // best bid price
  "B":"31.21000000", // best bid qty
  "a":"25.36520000", // best ask price
  "A":"40.66000000"  // best ask qty
}

Pushes any update to the best bid or ask's price or quantity in real-time for a specified symbol.
Multiple <symbol>@bookTicker streams can be subscribed to over one connection.

Stream Name: <symbol>@bookTicker
Update Speed: Real-time

I have found some references to bookTicker for example in BinanceSubscriptionType.java and some other places.

My question is, does XChange support the <symbol>@bookTicker stream at all, or is it just a coincidence in names?

Is there any way to get the <symbol>@bookTicker stream subscription in Xchange?

Thanks for clarification and happy coding!

gryffus commented 8 months ago

Solution lies here:

https://raw.githubusercontent.com/knowm/XChange/develop/xchange-stream-binance/src/test/java/info/bitrich/xchangestream/binance/BinanceBookTickerRealtimeExample.java

In short, yes, it is possible to get the <symbol>@bookTicker stream subscription :)

Closing.