I am writing a separate module to get positions according to following - (still on kite2.0) positions = kite.positions() I am passing 'token' and 'kite' as parameters. 'Token' is to identify positions against the instruments subscribed to.The function defined in this module is called in on_tick method on ipython IDE. kite is initialised in the IDE and token comes from ticks data. However when run , it throws the error - kiteconnect.exceptions .Token exception :invalid session . When called directly on ipython notebook , it is giving me correct positions. Can someone help me identify the mistake I am making?
Hi, You will get invalid session error(TokenException) only when you are passing invalid api_key or access_token. You can print the final URL that is being sent and check if all the params are sent properly or not.
Thanks sujith. Actually I am able to get what I want when I run my code on jupyter note book - like getting the url then request token and subsequently, access token and public token -among other data. However when I want to run my python module under on_tick then the question which I was facing was - what parameters should I pass to my function which will fetch my positions. I was thinking since I had already initialised kite instance on jupyter notebook , passing kite and token to my function should work. However it did not. After your reply I collected the data in a dictionary and referenced this dictionary in my function to extract the access token , which is required to be set to get positions. Something like this- kitedata = kite.request_access_token(access_token) # on interpreter And following in the module: def mypositions(kitedata): kite.set_access_token(kitedata["access_token"]) positions = kite.positions() return positions Now I can call the module and the function 'mypositions' therefrom. Though I achieved what I wanted to , did you mean to have any other/different approach in mind while replying, as I could not understand properly. Else you may close this thread. (I am novice to programming world - so my language may sound ambiguous at places)
Hi, The request_access_token will take request token as the argument. It is called to generate a new access token when you receive request token. You shouldn't be calling this method. You need to call set_access_token method.
PS: Kite Connect 1 will be deprecated soon. You shouldn't be spending time on this. I would suggest migrating to Kite Connect 3.
You will get invalid session error(TokenException) only when you are passing invalid api_key or access_token. You can print the final URL that is being sent and check if all the params are sent properly or not.
After your reply I collected the data in a dictionary and referenced this dictionary in my function to extract the access token , which is required to be set to get positions. Something like this-
kitedata = kite.request_access_token(access_token) # on interpreter
And following in the module:
def mypositions(kitedata):
kite.set_access_token(kitedata["access_token"])
positions = kite.positions()
return positions
Now I can call the module and the function 'mypositions' therefrom. Though I achieved what I wanted to , did you mean to have any other/different approach in mind while replying, as I could not understand properly. Else you may close this thread.
(I am novice to programming world - so my language may sound ambiguous at places)
The request_access_token will take request token as the argument. It is called to generate a new access token when you receive request token.
You shouldn't be calling this method. You need to call set_access_token method.
PS: Kite Connect 1 will be deprecated soon. You shouldn't be spending time on this. I would suggest migrating to Kite Connect 3.