Unable to fetch data using Python SDK
-
I am trying to fetch market data using the Python SDK. The reference documentation I am following is from here:
https://github.com/angelbroking-github/smartapi-pythonThe code is copy pasted from here without the order bit. On running the code, the on_close event gets triggered with the following code and reason:
Code = 1006
Reason = "connection was closed uncleanly (I dropped the WebSocket TCP connection: global name 'JSON' is not defined)"Is it a missing library that I need to install or some code issue? Can someone advise pls?
-
Hi @mrchharus , please share your contact details on api@angelbroking.com
-
@admin Would you mind helping me sir as I've cross checked the feed token again and tried your another code to fetch data but it still the same
-
@admin I've been using this feed token from the starting
-
@mrchharus you're passing wrong feedToken. Please review.
-
@kpsidd !Hey I'm facing the same problem from last 2 days , but it was working fine before that This is my code and ouput
-
@rjbanna Sorry, missed your reply.
I have the latest SDK. I will try out with your code and see it.
Will update.
-
@kpsidd Do you have the latest python SDK? I'm using the following code for the socket streaming.
import time, json from smartapi import SmartConnect, WebSocket obj = SmartConnect(api_key="KEY") data = obj.generateSession("USER_ID","PASS") CLIENT_ID = 'ID' FEED_TOKEN = obj.getfeedToken() token = 'nse_cm|2885' ss = WebSocket(FEED_TOKEN, CLIENT_ID) def on_tick(ws, ticks): print(ticks) def on_connect(ws, response): print("on connect") ws.send_request(token) def on_close(ws, code, reason): print("on close") ws.stop() ss.on_ticks = on_tick ss.on_connect = on_connect ss.on_close = on_close ss.connect()
-
Can someone help with this please?