Skip to Content
API ReferenceWebSocketsData SocketOverviewUnsubscribe and Connection Management

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 unsubscribe with the symbols and the same data_type you used to subscribe, for example SymbolUpdate.
  • A successful unsubscribe returns type unsub, code 200 and s ok. The message text 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=True so a dropped connection recovers on its own. reconnect_retry sets the retry count, up to 50.
  • Handle disconnects and errors in the on-close and on-error callbacks.
Last updated on