WebSocket functionality issue
-
Hi All,
I am using below code to get bid/ask volume.- from smartapi import SmartConnect
#from smartapi import WebSocket
from smartapi import SmartWebSocket
obj=SmartConnect(api_key=api_key)
data = obj.generateSession(clientId, password)
FEED_TOKEN=obj.getfeedToken()''' SBIN'''
token="nse_cm|3045"
task="dp" #'mw'|'sfi'|'dp'
ws = SmartWebSocket(FEED_TOKEN, clientId)def on_tick(ws, tick):
for i in tick:
if 'tbq' in i.keys():
print(i['tbq'])
print(i['tsq'])
ws.stop()def on_connect(ws, response):
ws.send_request(token,task)def on_close(ws):
ws.stop()ws.on_ticks = on_tick
ws.on_connect = on_connect
ws.on_close = on_closews.connect()
Challanges:
- While importing lib, from smartapi import WebSocket facing (C:\Users\kamal\anaconda3\lib\site-packages\smartapi_init_.py) error. Tried from smartapi import SmartWebSocket & it is working fine
- Ticker is not giving task 'dp', instead looping the task 'hb'.
__on_open################
{'task': 'cn', 'channel': 'NONLM', 'token': 'XXXXXX', 'user': 'XXXXXX', 'acctid': 'XXXXXX'}
2021-06-21 17:18:04.942797 : Start task in the background
{'task': 'hb', 'channel': '', 'token': 'XXXXXX', 'user': 'XXXXXX', 'acctid': 'XXXXXX'}
2021-06-21 17:18:34.953644 : Start task in the background
{'task': 'hb', 'channel': '', 'token': 'XXXXXX', 'user': 'XXXXXX', 'acctid': 'XXXXXX'}
2021-06-21 17:19:04.957672 : Start task in the background
{'task': 'hb', 'channel': '', 'token': 'XXXXXX', 'user': 'XXXXXX', 'acctid': 'XXXXXX'}
{'task': 'hb', 'channel': '', 'token': '0999895434', 'user': 'V183756', 'acctid': 'V183756'}
HeartBeat Sending Failed --> this is in loop after stopping manually.- I had to stop manually, tried but service running in background not able to stop.
I just need market depth, can someone help me/correct my code?
- from smartapi import SmartConnect
-
HI @sapravi6 said in WebSocket functionality issue:
@admin is your websocket got updated ?
We dont have any update on this our team is working on this.
-
@admin is your websocket got updated ?
-
HI @Kamal Currenlty we are working on websocket once fixed we will update you.
-
Thanks for the response,
I used same code for getting market depth. Total buy/sell volume. As per Official documentation says, "tbq/tsq" gives the numbers. But not present in API response.
32 tbq Total buy quantity
33 tsq Total sell quantitytask="dp"
Sample Output:
Ticks: [{'bno': '5', 'bno1': '14', 'bno2': '29', 'bno3': '26', 'bno4': '40', 'bp': '430.40', 'bp1': '430.35', 'bp2': '430.30', 'bp3': '430.25', 'bp4': '430.20', 'bq': '2778', 'bq1': '6556', 'bq2': '15776', 'bq3': '8624', 'bq4': '17065', 'bs': '450', 'bs1': '2518', 'bs2': '13472', 'bs3': '5992', 'bs4': '8936', 'e': 'nse_cm', 'name': 'dp', 'sno': '1', 'sno1': '16', 'sno2': '34', 'sno3': '23', 'sno4': '43', 'sp': '430.50', 'sp1': '430.55', 'sp2': '430.60', 'sp3': '430.65', 'sp4': '430.70', 'tk': '3045'}]I am trying to get "bid/ask" volume along with LTP, any alternate?
Thanks in advance,
Kamal. -
Hi @Kamal Please go thorugh the below doc
https://github.com/angelbroking-github/smartapi-python -
Could you help or can you share working code including packages along with versions
-
I faced the same issue today. Its frustrating that HB issues still not resolved.
-
@rajanprabu Thanks for your response
smartapi-python==1.2.9
websocket-client==1.1.0 -
Which SDK version are you using ??