sonvister / Binance

A .NET Standard Binance API library.
MIT License
229 stars 79 forks source link

Multi-threading api problem #104

Open evo11x opened 5 years ago

evo11x commented 5 years ago

I made a global ServiceProvider from where each thread gets it's api, but one thread is using the websockets, I don't know if that is a problem? But the application now works fine for 1-3 days until it closes without any error. You have any ideea what is happening? Because with the older version of API worked fine.

sonvister commented 5 years ago

I don't have time to help debug application code. If someone can provide actionable information demonstrating a multi-threading API problem (and potentially a fix) that would be useful.

evo11x commented 5 years ago

Hi, after I updated all the reference dll files and visual studio, now seems to work, except the api rate limiter for the order processor (which runs on another thread), it is too aggressive and cannot process the orders when there are more than 2-3 open orders, after manual stop and restart of the candlestick reader thread it continues to execute orders until it blocks again and some orders remain unfilled forever because of this. It's strange that when restarting the other thread it continues with the order processor thread and there are 1sec delays for each one. Please note that binance let's a higher number of requests if larger amounts of orders get filled and without many unfilled moving orders.

sonvister commented 5 years ago

@evo11x, as far as I know Binance allows 10/sec. If the rate limiter is too aggressive (not accurate), I would appreciate any help in identifying the issue(s). Otherwise, you can always replace or disable (HttpClient.RateLimiter = null) the rate limiter.

evo11x commented 5 years ago

@sonvister ok I will try to find the issue, the app is definitely not requesting more than 2-3/sec in total from all the threads combined and it hits the rate limiter very often when using the orders (cancel, get bid price, post new order and get order status), stopping and restarting the other thread it continues to work normally for a period of time.

alikalfaoglu commented 5 years ago

Try refactoring your code completely using async - await. I guess you're mostly using sync code.