Agent setup¶
Set up an AI coding agent to build on Kite Connect with the official Python
client, pykiteconnect. Install the
SDK with uv, work from the examples below, and use these docs as the API
reference.
Note
Point your agent at these instructions directly:
https://kite.trade/docs/connect/v3/agent-setup/prompt.md.
Paste that URL into your agent and ask it to run the setup.
Tip
Testing against the demo environment at sandbox.kite.trade? Use the
Sandbox reference and its ready-made agent prompt at
sandbox-prompt.md, which embeds a runnable
local-callback bootstrap script.
1. Install with uv¶
uv is the recommended way to manage and run Python. Add the SDK to a project:
uv init my-kite-app && cd my-kite-app
uv add kiteconnect
Or run a one-off script without a project:
uv run --with kiteconnect main.py
2. Authenticate¶
Kite Connect uses an OAuth-style login flow: send the user to the login URL,
capture the request_token from your registered redirect URL, then exchange it
for an access_token (valid for the trading day).
from kiteconnect import KiteConnect
kite = KiteConnect(api_key="your_api_key")
# Send the user to kite.login_url(); capture the request_token from the
# redirect URL after they log in.
print(kite.login_url())
# 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"])
See User for the full login flow and checksum details.
3. Place an order¶
place_order() returns an order_id. Use the SDK constants for the variety,
exchange, product, and order type.
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_LIMIT,
price=1500,
validity=kite.VALIDITY_DAY,
)
print("Order placed:", order_id)
Read positions and holdings with kite.orders(), kite.positions(), and
kite.holdings(). See Orders for every parameter and order variety.
4. Stream live market data¶
KiteTicker streams quotes over WebSocket through callbacks.
from kiteconnect import KiteTicker
kws = KiteTicker("your_api_key", "your_access_token")
def on_ticks(ws, ticks):
print(ticks)
def on_connect(ws, response):
ws.subscribe([738561]) # instrument_token for RELIANCE
ws.set_mode(ws.MODE_FULL, [738561])
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.connect()
See WebSocket streaming for packet structure and modes.
More examples¶
The SDK ships runnable examples for orders, GTT, margins, and the ticker: pykiteconnect/examples. Give these files to your agent as context when writing code.
Read the docs as Markdown¶
Use the examples above to write code, and these docs as the reference for parameters, constants, and response shapes. Every page is available as Markdown:
- Append
.mdto any page path, e.g.orders/index.md. - Or use the Copy as Markdown / View as Markdown actions at the top of any page.
Resources¶
- Python SDK: github.com/zerodha/pykiteconnect
- Python SDK reference: kite.trade/docs/pykiteconnect/v4
- Other languages: Libraries and SDKs
- Developer forum: kite.trade/forum