Facing problem when streaming the live data
-
Can anyone please help me when I trying to fetched real time data using this code
from smartapi import SmartConnect from smartapi import WebSocket obj = SmartConnect(api_key=apikey) data = obj.generateSession(client_token, password) feedToken = obj.getfeedToken() FEED_TOKEN = feedToken CLIENT_CODE = client_token task = "mw" # 'mw'|'sfi'|'dp' token = "nse_cm|26009" WS = WebSocket(FEED_TOKEN, CLIENT_CODE) def on_tick(ws, tick): print(tick) def on_connect(ws, response): ws.send_request(token) # def on_close(ws, code, reason): # ws.stop() # Assign the callbacks. WS.on_ticks = on_tick WS.on_connect = on_connect # WS.on_close = on_close WS.connect()
it's display nothing like this____
can you please tell me what is happening????
I'm using python SDK -
It's working now I had given the wrong API key
please check the API key once @nayan_nandi -
WebSocket
from smartapi import SmartConnect
from smartapi import WebSocket
obj=SmartConnect(api_key="my_key")
data = obj.generateSession('Client_id', 'Pass')
feedToken=obj.getfeedToken()
FEED_TOKEN=feedToken
CLIENT_CODE="Client_id"
token="nse_cm|2885" #"nse_cm|2885&nse_cm|1594&nse_cm|11536"
task="dp" #"mw"|"sfi"|"dp"
ss = WebSocket(FEED_TOKEN, CLIENT_CODE)def on_tick(ws, tick):
print("Ticks: {}".format(tick))def on_connect(ws, response):
ws.websocket_connection() # Websocket connection
ws.send_request(token,task)def on_close(ws, code, reason):
ws.stop()Assign the callbacks.
ss.on_ticks = on_tick
ss.on_connect = on_connect
#ss.on_close = on_closess.connect()
print(tick) -
Please share your code for better diagnosis..
-
@nayan_nandi I am also facing the same problem
if it is fixed on your side please let me know -
@rajanprabu Thank sir I was missing this code, thanks for your help sir.......
-
You need to add
ws.websocket_connection()
try with the following code
from smartapi import SmartConnect from smartapi import WebSocket import creds obj = SmartConnect(api_key=creds.api_key) data = obj.generateSession(creds.client_token, creds.password) feedToken = obj.getfeedToken() print(feedToken) FEED_TOKEN = feedToken CLIENT_CODE = creds.client_token token = "nse_cm|2885" # Token number of RELIANCE-EQ task = "mw" # 'mw'|'sfi'|'dp' ss = WebSocket(FEED_TOKEN, CLIENT_CODE) def on_tick(ws, tick): print("Ticks: {}".format(tick)) def on_connect(ws, response): ws.send_request(token, task) # def on_close(ws, code, reason): # ws.stop() ss.on_ticks = on_tick ss.on_connect = on_connect # ss.on_close = on_close ss.connect()
-
@admin Sir I did but sowing same thing____
"C:\Python 3.9.2\python.exe" C:/Users/Nayan/PycharmProjects/Angel_Broking/main.py None <function on_connect at 0x00000026BF9B7F70> Ticks: [{'ak': 'nk', 'msg': 'mw', 'task': 'mw'}] Process finished with exit code -1
I'm using trading api.....
-
Hi @nayan_nandi can you please restart your system and give a try.
-
@admin How can i do it sir??
-
Hi @nayan_nandi try to restart you kernel and give a try.
-
Hi @nayan_nandi we will review the code and revert you back.
-
@admin So sir why i'm not getting feed. also when i trying to print feedToken it's show None what can i do.....
This is my code______from smartapi import SmartConnect from smartapi import WebSocket import creds obj = SmartConnect(api_key=creds.api_key) data = obj.generateSession(creds.client_token, creds.password) feedToken = obj.getfeedToken() print(feedToken) FEED_TOKEN = feedToken CLIENT_CODE = creds.client_token token = "nse_cm|2885" # Token number of RELIANCE-EQ task = "mw" # 'mw'|'sfi'|'dp' ss = WebSocket(FEED_TOKEN, CLIENT_CODE) def on_tick(ws, tick): print("Ticks: {}".format(tick)) def on_connect(ws, response): ws.send_request(token, task) # def on_close(ws, code, reason): # ws.stop() ss.on_ticks = on_tick ss.on_connect = on_connect # ss.on_close = on_close ss.connect()
-
Hi @nayan_nandi web socket is working fine from our end.
-
@admin Sir the issues is not not resolve yet. Same problem facing today also....
Please do something.... -
Hi @nayan_nandi we have tested the web socket today it is working fine now.
-
Hi @nayan_nandi we have tried to handle all this issues in the new version of python sdk.We will be testing it and reverting you back.
-
@admin Sir can you please tell me what is the issue is happening???
And why it's happening....... -
Hi @nayan_nandi we regret for the delay we will keep you updated on the issue.
-
@rajanprabu said in Facing problem when streaming the live data:
@nayan_nandi
if you using new 1.2.2 python SDK you need to send task parameter as well.
def on_connect(ws, response):
ws.send_request(token,'mw')did you try this @nayan_nandi ?