Skip to main content

Multi Websocket

Using Multi Websocket will provide multiple instruments available actions and possible values at once.

from typing import Any
from thefirstock.firstockModules import firstockWebSockets
from thefirstock.pyClient.websocket import WsClient
from thefirstock.pyClient.websocket.enums import MessageTopic

# Pass 1 or 2 for Activating Websocket 1 or Websocket 2 in webSocketLogin()
client = firstockWebSockets.webSocketLogin()
ws = client.ws

@ws.on_connect
def connected(client, message):
if message.get('s') == 'OK':
client.subscribe_feed('NSE|26000#NSE|26009#NSE|22')

@ws.on_message(MessageTopic.SUBSCRIBE_FEED)
def msg_handler(client: WsClient, message: Any):
print(message)

ws.connect(uid="<userId>", actid="<userId>")
ws.run_forever()