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

Correct method to unsubscribe from WebSocket events? #146

Open
TimUnderhay opened this issue Sep 17, 2021 · 2 comments
Open

Correct method to unsubscribe from WebSocket events? #146

TimUnderhay opened this issue Sep 17, 2021 · 2 comments
Labels

Comments

@TimUnderhay
Copy link

I'm wondering: what is the correct method for unsubscribing from a WS subscription, like say wsClient.subscribeSpotKline(...params)? Thanks in advance.

@tiagosiebler
Copy link
Owner

This is admittedly not intuitive at the moment. The subscribe method returns a websocket object. You should be able to request closure using that ws object: wsClient.closeWs(ws):
https://github.com/tiagosiebler/binance/blob/master/src/websocket-client.ts#L366-L372

Would be good to add this to the readme or samples.

@mr-smit
Copy link

mr-smit commented Nov 24, 2022

How to unsubscribe:


// subscribe
let ws_usdm = wsClient.subscribeSymbolBookTicker('BTCUSDT', 'usdm'); 

// unsubscribe
wsClient.closeWs(ws_usdm);

you can store ws variables in array and use array to closeWs in loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants