I'm trying to get live data from websocket but on running the code, It isn't fetching the data and also not showing any error while running. I have followed the code given in the documentation.

from fyers_api import fyersModel
import os
import pandas as pd
import datetime as dt
from fyers_api.Websocket import ws
import sys
import time

data_type = "symbolData"
with open('access.txt','r') as r :
    access_token = r.read()

client_id = "DFGKPT0IK2-360"

newtoken = f"{client_id}:{access_token}"
symbol = ["NSE:SBIN-EQ"]
# symbol = ['MCX:CRUDEOILM23JULFUT']
kws = ws.FyersSocket(access_token=newtoken,run_background= False,log_path = os.getcwd())

def on_ticks(msg):
    script = msg[0]['symbol']
    ltp = msg[0]['ltp']
    high = msg[0]['high_price']
    low = msg[0]['low_price']
    ltt = dt.datetime.fromtimestamp(msg[0]['timestamp'])
    print (f"Script: {script}, Ltp: {ltp}, High: {high}, Low:{low}, ltt:{ltt}")


kws.websocket_data = on_ticks
kws.subscribe(symbol=symbol,data_type="symbolData")
kws.keep_running()
2 replies