Zerodha Kite Connect tutorial

Zerodha API 2026: automate Kite Connect with Python

A practical setup guide for traders who want broker-ready Python automation without leaking tokens, duplicating orders, or confusing backtest code with live execution code.

Summary

  • Use Kite Connect for authenticated order, portfolio, margin, GTT, quote, historical, and WebSocket workflows.
  • Start with a clean token flow, then add order validation and a duplicate-order guard before going live.
  • For realtime ticks and historical candle data, use Zerodha's Connect plan; for basic order APIs, the Personal plan may be enough.

Prerequisites

Account and app

Zerodha trading account, Kite developer app, API key, API secret, and redirect URL.

Plan choice

Personal is free for order and portfolio APIs. Connect adds WebSocket and historical data for INR 500/month per app.

Risk checks

Define allowed symbols, max quantity, product type, order variety, and one-order-per-signal protection before live trades.

Step-by-step Kite Connect flow

  1. Create a Kite Connect app and save the API key and secret outside your source code.
  2. Open the official login URL and complete Zerodha login.
  3. Capture the request_token from the redirect URL.
  4. Exchange the request_token for an access_token with the Python client.
  5. Store the access token securely for the trading session.
  6. Place only validated orders, then log order_id, status, symbol, price, and source signal.

Working Python starter code

Replace placeholders with your own credentials. Do not commit API secrets to GitHub or paste live keys into shared chats.

from kiteconnect import KiteConnect

API_KEY = "your_api_key"
API_SECRET = "your_api_secret"
REQUEST_TOKEN = "request_token_from_redirect"

kite = KiteConnect(api_key=API_KEY)
session = kite.generate_session(REQUEST_TOKEN, api_secret=API_SECRET)
kite.set_access_token(session["access_token"])

order_id = kite.place_order(
    variety=kite.VARIETY_REGULAR,
    exchange=kite.EXCHANGE_NSE,
    tradingsymbol="INFY",
    transaction_type=kite.TRANSACTION_TYPE_BUY,
    quantity=1,
    product=kite.PRODUCT_CNC,
    order_type=kite.ORDER_TYPE_MARKET,
    validity=kite.VALIDITY_DAY,
)
print("Order placed:", order_id)

Common errors and fixes

ErrorLikely causeFix
403 or token invalidExpired access token, wrong API key, or reused request tokenRun the login flow again and exchange a fresh request_token once.
Order rejectedWrong symbol, exchange, product, lot size, or marginValidate against instruments, product rules, and margin before placing.
Duplicate ordersTradingView alert fired again or webhook retriedSave signal IDs and reject duplicates within the same candle or strategy state.
Rate limit errorsPolling quotes or placing too many requests too fastBatch quote calls, use WebSockets for ticks, and add request throttling.

FAQ

Is Zerodha Kite Connect API free in 2026?

Zerodha lists a free Personal API plan for order, GTT, alerts, margin, and portfolio APIs. The Connect plan adds realtime WebSocket data and historical candles for INR 500/month per app.

Do I need WebSocket data?

Use WebSockets when your system reacts to live tick data. If your order signal already comes from TradingView, your webhook receiver may only need validated order placement plus logging.

Should beginners automate live orders immediately?

No. Start with paper logs, then small quantity dry-runs, then live orders with max-loss, max-orders, and duplicate-signal protection.