The Script Save KiteEnctoken to jsonbin.io, which can be used to synchronized Kite Enctoken between your local pc/laptop browser and Algo Trading Code at Remote Servers.
To set it up for the first time, you need to follow these steps. (Once all the steps completed, from next login onwards it will work automatically)
Now Type {"enctoken":"abcdefghijklmnopqrstuvwxyz"} in the text box and click create.
Now Click on the Profile Picture, Then Click on Dashboard
Now Copy the 24 Charachter long BIN_ID and save it on a notepad as BIN_ID = <PASTE 24 Charachter BIN_ID HERE>(For Example in this case it shall be BIN_ID = 6129d9bd2aa800361271257f)
Now Click on the VIEW MASTER KEY
And Copy the 60 Character long Master Key by clicking on COPY KEY and save it on a notepad as YOUR_API_KEY = <PASTE 60 Charachter Master Key HERE>(For Example in this case it shall be YOUR_API_KEY = $2b$10$IIWfEN3l97/jWpsxjBli0eUQopUdqzt0Ksx9dl87xGINSKxCesLte)
Now You may close the jsonbin.io website and open https://www.tampermonkey.net/ and download for chrome/firefox/edge/safari (whatever you use, In my case i will download for chrome)
Once TamperMonkey has been added to chrome click the extension button and find tampermonkey and click on pin so it should be visible
Now Open https://kite.zerodha.com/ and you will see the TamperMonkey Icon has a red notification with 1 written on it.
Click on It, and then click on the setting below SaveKiteEnctoken
Now Fill the Your Api Key with the MASTER KEY Saved in Point No. 7 and Bin id with the BIN ID saved in Point No.5 and then click on save.
Now Login to kite as usual, and the enctoken will automatically be updated.
Python Program Modification for obtaining enctoken automatically.
###############################################################################importrequestsdefget_enctoken(YOUR_API_KEY, BIN_ID):
enctoken_url="https://api.jsonbin.io/v3/b/"+BIN_ID+"/latest"headers= {
'X-Master-Key': YOUR_API_KEY
}
req=requests.get(enctoken_url, json=None, headers=headers)
enctoken=req.json()['record']['enctoken']
returnenctokenYOUR_API_KEY=<PASTE60CharachterMasterKeyHEREfromPointNo.7>BIN_ID=<PASTE24CharachterBIN_IDHEREfrompointNo. 5>enctoken=get_enctoken(YOUR_API_KEY, BIN_ID)
################################################################################## For Example in our case it will be# YOUR_API_KEY = "$2b$10$IIWfEN3l97/jWpsxjBli0eUQopUdqzt0Ksx9dl87xGINSKxCesLte"# BIN_ID = "6129d9bd2aa800361271257f"# enctoken = get_enctoken(YOUR_API_KEY, BIN_ID)#################################################################################
Hence, For Example if you want to run your code from colab just do like this and it wont log you out of your browser session. (and when your browser session expires and you relogin, the enctoken will automatically be updated and your algo code will work as intended without interruption)
Disclaimer: I have made this tool for my personal use and it may have bugs.