How to login using python in websocket

client = firstockWebSockets.webSocketLogin()
ws = client.ws

Note

  • As soon as connection is done, a connection request should be sent with User id and login session id.
  • All input and output messages will be in json format.

what is the session id ?

Hi SKB_ZONE

First you need to login to the Firstock API

from thefirstock import thefirstock

login = thefirstock.firstock_login(
    userId='AA123',
    password='password',
    TOTP='1234698',
    vendorCode='AA123_API',
    apiKey='NVDewefds2343q2334',
)

Over here the vendor code and the apiKey is available in the below link

please login to the above link and generate the API key and vendor code and place to the above code and then upon login their will be a config.json file will be generated which will be used by the websockets automatically,

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


client = firstockWebSockets.webSocketLogin()
ws = client.ws


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


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


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

in the above code please replace the userId with your userId and then the websockets will start running

from thefirstock import thefirstock

login = thefirstock.firstock_login(
    userId='AA123',
    password='password',
    TOTP='1234698',
    vendorCode='AA123_API',
    apiKey='NVDewefds2343q2334',
)

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


client = firstockWebSockets.webSocketLogin()
ws = client.ws


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


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


ws.connect(uid="AA123", actid="AA123")
ws.run_forever()