WebSockets API - Append Instrument Tokens to the existing websocket connection

I’ve been using the websockets-api to get the realtime prices of the instruments present in watchlist.

The application is designed to subscribe to a single socket connection, and the user can add or remove instruments from the watchlist.

Is it possible to update the list of instrument keys on the fly, for the same socket connection? or the socket has to be closed and a new socket connection has to be initiated with the new set of instrument keys?

Prompt help will be appreciated.


Hi @Pradeep_Jaiswar , tagging you for a prompt response.

Certainly, it’s feasible to dynamically update the list of instrument keys while maintaining the same socket connection. You can explore our WebSocket implementations in various programming language SDK for more details.

  1. Python
  2. Nodejs
  3. Java
  4. PHP
1 Like

Thanks @Ketan !

The abstraction of websockets using streamer works great, and also looks clean.

1 Like


I’m getting following exception, whenever trying to call any function after .connect().

websocket._exceptions.WebSocketConnectionClosedException: socket is already closed.

Will it be possible to update the list after connection is established?

Yes, it is possible. If you’re using the Python SDK, please refer to the example in the README here:

Make sure you are using the latest Python SDK version 2.4.1.