from fyers_api.Websocket import ws
def run_process_foreground_symbol_data(access_token):
'''This function is used for running the symbolData in foreground
1. log_path here is configurable this specifies where the output will be stored for you
2. data_type == symbolData this specfies while using this function you will be able to connect to symbolwebsocket to get the symbolData
3. run_background = False specifies that the process will be running in foreground'''
data_type = "symbolData"
symbol = ["NSE:SBIN-EQ","NSE:ONGC-EQ"] ##NSE,BSE sample symbols
#symbol =["MCX:SILVERMIC22FEBFUT"]
# symbol =["MCX:SILVERMIC21NOVFUT","MCX:GOLDPETAL21SEPTFUT"]
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)
fs.keep_running()
def run_process_foreground_order_update(access_token):
'''This function is used for running the order_update in background
1. log_path here is configurable this specifies where the output will be stored for you.
2. data_type == orderUpdate this specfies while using this function you will be able to connect to orderwebsocket to get the orderUpdate
3. run_background = False specifies that the process will be running in foreground '''
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():
### Insert the accessToken and app_id over here in the following format (APP_ID:access_token)
access_token= ""
## run a specific process you need to connect to get the updates on
run_process_foreground_symbol_data(access_token)
# run_process_foreground_order_update(access_token)
if __name__ == '__main__':
main()
If there is another file called websocket.py or a directory called websocket in your current directory, it will cause issues. Also i think there is some install errors, can you create a new virtual environment and install the latest version of fyers apiv2?
'''This function is used for running the symbolData in foreground
1. log_path here is configurable this specifies where the output will be stored for you
2. data_type == symbolData this specfies while using this function you will be able to connect to symbolwebsocket to get the symbolData
3. run_background = False specifies that the process will be running in foreground'''
data_type = "symbolData"
symbol = ["NSE:SBIN-EQ","NSE:ONGC-EQ"] ##NSE,BSE sample symbols
#symbol =["MCX:SILVERMIC22FEBFUT"]
# symbol =["MCX:SILVERMIC21NOVFUT","MCX:GOLDPETAL21SEPTFUT"]
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)
fs.keep_running()
'''This function is used for running the order_update in background
1. log_path here is configurable this specifies where the output will be stored for you.
2. data_type == orderUpdate this specfies while using this function you will be able to connect to orderwebsocket to get the orderUpdate
3. run_background = False specifies that the process will be running in foreground '''
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():
### Insert the accessToken and app_id over here in the following format (APP_ID:access_token)
access_token= "your access token"
## run a specific process you need to connect to get the updates on
run_process_foreground_symbol_data(access_token)
# run_process_foreground_order_update(access_token)