LUCIT-Systems-and-Development / unicorn-binance-websocket-api

A Python SDK by LUCIT to use the Binance Websocket API`s (com+testnet, com-margin+testnet, com-isolated_margin+testnet, com-futures+testnet, com-coin_futures, us, tr, dex/chain+testnet) in a simple, fast, flexible, robust and fully-featured way.
https://unicorn-binance-websocket-api.docs.lucit.tech/
Other
685 stars 165 forks source link

`stream_buffer_name` vs `stream_label` in `binance_websocket_api_manager.create_stream()` #140

Closed xilopaint closed 3 years ago

xilopaint commented 3 years ago

Could anyone explain me the difference between stream_buffer_name and stream_label parameters in binance_websocket_api_manager.create_stream()?

What's the point of having both parameters instead of only one of them?

oliver-zehentleitner commented 3 years ago

stream_label is the name/label you choose for the stream and can be used with get_stream_id_by_label() and is shown in print_summary() which helps you to identify it in the view and should be unique (one stream, one label)

stream_buffer_name is the name of the buffer you want to use. you can use one buffer for all streams or just one buffer for one stream. for example you can create 2 streams to stream all trades. Since there are more than 1024 trading pairs, not all subscriptions fit into one stream, so you have to create 2 streams: stream_label="trades_1" and stream_label="trades_2" but both use stream_buffer_name="trades"

edit: https://oliver-zehentleitner.github.io/unicorn-binance-websocket-api/unicorn_binance_websocket_api.html#unicorn_binance_websocket_api.unicorn_binance_websocket_api_manager.BinanceWebSocketApiManager.create_stream

xilopaint commented 3 years ago

Since there are more than 1024 trading pairs, not all subscriptions fit into one stream

Thanks for the explanation. How many subscriptions fit into one stream?

oliver-zehentleitner commented 3 years ago

that depends on the exchange endpoint, i made an overview here: https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/wiki/Binance-websocket-endpoint-configuration-overview

xilopaint commented 3 years ago

you can use one buffer for all streams or just one buffer for one stream.

Do I have better performance using just one buffer per stream or one buffer for all streams?

oliver-zehentleitner commented 3 years ago

Splitting them uses a little bit more RAM but i think it saves operation times and avoids threading locks. Only one stream at a time can write to the buffer - the more buffers the less locks...

xilopaint commented 3 years ago

Splitting them uses a little bit more RAM but i think it saves operation times and avoids threading locks. Only one stream at a time can write to the buffer - the more buffers the less locks...

So is it generally preferable to split them?

oliver-zehentleitner commented 3 years ago

I think yes! But never tested this out. https://medium.com/python-features/using-locks-to-prevent-data-races-in-threads-in-python-b03dfcfbadd6

xilopaint commented 3 years ago

One more question. stream_buffer_name can be bool or str. If it's set to False data is written to the default stream_buffer and if it's set to True data can be read via pop_stream_data_from_stream_buffer(stream_id). In the latter case do we have a separate stream_buffer without a name since we are not setting a str to stream_buffer_name?

oliver-zehentleitner commented 3 years ago

yes

xilopaint commented 3 years ago

What happens if I unsubscribe from all channels and markets in a stream? An exception is returned or the library handle this situation? Can a stream object live without subscriptions?

oliver-zehentleitner commented 3 years ago

then its a stream (established websocket connection) without subscriptions...

i suggest you try a few of the example files i prepared and play a little bit with the code... try and error. I think the initial question is answered i close this!