Can I generate session and tokens once and use them for trading and websockets ?


  • Hi @admin @bhaveshjain,

    So far I was using only Websockets and for that I generate feedtoken in the morning and use it whole day ( of course if there is no disruption ).

    In a similar manner is it possible to generate smart connect object using tokens generated before or do I need to go through generate session each time for broking operations ?

    @rjbanna and other experienced users please step in.

    Thanks in advance for your time and effort.


  • @rjbanna Thanks got it..


  • @rajanprabu Which trading object are you referring to? If you have generated the feed token, then you must have generated the trading object using the generateSession method. Then use this object to generate the required tokens and save them to session for later use.


  • @rjbanna Thanks for the response. I use the feedtoken for Websockets and I have no issues. but for broking operations how do I re use the tokens ?

    sample code given here
    https://github.com/angelbroking-github/smartapi-python

    obj=SmartConnect(api_key="your api key")
    
    data = obj.generateSession("Your Client ID","Your Password")
    refreshToken= data['data']['refreshToken']
    

    how do I generate trading object with tokens already obtained ?


  • @rajanprabu You need to generate tokens only once and you can reuse it whenever required. They are valid for day, but if you don't use it for let's say 2 to 3 hours then I guess they will become invalid. I don't know the exact timings. I have experienced similar behaviour. Also do remember that, if you login through the web browser, then those previously generated tokens will become invalid and you will need to regenerate it.