Member-only story
Backtesting Gann Square of 9 Intraday Strategy Using Python and Zerodha API
9 min readSep 18, 2023
Getting Instrument Token of a Scrip Using Python and Zerodha API
The KiteConnect APIs
We shall be using Zerodha’s Kite Connect API to back-test the given dataset. We’re a Zerodha Partner and if you’ve signed up with Unofficed, then You’ll get access to the raw file used to make this tutorial.
Kite Connect offers REST-like HTTP APIs with a wide range of capabilities that will suffice our needs.
Step 1 — Initialization of Kite Object
As You can see from the example of KiteConnect Python API from Zerodha’s GitHub, Step 1 is to create the Kite object
import logging
from kiteconnect import KiteConnect
logging.basicConfig(level=logging.DEBUG)
kite = KiteConnect(api_key="your_api_key")
# Redirect the user to the login url obtained
# from kite.login_url(), and receive the request_token
# from the registered redirect url after the login flow.
# Once you have the request_token, obtain the access_token
# as follows.
data = kite.generate_session("request_token_here", api_secret="your_secret")
kite.set_access_token(data["access_token"])