Access variable from on_ticks() while running Fyers websocket(run_background= True). Fyers API v2

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.

@chirag @Z4PBvkQGyF

You should specify your API version

Hi @chirag I am using API v2.

Hi @siddhantmohanty007-ciy
Are you getting any issue in Fyers APIs ?

Yes the issue is when run_background = True, dict1 = {‘LTP’ : 0} is not getting updated. Your API has some problems in background functions. I have tried the same in different websocket(e.g. TrueData) I am able to do this simple operation.

Refer below article

https://community.fyers.inhttps://fyers.in/community/t/wesocket-in-background/12569

hi @Z4PBvkQGyF there are already 2 topics where LTP is updating in V3 but ech_time and vol_traded fields are not updating.

There is definitely some issue with websocket data.

Fyers Api V3 Websocket returning same exch_feed_time

Hi @siddhantmohanty007-ciy ,
If you set run_background to true, it won’t use your callback function, but it will write updates to a log file only.

Hi @chirag ,

We’re currently addressing this issue, and an updated SDK will be available soon. In the meantime, you can use the following workaround: when using the subscribe function, include the channel parameter and set its value to 15. This should resolve the problem.

fyers.subscribe(symbols=symbols, data_type=data_type, channel=15)

thanks @ZppA1qLXjC tested with mcx:crude its ok.