It looks like you're new here. If you want to get involved, click one of these buttons!
api_key = 'XXXXX'
api_secret = 'XXXXXX'
# Log in on website and get token:
kite = KiteConnect(api_key)
# Launch browser login to get request_token
tkn = input('Enter request Token')
user = kite.generate_session(tkn,api_secret)
kite.set_access_token(user['access_token'])
# is the user['access_token'] the public token required to login to KiteTicker?
kws = KiteTicker(api_key,user['access_token'])
def on_ticks(ws, ticks):
# Callback for tick reception.
print(ticks)
# Connect callback
def on_connect(ws, response):
# Callback for successful connection.
# Subscribe to a list of instrument_tokens
# (RELIANCE:BSE and INFOSYS:BSE here).
tokens = [
153683204,
153653508,
]
ws.subscribe(tokens)
# Set all symbols to tick in `full` mode.
ws.set_mode(ws.MODE_FULL, tokens)
print('Connected!')
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.connect()
A request token is valid only for a couple of minutes and can be used only once.
Once you have an access token store it and re-use it until it is expired.
In the above code, you just need to remove generate session. You should only call it when the existing access token is expired.
kws = KiteTicker(api_key,user['access_token'])?
The reason I ask, is that I cannot manually refresh the token every 24 hours, and the only option is to then generate a token every time I run kiteticker which is an unnecessary burden on the api server as well as time wasted in gettign the ticks at my end.
It is mandatory by the exchange that a user has to log in manually at least once a day. We don't recommend automating login flow.