I am new to the kite.dev forum and coding in general.. I tried following the exact steps and resolved bugs in the way, thanks to this forum only.. But after everything is done, I am not getting any data after executing kws.connect(), I am also not getting any error. I am trying during the market hours only.
You will need to enable/set debug level logging as you are logging ticks here logging.debug("Ticks: {}".format(ticks)). You won't need to, if you direct print the ticks, print(ticks).
kite.set_access_token('my_access_token')
I have edited out your publically posted access_token. Avoid posting any account-related credentials, as it can lead to compromise. Access token need to be set to make API or WebSocket connection. This documentation explains login flow in detail.
Here is a WebSocket usage example for the Python client.
Am I doing something wrong?
from kiteconnect import KiteConnect
from kiteconnect import KiteTicker
import logging
api_key = ''
api_secret = ''
kite = KiteConnect(api_key)
kite.login_url()
request_token = ''
kite.generate_session(request_token, api_secret)
access_token = ''
public_token = ''
# Websocket code below
kws = KiteTicker(api_key, access_token)
def on_ticks(ws, ticks):
logging.debug("Ticks: {}".format(ticks))
def on_connect(ws, response):
ws.subscribe([1304833]) # Zomato
ws.set_mode(ws.MODE_FULL, [1304833])
def on_close(ws, code, reason):
ws.stop()
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close
kws.connect()
Solved the problem. Made 3 changes, not sure what exactly worked:
- uninstalled and re-installed websocket library
- Added this to the code: - Added this also to the code:
logging.debug("Ticks: {}".format(ticks))
. You won't need to, if you direct print the ticks,print(ticks)
. I have edited out your publically posted access_token. Avoid posting any account-related credentials, as it can lead to compromise. Access token need to be set to make API or WebSocket connection. This documentation explains login flow in detail.