dict1 = {'LTP' : 0}
#Getting live data using websocket
new_token = f"{client_id}:{access_token}"
symbol = ['MCX:CRUDEOIL23SEPFUT']
kws = ws.FyersSocket(access_token=new_token, run_background= True, log_path=os.getcwd())
def on_ticks(msg):
symbol = msg[0]['symbol']
ltp = msg[0]['ltp']
dict1['LTP'] = ltp
kws.websocket_data = on_ticks
kws.subscribe(symbol=symbol, data_type="symbolData")
kws.keep_running()
time.sleep(5)
# access dict1['LTP'] in your main program
print(dict1['LTP'])
I am implementing fyers websocket for tick data in the background.
How to access dict1['LTP'] outside on_ticks function when run_background = True.
I am having trouble accessing the updated dict1['LTP'] value outside the on_ticks function. This could be due to the fact that the on_ticks1 function might not have had a chance to update dict1 before trying to access it.
Can anyone explain the flow of execution in WebSocket connection when run_background = True.
Please provide some examples or sample code or modify above code for better understanding.