I’ve use the both the code and still getting same response during live market also. In fact, I tried with lite mode too…here is the reponse from lite mode …
fyers.subscribe(symbols=symbols, data_type=data_type, channel=15)
# Keep the socket running to receive real-time data
# fyers.keep_running()
fyers.connect()
I hope you understand the order in which function is called matters.
Can you pls tell me how this code will work? “fyers” object is used before its creation
symbols = [‘NSE:SBIN-EQ’, ‘NSE:ADANIENT-EQ’]
** fyers.subscribe(symbols=symbols, data_type=data_type) —> You are using fyers object here**
# Keep the socket running to receive real-time data
fyers.keep_running()
Replace the sample access token with your actual access token obtained from Fyers
access_token = “XCXXXXXXM-100:eyJ0tHfZNSBoLo”
Create a FyersDataSocket instance with the provided parameters
**fyers = data_ws.FyersDataSocket( ----> but creating **
access_token=access_token, # Access token in the format "appid:accesstoken"
log_path="", # Path to save logs. Leave empty to auto-create logs in the current directory.
litemode=False, # Lite mode disabled. Set to True if you want a lite response.
write_to_file=False, # Save response in a log file instead of printing it.
reconnect=True, # Enable auto-reconnection to WebSocket on disconnection.
on_connect=onopen, # Callback function to subscribe to data upon connection.
Forget your code, read my 1st post, take the one from github and start from there. Do proper code review, this much code proficiency is expected.
Websocket code runs in a different thread, all those functions are callbacks and they will be triggered by events in the Fyers module that you cant see.
You have to init class, then connect and lastly subscribe.