wisespace-io / binance-rs

Rust Library for the Binance API
Other
636 stars 287 forks source link

Support for Multiple Streams With Config #196

Open sudonomen opened 1 year ago

sudonomen commented 1 year ago

Can't seem to figure out how to get multiple steams with a config.

I tried using a single websocket and looping over an array of symbols to do the connection. I end up only getting data for a single symbol. I'm new to rust so maybe I'm just missing something.

Open a websocket for each symbol?

I will comb through your implementation of "multiple streams" and see If I can figure it out but In the meantime if you see this and have a suggestion let me know.

Thanks

sudonomen commented 1 year ago

After doing some research - I don't think Binance limits connections per IP(I could be wrong). I should be fine opening a websocket for each symbol. Probably not the most efficient way to do it as It most certainly adds overhead but at least it works.

sudonomen commented 1 year ago

Answered my own question.

It's pretty simple but not very intuitive. If you reference the Binance.us Docs they say multiple streams can be subscribed to by combining the "Stream Name". For example if you want the trade stream for BTCUSD and ETHUSD you would use the path stream?streams=btcusd@trade/ethusd@trade. To get multiple streams using a config using this library you can simply put the string btcusd@trade/ethusd@trade into the connect_with_config function.

EXAMPLE: let config = Config::default().set_ws_endpoint("wss://stream.binance.us:9443/ws");

let agg_trade = "btcusd@trade/ethusd@trade";

web_socket.connect_with_config(agg_trade, &config).unwrap(); // check error

sudonomen commented 1 year ago

Reopened for discussion

Perhaps there's a cleaner way to approach this. I could simply update the docs but maybe adding a function connect_multiple_streams_with_config would be cleaner?