from fyers_apiv3.FyersWebsocket import data_ws
fyers = data_ws.FyersDataSocket(
access_token=new_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.
on_close=onclose, # Callback function to handle WebSocket connection close events.
on_error=onerror, # Callback function to handle WebSocket errors.
on_message=onmessage # Callback function to handle incoming messages from the WebSocket.
)
Hi @ajith.n.namboothiri.uy30abqu
Please share your code so that I can check from my side
I shared the code, looks like it was deleted. The exact error is : AttributeError: partially initialized module ‘fyers_apiv3.FyersWebsocket.data_ws’ has no attribute ‘FyersDataSocket’ (most likely due to a circular import) This happens on the sample code in Response Attributes(Market Data Update) available in API v3 documentation
from fyers_apiv3.FyersWebsocket import data_ws def onmessage(message): print("Response:", message) def onerror(message): print("Error:", message) def onclose(message): print("Connection closed:", message) def onopen(): data_type = "SymbolUpdate" # Subscribe to the specified symbols and data type symbols = ["NSE:NIFTY50-INDEX" , "NSE:NIFTYBANK-INDEX"] fyers.subscribe(symbols=symbols, data_type=data_type) # 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 with open("access.txt","r") as r: access_token = r.read() client_id = 'XXXXX' new_token = f"{client_id}:{access_token} " # Create a FyersDataSocket instance with the provided parameters fyers = data_ws.FyersDataSocket( access_token=new_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. on_close=onclose, # Callback function to handle WebSocket connection close events. on_error=onerror, # Callback function to handle WebSocket errors. on_message=onmessage # Callback function to handle incoming messages from the WebSocket. ) # Establish a connection to the Fyers WebSocket fyers.connect()
when I changed fyers object to wfyers, it worked. Thank you
Hi @ajith.n.namboothiri.uy30abqu
Glad to know it is working for you now.