### Run Order Update in Background Source: https://github.com/fyersdev/fyers-api-sample-code/blob/sample_v3/My API Sample Script(GET STARTED)/websocket sample script/websocket_background.ipynb This function demonstrates how to subscribe to order updates from the Fyers API and process them in a background thread. It requires an access token and allows for custom message handling and log file configuration. The `keep_running()` method is essential for continuous data reception. ```python from fyers_api.Websocket import ws def run_process_background_order_update(access_token): data_type = "orderUpdate" fs = ws.FyersSocket(access_token=access_token,run_background=True,log_path="/home/Downloads/") fs.websocket_data = custom_message fs.subscribe(data_type=data_type) fs.keep_running() def custom_message(msg): print (f"Custom:{msg}") def main(): access_token= "L9*****BW-100:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9******************************lcnMuaW4iLCJpYXQiOjE2MzE1ODY2MzUsImV4cCI6MTYzMTY2NTgzNSwibmJmIjoxNjMxNTg2NjM1LCJhdWQiOlsieDowIiwieDoxIiwieDoyIiwiZDoxIiwiZDoyIiwieDoxIiwieDowIl0sInN1YiI6ImFjY2Vzc190b2tlbiIsImF0X2hhc2giOiJnQUFBQUFCaFFBbExjOTlIUG85TTF4LWl5bTBZRFRHMHhXSi1HVGRkNU5BWlFET2xXYUpIS2h4S2RjMXVYckthc1R3VGlDQ01sYTBhanp6SmYwSWtHSHVFQjcwTThUcFcxckctQUdOWGZlQWhzZVY0bTVRSm1FRT0iLCJkaXNwbGF5X25hbWUiOiJQSVlVU0ggUkFKRU5EUkEgS0FQU0UiLCJmeV9pZCI6IkRQMDA0MDQiLCJhcHBUeXBlIjoxMDAsInBvYV9mbGFnIjoiTiJ9.Dacrm4oZU1Vcarr3nW8rKueJpVNBJCNVvdjg0cDMQrQ" run_process_background_order_update(access_token) if __name__ == '__main__': main() ``` -------------------------------- ### Run Symbol Data Subscription in Background Source: https://github.com/fyersdev/fyers-api-sample-code/blob/sample_v3/My API Sample Script(GET STARTED)/websocket sample script/websocket_background.ipynb This function demonstrates subscribing to symbol-specific data from the Fyers API in a background process. It allows specifying multiple symbols and data types, with options for background execution, log path configuration, and custom message handling. The `keep_running()` method ensures continuous data flow. ```python from fyers_api.Websocket import ws def run_process_background_symbol_data(access_token): data_type = "symbolData" symbol = ["NSE:SBIN-EQ","NSE:ONGC-EQ"] ##NSE,BSE sample symbols # symbol =["MCX:SILVERMIC21NOVFUT","MCX:GOLDPETAL21SEPFUT"] ##MCX SYMBOLS fs = ws.FyersSocket(access_token=access_token,run_background=True,log_path="/home/Downloads/") fs.websocket_data = custom_message fs.subscribe(symbol=symbol,data_type=data_type) fs.keep_running() def custom_message(msg): print (f"Custom:{msg}") def main(): access_token= "L9******BW-100:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ****************************nllcnMuaW4iLCJpYXQiOjE2MzE1ODY2MzUsImV4cCI6MTYzMTY2NTgzNSwibmJmIjoxNjMxNTg2NjM1LCJhdWQiOlsieDowIiwieDoxIiwieDoyIiwiZDoxIiwiZDoyIiwieDoxIiwieDowIl0sInN1YiI6ImFjY2Vzc190b2tlbiIsImF0X2hhc2giOiJnQUFBQUFCaFFBbExjOTlIUG85TTF4LWl5bTBZRFRHMHhXSi1HVGRkNU5BWlFET2xXYUpIS2h4S2RjMXVYckthc1R3VGlDQ01sYTBhanp6SmYwSWtHSHVFQjcwTThUcFcxckctQUdOWGZlQWhzZVY0bTVRSm1FRT0iLCJkaXNwbGF5X25hbWUiOiJQSVlVU0ggUkFKRU5EUkEgS0FQU0UiLCJmeV9pZCI6IkRQMDA0MDQiLCJhcHBUeXBlIjoxMDAsInBvYV9mbGFnIjoiTiJ9.Dacrm4oZU1Vcarr3nW8rKueJpVNBJCNVvdjg0cDMQrQ" run_process_background_symbol_data(access_token) if __name__ == '__main__': main() ``` -------------------------------- ### Symbol Data (Foreground Process) Source: https://github.com/fyersdev/fyers-api-sample-code/blob/sample_v3/My API Sample Script(GET STARTED)/websocket sample script/websocket_foreground.ipynb This function demonstrates how to fetch symbol data from the Fyers API in a foreground process. It initializes the FyersSocket, subscribes to the 'symbolData' data type for specified symbols, and uses a custom message handler. The `keep_running()` method is crucial for maintaining the WebSocket connection to receive data. ```python from fyers_api.Websocket import ws def run_process_foreground_symbol_data(access_token): data_type = "symbolData" symbol = ["NSE:NIFTY50-INDEX","NSE:SBIN-EQ"] ##NSE,BSE sample symbols # symbol =["MCX:ALUMINIUM21SEPFUT","MCX:SILVERMIC21NOVFUT"] fs = ws.FyersSocket(access_token=access_token,run_background=False,log_path="") fs.websocket_data = custom_message fs.subscribe(symbol=symbol,data_type=data_type) # symbol = ["NSE:ONGC-EQ"] # fs.unsubscribe(symbol=symbol) fs.keep_running() def custom_message(msg): print (f"Custom:{msg}") def main(): access_token= "L*********BW-100:eyJ0eXAiOiJKV1QiLCJhbGc***************************cGkuZnllcnMuaW4iLCJpYXQiOjE2MzI4MDYxNjQsImV4cCI6MTYzMjg3NTQwNCwibmJmIjoxNjMyODA2MTY0LCJhdWQiOlsieDowIiwieDoxIiwieDoyIiwiZDoxIiwiZDoyIiwieDoxIiwieDowIl0sInN1YiI6ImFjY2Vzc190b2tlbiIsImF0X2hhc2giOiJnQUFBQUFCaFVxVVVoT0VINDUyUGRhRW5pZWNHQS1QaUNhaXFwVVdsYl92ZE9SdmFMOFUwTGt6WVJFLTByLUNHZkEteS1UUmo0UndDYi1CaXItcEtsWGs4SnJNMkNzVU9wdmhEc290TUVfYUdyUU85TjUwaExDWT0iLCJkaXNwbGF5X25hbWUiOiJQSVlVU0ggUkFKRU5EUkEgS0FQU0UiLCJmeV9pZCI6IkRQMDA0MDQiLCJhcHBUeXBlIjoxMDAsInBvYV9mbGFnIjoiTiJ9.hcxy3cddSU9crbB0qw1kIoYEYbGLh4o2-RmDzK3nYOs" run_process_foreground_symbol_data(access_token) if __name__ == '__main__': main() ``` -------------------------------- ### Order Update (Foreground Process) Source: https://github.com/fyersdev/fyers-api-sample-code/blob/sample_v3/My API Sample Script(GET STARTED)/websocket sample script/websocket_foreground.ipynb This function demonstrates how to receive real-time order updates from the Fyers API in a foreground process. It initializes the FyersSocket, subscribes to the 'orderUpdate' data type, and uses a custom message handler to process incoming data. The `keep_running()` method is essential for maintaining the WebSocket connection. ```python from fyers_api.Websocket import ws def run_process_foreground_order_update(access_token): data_type = "orderUpdate" fs = ws.FyersSocket(access_token=access_token,run_background=False,log_path="") fs.websocket_data = custom_message fs.subscribe(data_type=data_type) fs.keep_running() def custom_message(msg): print (f"Custom:{msg}") def main(): access_token= "L9*******BW-100:eyJ0eXAiOiJKV1QiLCJhbGc************************kuZnllcnMuaW4iLCJpYXQiOjE2MzI0NzgzNzgsImV4cCI6MTYzMjUyOTg1OCwibmJmIjoxNjMyNDc4Mzc4LCJhdWQiOlsieDowIiwieDoxIiwieDoyIiwiZDoxIiwiZDoyIiwieDoxIiwieDowIl0sInN1YiI6ImFjY2Vzc190b2tlbiIsImF0X2hhc2giOiJnQUFBQUFCaFRhU3FPWXdVNE50cE9UQm9tbHl5Y3RTb0o3QlVDUFRwWkNHem85SW5VVFlNRWZrdm5lWHFETTJiTEtub09Nc1h0d2hGQ0J3c2JtRWZlWm1TRWdrZ1NNcUJJektRX2RLOWtLajBnZ1dUNUVIOTF1az0iLCJkaXNwbGF5X25hbWUiOiJQSVlVU0ggUkFKRU5EUkEgS0FQU0UiLCJmeV9pZCI6IkRQMDA0MDQiLCJhcHBUeXBlIjoxMDAsInBvYV9mbGFnIjoiTiJ9.qkdO2vC8mic10ETqQloSrQ6-iHKX5eBWlZ3pBfMxAIA" run_process_foreground_order_update(access_token) if __name__ == '__main__': main() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.