osparamatrix / ks-orderapi-python

47 stars 59 forks source link

Added set_session_token function #40

Open algowhizz opened 3 years ago

algowhizz commented 3 years ago

Hi, I have added a function which allows the user to pass session_token generated via curl or requests using various session_API login methods like OTT. Once session_token is generated, it can be set using client.set_session_token as :

client = ks_api.KSTradeApi(access_token = access_token, userid = user_id, 
                                        consumer_key = consumer_key, ip = kotak_ip, app_id = kotak_appId)
client.set_session_token(session_token=user_session_token)

followed by usual client operations. I believe this is a good functionality to add because it allows user to initiate client without OTP access_code.

jayakarthik-devices commented 2 years ago

@algowhizz Where can i get user_session_token ? Can you guide me on that.

algowhizz commented 2 years ago

@algowhizz Where can i get user_session_token ? Can you guide me on that. https://github.com/algowhizz/kotakapi/blob/23c37c480d0422dbf2e185caa57132b02a84fa6f/2fa_ott_login.py This is the code you need to use to generate the session token given by https://github.com/algowhizz/kotakapi/blob/23c37c480d0422dbf2e185caa57132b02a84fa6f/2fa_ott_login.py#L36

jayakarthik-devices commented 2 years ago

@algowhizz Thanks for providing the info. This is really helpful.

One last question on this..

  1. My understanding based on the code that you shared is OTT will remain constant till we change any one of parameter like the password, consumer key, access token. So if that is changed we need to regenerate OTT.
  2. Session Token part of the python code is something i can integrate in my regular python code that will generate a new session token for every session.

Is my understanding correct.

algowhizz commented 2 years ago
  1. My understanding based on the code that you shared is OTT will remain constant till we change any one of parameter like the password, consumer key, access token. So if that is changed we need to regenerate OTT.

OTT needs to be generated everyday as it basically replaces the OTP that you receive via e-mail or SMS. Since it is easier to generate OTT than fetch OTP using selenium, I have written the script for automated OTT and session token generation every day.

  1. Session Token part of the python code is something i can integrate in my regular python code that will generate a new session token for every session.

Since OTT has to be generated everyday, the session token follows the OTT. So, the procedure is as simple as : generate OTT followed by session token (valid for 1 day). Then use the session token in your further code. If you dont wish to do all this, you can simply use the standard method where OTP is used to initialise ks_client.

jayakarthik-devices commented 2 years ago

@algowhizz Thanks for answering the questions. This method is easier. I will take this.

jayakarthik-devices commented 2 years ago

@algowhizz One more question... In the previous method where I manually give access code(OTP) and login, if I try to login again in a different system, it will automatically kill my session in previous system. But now with this method, it is not killing my previous system. How to kill a kotak session connectivity in linux.