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

UnsubscribeAsync stops all subscribers #1285

Closed
XHighIntell opened this issue Jul 22, 2023 · 1 comment
Closed

UnsubscribeAsync stops all subscribers #1285

XHighIntell opened this issue Jul 22, 2023 · 1 comment

Comments

@XHighIntell
Copy link

XHighIntell commented Jul 22, 2023

Describe the bug
When we have more than one subscribe to a one symbol. Unsubscribing one will stop all others.

To Reproduce

using Binance.Net;
using Binance.Net.Clients;
using Binance.Net.Objects.Models.Spot.Socket;
using CryptoExchange.Net.Authentication;
using Binance.Net.Enums;

static async Task Main(string[] args) {
    var client = new BinanceSocketClient(options => {
        options.Environment = BinanceEnvironment.Live;
    });
    
    var o = await client.SpotApi.ExchangeData.SubscribeToKlineUpdatesAsync("BTCTUSD", KlineInterval.OneMinute,
        x => {
            Console.WriteLine(x.Data.Data.OpenTime + " " + x.Data.Data.OpenPrice + " " + x.Data.Data.HighPrice + " " + x.Data.Data.LowPrice + " " + x.Data.Data.ClosePrice);
            if (x.Data.Data.Final == true) {
                Console.WriteLine("===========");
            }
        });
    var oo = await client.SpotApi.ExchangeData.SubscribeToKlineUpdatesAsync("BTCTUSD", KlineInterval.OneMinute,
        x => {
            Console.WriteLine(x.Data.Data.OpenTime + " " + x.Data.Data.OpenPrice + " " + x.Data.Data.HighPrice + " " + x.Data.Data.LowPrice + " " + x.Data.Data.ClosePrice);
            if (x.Data.Data.Final == true) {
                Console.WriteLine("===========");
            }
        });
    await client.UnsubscribeAsync(oo.Data.Id); // <--- Let unsubscribe one and keep another
    Console.WriteLine("Unsubscribe id=" + oo.Data.Id);
    Console.ReadLine();
}

Expected behavior
Should keep getting events.

Debug logging
image

@JKorf
Copy link
Owner

JKorf commented Jul 23, 2023

That's because you're subscribing to the same symbol twice. The server sees that as the same subscription, so when you unsubscribe one they'll both unsubscribe. If you change the symbol on one of the two it'll work correctly.

@JKorf JKorf closed this as completed Jul 23, 2023
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

2 participants