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.02k stars 420 forks source link

Unsubscribe bug #1292

Closed Hulkstance closed 10 months ago

Hulkstance commented 11 months ago

I've observed an issue in the SocketConnection.cs when multiple subscriptions target the same symbol. Specifically, when one subscription tries to unsubscribe, the symbol gets unsubscribed from the exchange, causing all other subscriptions for that symbol to stop receiving messages. Ideally, the exchange-specific UnsubscribeAsync API call should only be made if there's a single subscription left for that symbol.

To provide some context: I've built an API to stream market data using SignalR and Proto.Actor. For every user that connects, a unique actor is spawned to manage their subscriptions. However, in my testing, I noticed that if two users subscribe to the same symbol and one unsubscribes, both end up losing the feed.

@JKorf, it should be relatively easy to fix. It just shouldn't call the exchange-specific UnsubscribeAsync API call if there are multiple subscriptions targeting the same symbol.

JKorf commented 10 months ago

Hi, this should be fixed in the latest version!