DEV Community

Ilyaz K
Ilyaz K

Posted on

Automating Zerodha Kite Orders with Python: What to Plan Before You Code

Indian traders often start automation with a short Python script and the Kite Connect API. The first order goes through in an afternoon. The problems show up later: the token that expires every morning, the order that fails at 9:15 because of a price band, the script that keeps running after a network drop and sends the same order twice.

Here is what to plan before you write the trading logic.

The daily login

Kite Connect access tokens are valid for one trading day. Your system needs a clear morning step: the login, the request token, and the exchange for an access token. Decide who does it and when. If it is a person, put it in a checklist. If it is automated, keep the credentials outside the code and log every login attempt.

Order types and product codes

Write down, per strategy, which product you use (MIS for intraday, CNC for delivery, NRML for F&O carry) and which order type (market, limit, SL, SL-M). Exchanges and brokers reject some combinations, and the error text arrives as a string you need to handle, not ignore.

Rate limits and retries

The API limits how many requests you can send per second. A loop that checks positions on every tick will hit that limit. Batch your reads, and give every order a unique tag so a retry after a timeout can check whether the first attempt already went through.

Market hours and special sessions

Pre-open, normal market, closing session, and the occasional special trading session on a weekend all behave differently. Your scheduler should know the exchange calendar instead of assuming 9:15 to 15:30 every weekday.

Signals from outside

Many traders want orders to come from TradingView alerts or a Telegram channel rather than from their own script. That adds a parser and a webhook endpoint, and it needs the same care: duplicate alerts, symbol names that differ from NSE trading symbols, and lot sizes for F&O contracts.

Logging that helps later

Store every signal, every order request, and every broker reply with timestamps. When something goes wrong at 10:02 on a busy day, this log is the only way to know whether the signal, the code or the broker caused it.

Getting it built

At AlgoDevelop we build broker automation for Zerodha, Upstox, Angel One, Fyers and other Indian brokers, plus MT4/MT5 Expert Advisors and signal copiers. Each project comes with the source code.

Test with small quantities first. Automation repeats mistakes as quickly as it repeats good trades.

Top comments (0)