Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Multiple Streams With Config #196

Open
sudonomen opened this issue Dec 23, 2022 · 3 comments
Open

Support for Multiple Streams With Config #196

sudonomen opened this issue Dec 23, 2022 · 3 comments

Comments

@sudonomen
Copy link

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 sudonomen changed the title Multiple Streams With Config Support for Multiple Streams With Config Dec 23, 2022
@sudonomen
Copy link
Author

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
Copy link
Author

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 sudonomen reopened this Dec 23, 2022
@sudonomen
Copy link
Author

sudonomen commented Dec 23, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant