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

Websock error #163

Closed muteddisk closed 5 years ago

muteddisk commented 5 years ago

Hi M. Korf, That was a big update to stream line your APIs. Keep up the great work. I'll send a donation as soon as I can for your great work. The issue with the update is the "subscribe" to any of the call is not returning to the thread. So if you you subscribe to klines and ticker, the thread locks. I could start each stream on a different thread but then it creates a lot of connections.

Thanks

JKorf commented 5 years ago

Hi, thanks for the kind words again. Donations are always appreciated ;) It was a lot of work, but it should make life easier for those who use multiple libraries.

I'm not sure what problem you're seeing, could you perhaps add some code and what you would expect?

muteddisk commented 5 years ago

I put some code together to test it out

image

It won't do the for/next. It calls the first websock call (symbolticker) won't return from the call and run allsymbolsticker or klinestream. it will run whatever code I put on ticker changes but won't come out of it. I would have to start each stream on a different thread to be able to call more than one websock call

JKorf commented 5 years ago

Okay so this seems like I forgot a ConfigureAwait(false) somewhere. Are you calling this from the UI thread? On a button click or a load event or something? If so, you could probably quickfix it by just calling it from a task. I'm not sure about the VB syntax, but in C# something like this would do the trick:

Task.Run(() =>{
    // Your loops and stuff
});

Tomorrow I'll look into where the hickup is.

muteddisk commented 5 years ago

no worries. I always test the new version before switching my code. That's what I was saying. I can go around on a different thread but 3 streams per symbol times X symbols make a shit loads of threads ;)

JKorf commented 5 years ago

I actually meant that when you put a new task around the whole thing it might continue past the first call. The UI thread can create a deadlock if not used correctly, but a new task for the whole thing might work just fine

muteddisk commented 5 years ago

Same issue with coinEx and BitFinex. Bittrex has a cast error. It seems to be all related to the changes to the websock.