Data Socket - Unsubscribe and Connection Management
This WebSocket allows you to unsubscribe from symbols and manage your Data Socket connection.
USE CASE
Stop updates for symbols you no longer track, for example when a watchlist is closed or a position is exited.
Details
- To stop receiving real-time data updates for a specific stock symbol or a group of symbols, you can utilize the "unsubscribe" action in the WebSocket API. Sending an "unsubscribe" message will remove the specified symbol(s) from your active subscriptions, and you will no longer receive updates for those symbols.
You can check the sample code to know how to unsubscribe to already subscribed symbols. - After a reconnect, previous symbols are resubscribed through auto-reconnect. To then update your symbol list, it is recommended to unsubscribe from the existing list and resubscribe with the updated list. See Updating subscribed symbols under Web Socket Introduction.
- In Python, call
unsubscribewith the symbols and the samedata_typeyou used to subscribe, for exampleSymbolUpdate. - A successful unsubscribe returns
typeunsub,code200 andsok. Themessagetext differs by SDK (Python:Unsubscribed; Node:successful). - You can run the call from the message callback, for example to drop a symbol once your condition is met.
- For a changed symbol list, unsubscribe from the current list and subscribe again. Do not open a second connection, because only one connection instance is allowed.
- Set
reconnect=Trueso a dropped connection recovers on its own.reconnect_retrysets the retry count, up to 50. - Handle disconnects and errors in the on-close and on-error callbacks.
Last updated on