JKorf / Binance.Net

A C# .netstandard client library for the Binance REST and Websocket Spot and Futures API focusing on clear usage and models
https://jkorf.github.io/Binance.Net/
MIT License
1.04k stars 429 forks source link

General question on multiple websocket klines #75

Closed keefehiggins closed 6 years ago

keefehiggins commented 6 years ago

Hey,

This might be more of a general question regarding websockets than an issue with binance.net. I am trying to connect to a lot of kline websockets. Im using a windows service on a dev machine (4 cores, 16 gb memory)

  1. I iterate over 6 different klines.
  2. I iterate over all the symbols inside the kline.
  3. This is approx (6 klines X 302 Symbols = 1,812 total websockets opened)
  4. I have tried many different ways to get this working (one thread per websocket, a large group of websockets in a thread, async, etc..) but I always start getting failures mainly (System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.) or sometimes (System.IO.IOException: Unable to write data to the transport connection: An established connection was aborted by the software in your host machine.)
  5. Im currently instantiating var socketClient = new BinanceSocketClient(); when I open each socket, but have tried reusing socketClient for multiple sockets.

Do you by chance have any ideas on how I can facilitate what im trying to do? Maybe there is something I am overlooking as this is the first attempt Ive tried at using sockets before.

Thanks!

JKorf commented 6 years ago

Hi, I've done some work on combining streams on websockets. With the new version you can provided multiple symbols in the SubscribeToKlineStreamAsync call to subscribe more symbols on a single websocket. This would mean that you would only need 6 websockets. Let me know if that helped!

keefehiggins commented 6 years ago

I implemented the new version and I haven't verified all the data but this is working 1000 times better so far. I really appreciate the fast turn around time!

I will go ahead and close this, but again thank you!