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

Clarification Needed on Unsubscribing from Specific Ticker Subscriptions #46

Open
wowDaiver opened this issue Jan 21, 2025 · 1 comment

Comments

@wowDaiver
Copy link

I am working on implementing ticker subscriptions using the WebsocketStream client. My goal is to subscribe to two tickers and later stop the subscription for one of them. Here’s what I’m doing:

this.wsClient = new WebsocketStream({
    wsURL: this.baseWsUrl,
    callbacks: {
        message: this.onMessage.bind(this),
    },
});
this.wsClient.ticker(symbol1);
this.wsClient.ticker(symbol2);

After subscribing to both tickers, I want to unsubscribe from one of them. I see that the WebsocketStream client provides an unsubscribe method, but I am unsure how to retrieve the required stream parameter for a specific ticker.

Could you clarify how I can properly obtain the stream value needed for the unsubscribe method?

Additional Context:
Using the WebsocketStream client from @binance/connector-typescript.
Subscriptions are being set up successfully, but the issue arises when attempting to manage them individually.
Thank you for your help!

@dimitrisn442
Copy link
Contributor

Hi @wowDaiver, you can use the unsubscribe() function to unsubscribe from your streams in the following way

this.wsClient = new WebsocketStream({
    wsURL: this.baseWsUrl,
    callbacks: {
        message: this.onMessage.bind(this),
    },
});
this.wsClient.ticker(symbol1);
this.wsClient.ticker(symbol2);

this.wsClient.unsubscribe("<symbol1>@ticker");

Let me know if that works for you!

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