Unable to get live feed.
-
@admin I am able to get historical as well as ltp data. but when trying for live feed getting following output.
__on_open################
{'task': 'cn', 'channel': 'NONLM', 'token': '0968926247', 'user': 'B96820', 'acctid': 'B96820'}
2022-05-29 13:27:52.873895 : Start task in the background
{'task': 'hb', 'channel': '', 'token': '0968926247', 'user': 'B96820', 'acctid': 'B96820'}
on open
Ticks: [{'ak': 'ok', 'msg': 'connected', 'task': 'cn'}]
Ticks: [{'ak': 'ok', 'msg': 'heartbeat', 'task': 'hb'}]
Ticks: [{'ak': 'ok', 'msg': 'mw', 'task': 'mw'}]
Ticks: [{'ak': 'ok', 'msg': 'mw', 'task': 'mw'}]
Ticks: [{'ak': 'ok', 'msg': 'mw', 'task': 'mw'}]
Ticks: [{'ak': 'ok', 'msg': 'mw', 'task': 'mw'}]
2022-05-29 13:28:22.890306 : Start task in the background
{'task': 'hb', 'channel': '', 'token': '0968926247', 'user': 'B96820', 'acctid': 'B96820'}
Ticks: [{'ak': 'ok', 'msg': 'heartbeat', 'task': 'hb'}]
@admin Will you please look where is the problem?
Thank you.
Following is the Code that I am using for live feed.from smartapi import SmartConnect
from smartapi import SmartWebSocketapikey = 'MlxYOLdb'
username = 'B96820'
pwd = 'password'
obj = SmartConnect(api_key=apikey)
data = obj.generateSession(username,pwd)
refreshToken= data['data']['refreshToken']
feedToken=obj.getfeedToken()
FEED_TOKEN = feedToken#"0980248722"
CLIENT_CODE = username
token = "nse_fo|108809&nse_fo|56855&nse_fo|5694&nse_fo|56906"
ss = SmartWebSocket(FEED_TOKEN, CLIENT_CODE)
task = "mw"def on_message(ws, message):
print("Ticks: {}".format(message))def on_open(ws):
ss.subscribe(task, token)
print("on open")
ss.subscribe(task, token)def on_error(ws, error):
print(error)def on_close(ws):
print("Close")ss._on_open = on_open
ss._on_message = on_message
ss._on_error = on_error
ss._on_close = on_closess.connect()
-
@Sukhwant280 use this code for feedtoken
feedToken = obj.getfeedToken() -
@admin
I get below response from generateSession. I cant find any relevant for FEED_TOKEN.{"status": True,
"message": "SUCCESS",
"errorcode": "",
"data": {
"clientcode": "XXXXXX",
"name": "XXXX YYYY",
"email": "",
"mobileno": "",
"exchanges": ["bse_cm", "nse_cm", "nse_fo"],
"products": ["BO", "NRML", "CO", "CNC", "MIS", "MARGIN"],
"lastlogintime": "",
"broker": "",
"jwtToken": "Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"refreshToken": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}
}Also, are you referring to below doc ? I cant find anything which explains which field to take from api response. Pleas advise
https://docs.google.com/document/d/1tZQzU2qNrB98eso6e6yqF3YxvXfK9cn5Xkzw_5jSJL8/edit -
Hi @Sukhwant280
FeedToken is different from refreshToken
jwtToken, refreshToken and feedToken are generated after successful login into your account via SmartAPI.
feedToken is required to be passed to a WebSocket connection request to start successful streaming of tick data.
Please read more about this in our documentation.
-
@admin - Thanks. Now I am using below in my code
AUTH_TOKEN -> jwtToken from response from generateSession('userid', 'password')
FEED_TOKEN -> refreshToken from response from generateSession('userid', 'password')Please confirm if above is not correct, coz still I am getting same response from websockt i.e "Attempting to resubscribe/reconnect...
In on pong function==> b'\x00'"I tried to troubleshoot from my end -> it failing at below step (i.e. row no 310 in smartWebsocketV2.py:
"token": SmartWebSocketV2._parse_token_value(binary_data[2:27]),
Can you help me here to understand whats wrong in my inputs ?
-
Hi @Sukhwant280 , Auth_token is JWT token obtained at the time of generating the session using loginbypassword api call.
-
@Mnagesh - Below is the code form websocket vs 2
my question is from where do we get AUTH_TOKEN. I tried adding "Secret-Key" from "Apps & API" section (i.e. this link -> https://smartapi.angelbroking.com/apps) but I get below feeds from websocket.
Code
from SmartApi.smartWebSocketV2 import SmartWebSocketV2AUTH_TOKEN = 'Bearer eyJhbGciOiJIUzU-w'
API_KEY = 'qwert'
CLIENT_CODE = 'X123456'
FEED_TOKEN = '00998877'correlation_id = "nishant_123_qwerty"
action = 1
mode = 3Websocket feed:
In on pong function==> b'\x00' -
@Sukhwant280 can you elaborate your Q? with part of code or function and its error or output
-
@admin - is AUTH_TOKEN same as Secret-Key ?
-
@admin - found answers to my question on documentation here https://drive.google.com/drive/u/0/folders/1GMwTMfxRdiloUziV4DYwlYchGXbOvTfL
follow up question : for AUTH_TOKEN, its mentioned (jwt auth token received from Login API). How do we generate auth token login api?
-
@admin I am not clear what needs to be entered in AUTH_TOKEN and correlation_id. Couldnt find anything on the documentation as well.
Please help
- topic:timeago_earlier,about a month
-
Code isn't finished?
- topic:timeago_earlier,17 days
-
@admin Please explain about two fields AUTH_TOKEN and correlation_id. How to get values for these two fields?
- topic:timeago_earlier,7 days
-
-
@nehak During market hours, live data is coming.
-