Websoket: Do I have to need separate API_KEY for running Websoket ? I cannot see the quote updated . Can anyone help me with simple code. The example code in Github is not working for me
Hi Sushovan,
you need to generate access token to use websocket, you do not need separate API_KEY.
You can try with this sample code, add your own app id and access token.
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"
##NSE,BSE sample symbols
symbol = ["NSE:SBIN-EQ"]
fs = ws.FyersSocket(access_token=access_token,run_background=False,log_path="/home/user/Documents/testing/latest_websocket")
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="/home/user/Documents/testing/latest_websocket")
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 = "PJ*****XU9-100:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhcGkuZnllcnMuaW4iLCJpYXQiOjE2NDgxMDIwODIsImV4cCI6MTY0ODE2ODIwMiwibmJmIjoxNjQ4MTAyMDgyLCJhdWQiOlsieDoyIiwiZDoyIiwiZDoxIiwieDoxIiwieDowIl0sInN1YiI6ImFjY2Vzc190b2tlbiIsImF0X2hhc2giOiJnQUFBQUFCaVBBckMxSEVIa19tejhfRXdoUXR0T251aldIWXVPVTVBbmVUU0haMWlMN2ZienBhN25Gb0FTaGp0RndEQU5KUll4SzBrMEJTd3VtVkQ0aGRnSW9jcWhoRnFscWNTaGVaRTBFb1U1b0JOaHdhbjVldz0iLCJkaXNwbGF5X25hbWUiOiJWSUtSQU0gU1JJIiwiZnlfaWQiOiJYVjAxMTc5IiwiYXBwVHlwZSI6MTAwLCJwb2FfZmxhZyI6Ik4ifQ.MrBaasK0jB7SUFzVXoOoQ1mfN4mGPewZ6dxoWv********" #appid:accesstoken
## 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()
Hello Vikram
Does this Websoket always run in Foreground ?
Hello @Vikram Sri
It seems that at a time either OrderUpdate or QuoteUpdate is working ? Is this correct ?
Quick response is appreciated