Step-by-Step Guide to Generate Access Token in Zerodha Kite API
Algo Trading is a method of trading in the stock market where computer programs automatically place buy and sell orders based on pre-defined rules. These rules are created using mathematical models, technical indicators, or market conditions.

1. API Key & API Secret
- When you create an app on Kite Developer Console, Zerodha gives you:
- API Key → a public identifier for your app.
- API Secret → a private key (keep it confidential).
These are permanent for your app (unless you regenerate them).
2. Request Token
- The request token is a temporary code generated every time a user logs in through Kite’s login URL.
- Flow:
- You redirect the user to Zerodha Kite login with your API key.
- The user logs in with their Zerodha credentials & OTP.
- Zerodha redirects back to your redirect URL with a request_token (valid only once and for a few seconds).
- Example:
https://your-redirect-url.com?request_token=rakeshtest
3. Access Token (most important for Algo Trading)
- You exchange the request token + API secret (using Kite SDK / API call) to get an access token.
- The access token is what you actually use for trading APIs (place order, fetch data, etc).
from kiteconnect import KiteConnect
# Define your API credentials
api_key = "your_api_key"
api_secret = "your_api_secret"
# Create KiteConnect instance
kite = KiteConnect(api_key=api_key)
# Set your request token
request_token = "your_request_token"
# Generate session and fetch access token
data = kite.generate_session(request_token=request_token, api_secret=api_secret)
access_token = data["access_token"]
# Set the access token for subsequent requests
kite.set_access_token(access_token)
Explanation:
from kiteconnect import KiteConnect
- Purpose: Imports the KiteConnect class from the kiteconnect library.
- Why it matters: This class allows you to interact with Zerodha’s Kite Connect API for trading, fetching data, and managing your account.
api_key = "your_api_key"
api_secret = "your_api_secret"
- Purpose: Stores your API credentials as strings.
- Why it matters: These are provided by Zerodha when you create an app on their developer platform. They authenticate your app
kite = KiteConnect(api_key=api_key)
- Purpose: Creates an instance of the
KiteConnectclass using your API key. - Why it matters: This object (
kite) is your gateway to all API operations like placing orders, checking positions, etc.
request_token = "your_request_token"
- Purpose: Stores the
request_tokenreceived after user login. - Why it matters: After the user logs in via the Kite login URL, Zerodha redirects to your app with a
request_token. This token is needed to generate the access token.
data = kite.generate_session(request_token=request_token, api_secret=api_secret)
- Purpose: Exchanges the
request_tokenfor anaccess_tokenusing your API secret. - Why it matters: The
access_tokenis what allows you to make authenticated API calls on behalf of the user.
access_token = data["access_token"]
- Purpose: Extracts the
access_tokenfrom the response dictionary. - Why it matters: You’ll need this token to authenticate future requests.
kite.set_access_token(access_token)
- Purpose: Sets the
access_tokenin yourkiteobject. - Why it matters: This step is essential before making any further API calls like placing orders or fetching market data.
Fastrack Astor FS2 Pro 1.96" Super AMOLED Smart Watch
Amazon
- Fastrack Astor FS2 Pro 1.96" Super AMOLED Smart Watch, Metal Body with 1000 Nits Brightness, SpO2, BP & Sleep Monitor, BT Calling, 100+ Sports Modes – Smartwatch for Men & Women (Rose Gold)
- Premium Display & Metal Design - 1.96” Super AMOLED screen with 1000 nits brightness, Always-On Display,
We earn a commission if you make a purchase, at no additional cost to you.
3 Comments
sign up for binance
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
admin
Thank you for your kind words! I’m glad you found the perspective interesting.
Please feel free to ask your question—I’ll be happy to help.
binance Registrera
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.