How to create Binance websocket connections to all coins of Futures market?

How to create Binance websocket connections to all coins of Futures market?

I read an official documentation for USDT-M and found this line:

If you need access to real-time kline updates, please consider using WebSocket Streams:

as I see, the command to connect to Binance suppose to look this way:
btcusdt@kline_1m

but is this for Futures market or for Spot? I am not sure, because a few blocks below there is this block of information:

<pair> _ <contractType>@continuousKline_<interval>

which leads to this:

btcusdt_perpetual@continuousKline_1m"

and as you see this is two absolutely different names of symbols. So which use for Futures?

Then I got another question. In Websocket documentation there are words that I can use startTime as parameter in request. Then, can you show an example with these two codes above?

Finally. How many streams can I launch for one connection? I have a goal to fetch klines data for every Futures market. Now I am doing it this way: wss://fstream.binance.com/stream?streams=
but it cannot handle more than 107 symbols.
By the way, is it okay to launch a websocket connection for EACH symbol rather than one with streams? How my goal can be achieved?

USD Futures Websocket Kline/Candlestick Streams
https://binance-docs.github.io/apidocs/futures/en/#kline-candlestick-streams

USD Futures Websocket Continuous Contract Kline/Candlestick Streams
https://binance-docs.github.io/apidocs/futures/en/#continuous-contract-kline-candlestick-streams

Continuous Contract Kline is a bit different from Klines.
Continuous Contract Kline is for the following contract types:

  • perpetual
  • current_quarter
  • next_quarter

Look into /fapi/v1/exchangeInfo endpoint to find those contract types.

Then I got another question. In Websocket documentation there are words that I can use startTime as parameter in request. Then, can you show an example with these two codes above?

Afaik startTime is only mentioned for REST API and Websocket API (which is different from Websocket Stream and is only available for Spot Market atm, so it’s not what you want).

Finally. How many streams can I launch for one connection?
By the way, is it okay to launch a websocket connection for EACH symbol rather than one with streams? How my goal can be achieved?

Pls consult this section → https://binance-docs.github.io/apidocs/futures/en/#websocket-market-streams, it says:

  • A single connection can listen to a maximum of 200 streams.
    You can consider distributing the streams among multiple connections , it might be harder to manage but more logical in sense of not entirely depend on one connection only and also better response time. You can research more about Multi connection vs Multiplexed stream and decide what’s best for your own use case.
1 Like