Livefeed using sockets
-
I'm having issue fetching the live feed using the API. I tried the sample code given on the Github but somehow I'm not able to get the live feed. Below is the code I used. If anybody knows how to resolve this, please let me know.
CODE
import logging from smartapi import SmartConnect, SmartSocket obj = SmartConnect(api_key="API_KEY") data = obj.generateSession("CLIENT_ID","PWD") tokens = obj.generateToken(data['data']['refreshToken']) feedToken = tokens['data']['feedToken'] token = 'nse_cm|2885' logging.debug(feedToken) ss = SmartSocket(feedToken, 'CLIENT_ID') def on_tick(ws, tick): logging.debug("Ticks: {}".format(ticks)) def on_connect(ws, response): logging.debug("on connect") ws.send_request(token) def on_error(ws, code, reason): logging.debug("Connection error: {code} - {reason}".format(code=code, reason=reason)) def on_close(ws, code, reason): logging.debug("on close") ws.stop() ss.on_ticks = on_tick ss.on_connect = on_connect ss.on_error = on_error ss.on_close = on_close ss.connect(threaded = True) while True: def on_ticks(ws, ticks): helper_method(ticks) def helper_method(ticks): print("Ticks received from while loop: {}".format(tick)) ss.on_ticks = on_ticks
RESPONSE
PAYLOAD eJyLrlZKzFayUsrPVtJRKkksBrGT84Ds3OJ0EDM/Ly81uSQ1Rak2FgAaGQ1z DATA b'x\x9c\x8b\xaeVJ\xccV\xb2R\xca\xcfV\xd2Q*I,\x06\xb1\x93\xf3\x80\xec\xdc\xe2t\x103?//5\xb9$5E\xa96\x16\x00\x1a\x19\rs' PAYLOAD eJyLrlZKzFayUsrPVtJRKkksBrGT84Ds3OJ0EDM/Ly81uSQ1Rak2FgAaGQ1z DATA b'x\x9c\x8b\xaeVJ\xccV\xb2R\xca\xcfV\xd2Q*I,\x06\xb1\x93\xf3\x80\xec\xdc\xe2t\x103?//5\xb9$5E\xa96\x16\x00\x1a\x19\rs'
After this response, nothing happens.
-
@vishant as I can see you have implemented using js please can you share your code?
-
@rjbanna did you get solution on this
-
Thanks @Ashok
-
-
What does the response key:values mean?
Would be helpful if someone can explain what does the below values like tm,tvalue,ak,msg,etc mean, where can i find the documentation for these?Ticks: [{'name': 'tm', 'tvalue': '25/02/2021 23:31:21'}
Ticks: [{'ak': 'ok', 'msg': 'connected', 'task': 'cn'}] -
@rajanprabu are you asking about the error faced in Dec ? That is due to wrong formatting of the input text to the WS Script
-
@Ashok what was wrong ??
-
@admin
Getting same error
Co No:- 8000662244
mail:- mangroliyadj6293@gmail.com
Client id : D108750 -
@admin Thanks for your help. The issue is solved.
-
Hi @dheepi , please share your contact details on api@angelbroking.com
-
I am facing the exact issue faced by @dushyant . Even I used the same token: 3045 which is the token for SBIN-EQ.
{"token":"3045","symbol":"SBIN-EQ","name":"SBIN","expiry":"","strike":"-1.000000","lotsize":"1","instrumenttype":"","exch_seg":"NSE","tick_size":"5.000000"}
The data is from the instruments API. which means the instrument data is wrong?
BR
Dheepi -
Hi @dushyant , I suppose you're passing wrong feedToken. Please review.
-
Hi @admin @bhaveshjain I am using latest SMARTAPI-PYTHON and getting the below output only for token="nse_cm|3045". I have tried few more ticks as well but still getting the same output.
Ticks: [{'ak': 'nk', 'msg': 'hb', 'task': 'hb'}]
Ticks: [{'ak': 'nk', 'msg': 'hb', 'task': 'hb'}]
Ticks: [{'ak': 'nk', 'msg': 'hb', 'task': 'hb'}]
Ticks: [{'ak': 'nk', 'msg': 'hb', 'task': 'hb'}]
Ticks: [{'ak': 'nk', 'msg': 'hb', 'task': 'hb'}]
Ticks: [{'ak': 'nk', 'msg': 'hb', 'task': 'hb'}]Please let me know how can I get data.
-
@vishant I have created the new thread for the same.
-
Hi @rjbanna,
Request you to raise this same query as a general discussion. So that other people will also be informed about this.
-
@bhaveshjain Can you please elaborate following terms that I receive as a response from socket? They are to, lo, sp, c(if this is close, then which close is it referring to?), tk, bs, bp, cng, bq, ap, nc, name, tbq.
-
@bhaveshjain I checked the websocket API and it is working as expected. There is one typo in the README.md file on Github. In the code feedToken=obj.getFeedToken(), the function name is misspelt. In the smartConnect.py file, the function name is getfeedToken(). with the "feed" in lowercase where as in the example it is "Feed" with first letter capital. So kindly resolve that issue or else people will receive the following error "'SmartConnect object has no attribute 'getFeedToken'". Thanks
-
@bhaveshjain Sure, I'll check it and let you know soon.
-