KiteBase
A module that manages the KiteConnect instance and provides robust API features to dependent modules.
Background
KiteBase is a core module which manages login and routes API requests in a robust manner.The module implements common core methods, and stores common attributes used widely in dependent modules.
The system automatically exits at a user-prescribed time. Check workflow below for more.
Download
Visit the Download section to get the setup script. Chose(1) KiteBase
during installation. You will need a secret code to install
the package onto your system. Please contact me @harshnisar on Twitter or Telegram for the code.
Workflow
KiteBase lets the user log into a KiteConnect session. Simply follow the steps below:-
Import modules
>> from Instance import Instance
-
Generate an Instance
>> I = Instance()
The user has been logged in. The scrip masters have been loaded as attributes. Telegram Bot Messaging methods have been made accsible, if selected. Robust KiteConnect API access methods are now available for use.
If you are a new KiteConnect user, please start with the
headless
flag set to False
so as to manually authorize KiteConnect to link to Kite.
See the Information section for more details.
Information
Instance Module: KiteConnect API will be logged into and the session's instance will be stored here.-
Login: Credentials stored during setup will be used to log-in to your app on KiteConnect.
In order to modify these credentials, use the
modify_cred
arguement and provide the updated values.
>> I = Instance(modify_cred=True)
-
First Time Authorization: For a new KiteConnect user, Zerodha asks for one time authorization to enable linking Kite and KiteConnect. To do this, launch with the
headless
flag set toFalse
>> I = Instance(headless=False)
After ever auto-action in the browser, press return in the python console for the next action, except for the authorization part, where the user needs to manually click on Authorize. -
Scrip Master: At login, a master scrip file is downloaded and saved. Because of this login will take a few seconds depending upon your connection. Check the master to see all available instruments for the day.
>> I.master
-
Kite: All API calls to KiteConnect are made thru the
kite
attribute ofInstance
. For example:
>> I.kite.ohlc('NSE:INFY')
-
ReKite: There is a restriction to the number of simultaneous requests in KiteConnect. When the number of these requests exceed the limit, the API throws an exception, which breaks a thread if not handled correctly. ReKite is a wrapper around Kite which makes all those API calls for you but if an exception is raised indicating exhaustion of simultaneous requests, it waits a bit and retries till the API successfully returns without exception.
So instead of calling kite methods thru kite, one can call them thru rekite.
>> I.rekite.ohlc('NSE:INFY')
-
Password: is provided as a prefilled argument to aid complete automation.
I = Instance(password="ae4awsf#AS?2sdfS")
-
host
: should be set to'localhost'
orFalse
when running from a local machine. The default value is for the cloud implementation where the webapp will send a login link to the user for every 2FA.I = Instance(host=False)