Zerodha Python automation means driving your Zerodha account from your own Python code using the official kiteconnect library (pykiteconnect) – logging in, placing and managing orders, reading positions and holdings, and streaming live market data. As of July 2026 you install it with pip install kiteconnect (current version 5.2.0), authenticate through Kite Connect’s OAuth login to get a one-day access token, and call methods like place_order() and the KiteTicker websocket. Order and account APIs are free for personal use; live and historical data cost Rs 500/month.
In my 8+ years building algo systems for clients across 14+ countries, Kite Connect remains the cleanest broker API in India for Python. This is the complete, evergreen tutorial. For the original launch-context walkthrough, see my earlier guide: Zerodha’s new API 2025: how to automate Kite Connect with Python. This 2026 edition goes deeper on orders, websockets, error handling and the new SEBI rules. It assumes basic Python familiarity but no prior trading-API experience, and every snippet below uses the real kiteconnect API so you can copy, paste and adapt it to your own strategy.
What you need before you start
- An active Zerodha account with Kite Connect enabled.
- A Kite Connect app created at the developer console (developers.kite.trade) for your
api_keyandapi_secret. - Python 3.8+ installed.
- A static IP – mandatory from April 2026 under SEBI’s algo framework (details below).
On pricing in 2026: the order-placement and account APIs (orders, positions, holdings, funds) are free for personal use, while real-time and historical market data is Rs 500 per month per API key (revised down from Rs 2,000). For most individual traders the free order APIs are enough to run a fully automated strategy; you only pay the Rs 500 if you need streaming quotes or historical candles for backtesting. I break the full cost-and-limits picture down in Zerodha Kite Connect API pricing and rate limits 2026.
Step 1: Install pykiteconnect
pip install kiteconnect
Confirm the version – you want 5.x (5.2.0 at the time of writing):
python -c 'import kiteconnect; print(kiteconnect.__version__)'
Step 2: API key setup and the login flow
Create an app in the Kite developer console, note the api_key and api_secret, and set a redirect URL. Login is a two-step OAuth flow: send the user to Kite’s login page, capture the request_token returned on the redirect, then exchange it for an access_token.
from kiteconnect import KiteConnect
kite = KiteConnect(api_key='your_api_key')
# 1. Open this URL, log in, and copy the request_token
# from the redirect URL.
print(kite.login_url())
# 2. Exchange the request_token for an access token.
data = kite.generate_session('request_token_here', api_secret='your_api_secret')
kite.set_access_token(data['access_token'])
print('Logged in as', data['user_id'])
Keep your api_secret out of source control – load it from an environment variable or a secrets manager, never hard-code it in a script you might share.
Token expiry: the access token is valid for a single trading day. Zerodha flushes tokens every morning between roughly 5:00 AM and 7:30 AM IST, so you must run generate_session again each day (a token generated at or after 7:30 AM stays valid until the next flush). In production I refresh the day’s token from a pre-market cron job and cache it.
Want a production-ready Zerodha bot without the trial and error? I build and deploy custom Kite Connect automations for traders. Message me on WhatsApp at +91 77352 68199 with your strategy.
Step 3: Placing, modifying and cancelling orders
Use place_order() with the variety, product and order-type constants exposed on the client. Here is an intraday (MIS) market buy for one share of INFY on NSE:
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_MIS,
order_type=kite.ORDER_TYPE_MARKET
)
print('Order placed:', order_id)
Modify a pending order (for example, convert it to a limit price) or cancel it:
# Modify to a limit order
kite.modify_order(
variety=kite.VARIETY_REGULAR,
order_id=order_id,
order_type=kite.ORDER_TYPE_LIMIT,
price=1500
)
# Cancel
kite.cancel_order(variety=kite.VARIETY_REGULAR, order_id=order_id)
Step 4: Positions and holdings
Read your long-term holdings and open positions with two calls:
# Long-term holdings (delivery)
holdings = kite.holdings()
# Open intraday and F&O positions
positions = kite.positions()
for p in positions['net']:
print(p['tradingsymbol'], p['quantity'], p['pnl'])
Step 5: Streaming live ticks with KiteTicker
For live prices, use the KiteTicker websocket instead of polling quotes. Subscribe by instrument token and choose a mode (LTP, quote or full):
from kiteconnect import KiteTicker
kws = KiteTicker('your_api_key', data['access_token'])
def on_ticks(ws, ticks):
print(ticks)
def on_connect(ws, response):
ws.subscribe([738561]) # INFY instrument token
ws.set_mode(ws.MODE_FULL, [738561])
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.connect()
In a real bot you would combine these pieces: authenticate once at market open, subscribe to your instruments over the websocket, run your signal logic on each tick, and route entries and exits through place_order with proper risk checks. Keep the websocket and your order logic in separate threads so a slow order call never blocks incoming ticks.
Error handling and rate limits
Kite enforces per-endpoint rate limits at the API-key level. Cross them and requests fail with HTTP 429.
| Endpoint | Rate limit |
|---|---|
| Quote | 1 request/sec |
| Historical candle | 3 requests/sec |
| Order placement | 10/sec (max 400/min, 5,000/day) |
| All other endpoints | 10 requests/sec |
Wrap calls and handle the typed exceptions – regenerate on token failures and back off on network errors. Every kiteconnect exception inherits from KiteException, so you can catch that as a final safety net while still handling the common cases explicitly:
from kiteconnect.exceptions import TokenException, NetworkException, OrderException
try:
kite.place_order(...)
except TokenException:
# access token expired - re-run generate_session
refresh_token()
except NetworkException:
# transient - retry with exponential backoff
retry_with_backoff()
except OrderException as e:
# order rejected by broker/exchange
print('Rejected:', e)
A practical tip from live desks: never fire orders in a tight loop. Throttle to stay under 10 orders/sec, and treat a 429 as a signal to sleep-and-retry, not to hammer harder.
2026 SEBI compliance and static IP
From 1 April 2026, SEBI’s retail algo-trading framework is fully mandatory (the rollout moved from August 2025 to October 2025 and then to this hard deadline). These rules apply to all retail traders using broker APIs, not just institutions, so factor them into your architecture from day one rather than retrofitting later. What it means for your Python bot:
- Static IP: only a static IP registered with Zerodha can send orders through the API – connections from any other IP are rejected. Run your script on a cloud VPS with a fixed IPv4 and register it in the console.
- OAuth + 2FA only: the login flow above is the only permitted authentication method; older login mechanisms are discontinued.
- Algo tagging: automated orders carry an exchange-assigned Algo-ID so every order is traceable to its source.
- Registration threshold: above 10 orders per second per exchange, a strategy must be formally registered as an algo through your broker.
I cover the full developer checklist in How to build SEBI-compliant algos in 2026.
Frequently asked questions
Is Zerodha Kite Connect free?
Partly. The order-placement and account APIs (orders, positions, holdings, funds) are free for personal use. Real-time and historical market data costs Rs 500 per month per API key as of 2026.
How long does a Kite Connect access token last?
One trading day. Zerodha flushes tokens each morning between about 5:00 AM and 7:30 AM IST, so you regenerate the access token daily via generate_session.
What is the order rate limit on Kite Connect?
10 orders per second, capped at 400 orders per minute and 5,000 orders per day per API key. Data endpoints have their own limits (quote 1/sec, historical candles 3/sec).
Can I automate Zerodha without Python coding?
Yes. You can bridge TradingView alerts to your broker with webhooks – see my guides for Fyers and Angel One, or hire a done-for-you build via my Pine Script and automation development service.
Do I need a static IP for the Zerodha API in 2026?
Yes. From April 2026, SEBI requires orders to originate from a static IP registered with your broker. A cloud VPS with a fixed IPv4 is the simplest way to comply.
Ready to automate your strategy on Zerodha? Whether you need a Python Kite Connect bot, a TradingView webhook bridge, or a full SEBI-compliant setup, I can build it. Chat with me on WhatsApp at +91 77352 68199.
Risk disclaimer: Trading and investing in securities carry a substantial risk of loss and are not suitable for every investor. Automated and algorithmic strategies can fail, misfire or amplify losses due to bugs, connectivity issues or market conditions. The code examples here are for educational purposes only and are not financial advice or a recommendation to trade. Test thoroughly in a paper or sandbox environment, comply with SEBI and exchange rules, and consult a SEBI-registered adviser before deploying real capital. Past performance does not guarantee future results.

Leave a Reply