Help regarding Websocket code
-
Hello,
I am new to SmartApi. I got the code below from GitHub
from SmartApi import SmartWebSocket # feed_token=092017047 FEED_TOKEN="YOUR_FEED_TOKEN" CLIENT_CODE="YOUR_CLIENT_CODE" # token="mcx_fo|224395" token="EXCHANGE|TOKEN_SYMBOL" #SAMPLE: nse_cm|2885&nse_cm|1594&nse_cm|11536&nse_cm|3045 # token="mcx_fo|226745&mcx_fo|220822&mcx_fo|227182&mcx_fo|221599" task="mw" # mw|sfi|dp ss = SmartWebSocket(FEED_TOKEN, CLIENT_CODE) def on_message(ws, message): print("Ticks: {}".format(message)) def on_open(ws): print("on open") ss.subscribe(task,token) def on_error(ws, error): print(error) def on_close(ws): print("Close") # Assign the callbacks. ss._on_open = on_open ss._on_message = on_message ss._on_error = on_error ss._on_close = on_close ss.connect() ####### Websocket sample code ended here #######
and
####### Websocket V2 sample code ####### from SmartApi.smartWebSocketV2 import SmartWebSocketV2 from logzero import logger AUTH_TOKEN = "Your Auth_Token" API_KEY = "Your Api_Key" CLIENT_CODE = "Your Client Code" FEED_TOKEN = "Your Feed_Token" correlation_id = "abc123" action = 1 mode = 1 token_list = [ { "exchangeType": 1, "tokens": ["26009"] } ] sws = SmartWebSocketV2(AUTH_TOKEN, API_KEY, CLIENT_CODE, FEED_TOKEN) def on_data(wsapp, message): logger.info("Ticks: {}".format(message)) # close_connection() def on_open(wsapp): logger.info("on open") sws.subscribe(correlation_id, mode, token_list) def on_error(wsapp, error): logger.error(error) def on_close(wsapp): logger.info("Close") def close_connection(): sws.close_connection() # Assign the callbacks. sws.on_open = on_open sws.on_data = on_data sws.on_error = on_error sws.on_close = on_close sws.connect()
I have a few questions:
- From where can I get the FEED_TOKEN ?
- For the newer version, from where can I get AUTH_TOKEN and FEED_TOKEN ?
Thanks in advance.
-
login api call
data = smartapi.generateSession(clientId , pwd , totp)
authToken = data['data']['jwtToken']
refreshToken = data['data']['refreshToken']fetch the feedtoken
feedToken = smartapi.getfeedToken()
fetch User Profile
res = smartapi.getProfile(refreshToken)
smartapi.generateToken(refreshToken)
res=res['data']['exchanges']
feedTokenuse this code