#This is my socket connection code, The socket is not giving any updates
instrumentList = [constants.Intsruments.NIFTY.value, constants.Intsruments.BANK_NIFTY.value]
def onopen():
print("Connection opened")
symbols = initInstruments()
if symbols:
t1 = threading.Thread(target=startApp)
t1.start()
# Subscribe to the specified symbols and data type
socketInstance.subscribe(symbols=symbols, data_type="SymbolUpdate")
socketInstance.keep_running()
else:
print("Symbol not found")
socketInstance.close_connection()
def onerror(message):
print("Error:", message)
def onmessage(ticks):
global ltpDict
ltpDict[ticks["symbol"]] = ticks["ltp"]
pprint(ltpDict)
def onclose(message):
print("Connection closed:", message)
def startApp():
#global serverThread
print("Inside startServer()")
app.run(host=f"{os.getenv('FLASK_IP')}",port=f"{os.getenv('FLASK_PORT')}")
#serverThread = ThreadedWSGIServer("0.0.0.0", 4001, app)
#serverThread.serve_forever()
def startTracking():
global socketInstance
# Create a FyersDataSocket instance with the provided parameters
socketInstance = data_ws.FyersDataSocket(
access_token=f"{os.getenv('CLIENT_ID')}:{os.getenv('TOKEN')}", # Access token in the format "appid:accesstoken"
log_path=f"{os.getenv('LOG_PATH')}", # Path to save logs. Leave empty to auto-create logs in the current directory.
litemode=True, # 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
socketInstance.connect()
startTracking()
Giving below output (Gets connected but no data updates)
Websocket not working
1 reply