Kite Connect is Zerodha's official trading API. It is well documented, genuinely reliable, and the authentication flow confuses almost everyone on their first attempt. This walks through the whole thing in order.
What Kite Connect actually is
It is an HTTP REST API. Your code sends requests, Zerodha's servers act on them. From Python you can read live prices, pull historical candles, place and modify orders, and check your positions.
It costs ₹2,000 per month per app. That is a real cost and worth deciding on deliberately — if you are only going to run one strategy on one account, it is fine. If you are still exploring whether algo trading suits you, backtest on free data first and pay for the API when you are close to going live.
1. Create the app
- Go to developers.kite.trade and log in with your Zerodha credentials.
- Choose Create new app, pick the Connect type, and give it a name and a redirect URL.
- The redirect URL can be
http://127.0.0.1while you are learning. It only needs to be somewhere you can read the address bar after login. - Once created you get an API key and an API secret. Copy both. Treat the secret like a password — it does not belong in a public repository.
2. Install the library
pip install kiteconnect
3. Generate an access token
This is the step people get stuck on, so here is what is happening rather than just the code. Zerodha will not let a script log in with a password. Instead you open a login URL in a browser, log in as a human, and Zerodha redirects you back with a one-time request_token. Your script exchanges that for an access_token.
from kiteconnect import KiteConnect
api_key = "your_api_key"
api_secret = "your_api_secret"
kite = KiteConnect(api_key=api_key)
print(kite.login_url())
# Open this URL in a browser, log in, then copy request_token
# from the redirected address bar
request_token = "PASTE_HERE"
data = kite.generate_session(request_token, api_secret=api_secret)
access_token = data["access_token"]
print("Access Token:", access_token)
The access token expires at the end of the trading day. Every morning you do this again. Save it to a file or a small database so the rest of your code can just read it instead of re-authenticating on every run.
4. Read a price
kite.set_access_token(access_token)
ltp = kite.ltp(["NSE:RELIANCE", "NSE:TCS"])
print(ltp)
If this works, your setup is correct. If it throws a token error, the problem is step 3, not step 4.
5. Place an order
order_id = kite.place_order(
variety=kite.VARIETY_REGULAR,
exchange=kite.EXCHANGE_NSE,
tradingsymbol="RELIANCE",
transaction_type=kite.TRANSACTION_TYPE_BUY,
quantity=10,
product=kite.PRODUCT_MIS,
order_type=kite.ORDER_TYPE_MARKET
)
print("Order placed:", order_id)
A returned order ID means the order reached Zerodha. It does not mean the order filled. Those are two different things, and assuming they are the same is the source of a lot of confusing bot behaviour. Check the order status separately before acting on the assumption that you now hold a position.
6. Historical data
from datetime import datetime
data = kite.historical_data(
instrument_token=738561, # RELIANCE
from_date="2026-01-01",
to_date="2026-04-26",
interval="day"
)
print(data[:5])
You need the instrument token, not the symbol. Download the full instrument list once with kite.instruments(), store it, and look tokens up from there rather than hardcoding numbers you will not recognise in three months.
7. Live ticks over WebSocket
from kiteconnect import KiteTicker
kws = KiteTicker(api_key, access_token)
def on_ticks(ws, ticks):
print(ticks)
def on_connect(ws, response):
ws.subscribe([738561]) # RELIANCE
ws.set_mode(ws.MODE_LTP, [738561])
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.connect()
Polling ltp() in a loop works for slow strategies and will get you rate limited on fast ones. If your logic reacts within seconds, use the WebSocket.
Errors you will actually see
- Token has expired — the daily one. Regenerate the access token.
- Invalid api_key — usually the app has been deactivated because the monthly billing lapsed.
- Insufficient funds — margin, not code. Check the account before debugging the script.
- Too many requests — you crossed a rate limit. See below.
Things worth doing before you go live
- Cache the access token in a file with the date, so a restart mid-day does not force a fresh browser login.
- Run on a VPS, not a laptop. Sleep, updates and Wi-Fi drops all happen at the worst possible moment.
- Log every order with its timestamp, parameters and the response. When something goes wrong at 10:04 you will want that file.
- Respect the limits — roughly 3 orders per second and 200 per minute. Build the throttle in from the start rather than after a rejection.
If you want a Kite-based system built properly — including reconnection handling, order state tracking and deployment — talk to us. That is the work we do, and most of it is the unglamorous parts this tutorial only mentions in passing.
FAQs
Is Kite Connect free?
No. It costs ₹2,000 per month per app. It is the most reliable retail trading API in India, but it is a recurring cost worth planning for before you commit.
How long does the access token stay valid?
Until the end of the trading day. A new token has to be generated every morning, which is why most people script the login step and cache the token in a file.
Can I do this without writing code?
There are no-code platforms such as Streak, and they work for standard strategies. The moment your logic needs something they do not support, you are back to writing it yourself in Python.
Does a returned order ID mean my order was filled?
No. It only means the order reached Zerodha. Fill status has to be checked separately, and treating the two as the same thing causes a lot of hard-to-debug bot behaviour.
Need a custom solution?
Instacode builds production-grade software — algo trading, ecommerce, web apps. Let's talk.
Get in Touch
💬 Comments (4)
확인했습니다 무료 스포츠 보기 그래서 더 찾아볼 필요 없겠어요 땡큐
nba중계
스포츠무료보기사이트
잘봤어요 스포츠무료중계 정보 정리가 깔끔해요.
아무튼 무료스포츠중계 정보 확인할 때 출처 꼭 체크해요.
좋은정보 계속 부탁드려요.
https://coktv1.com/
축구무료중계
epl중계
I blog frequently and I seriously appreciate your content.
Your article has really peaked my interest. I am going to bookmark your site and keep checking
for new details about once per week. I opted in for your Feed too.Vedonlyöntibonukset https://veikkaajille.com/sivukartta/
https://spinlander-lv.com
Man šķiet interesants Spinlander Casino Latvijā!|
Spinlander Kazino šķiet mūsdienīga spēļu vieta.|
Diezgan labs tiešsaistes kazino, īpaši tiem, kam patīk spēļu automāti.|
Spinlander piedāvā ērtu spēlēšanas pieredzi!|
Vienkāršs izkārtojums, spēles var atrast diezgan ātri!|
Šķiet labi, ka Spinlander Kazino Latvijā neizskatās pārbāzts ar lieku informāciju.|
Cilvēkiem, kuri izvēlas modernus spēļu automātus, Spinlander Casino Latvijā varētu šķist interesants.|
Reģistrācijas bonusi Spinlander Casino Latvijā var būt patīkams papildinājums!|
Pirms iemaksas veikšanas ir vērts iepazīties ar spēles
noteikumiem.|
Kopumā Spinlander Kazino Latvijā varētu
būt vienkāršs kazino variants!