---
name: zerodha-kite-algo-starter
description: >-
  Step-by-step skill for setting up a beginner-friendly, paper-first Python stack for Zerodha Kite Connect on AWS EC2 with a static IP, TOTP-based session refresh patterns, systemd/nginx deployment, and a small FastAPI dashboard with a generic demo strategy. Not financial advice; users are responsible for broker terms and compliance.
title: zerodha-kite-algo-starter
canonical_url: https://skilld.dev/gh/romit07/kite-algo-trade-skill
last_updated: 2026-11-12T02:34:28.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> 39 supporting files sit beside this SKILL.md. When the Skill refers to one, fetch https://skilld.dev/api/skills-raw/romit07/kite-algo-trade-skill/kite-algo-trade-skill/PATH with PATH replaced.
>
> If the user asked to install this Skill, run `npx skilld install romit07/kite-algo-trade-skill/kite-algo-trade-skill`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/kite-algo-trade-skill`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/romit07/kite-algo-trade-skill/kite-algo-trade-skill) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/kite-algo-trade-skill`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/kite-algo-trade-skill --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/kite-algo-trade-skill --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Zerodha Kite Connect — Algo starter (skill)

Use this document end-to-end: humans can follow it directly; AI coding agents should execute steps in order, stop on errors, and never commit secrets.

## Prerequisites

- Zerodha account with Kite Connect developer app approved (see `docs/01-kite-connect-app.md`).
- AWS account rights to create EC2, Elastic IP, and security groups (see `docs/02-aws-ec2-static-ip.md`).
- Local machine with Python 3.11+ for development tests; production target is Amazon Linux 2023 or Ubuntu on EC2.

## Safety and compliance

1. Read `DISCLAIMER.md`. This kit is **educational**; markets involve risk.
2. **Paper trading is the default** (`PAPER_TRADING=true`). Live orders require an explicit opt-in flag and understanding of broker rules.
3. Automating login and order placement is **your responsibility** under Zerodha’s terms and applicable regulations (including SEBI guidance). Do not bypass security controls.

## Phase A — Clone and configure (local)

1. Clone this repository.
2. Copy `.env.example` to `.env` and fill placeholders only on your machine. Never commit `.env`.
3. Create a virtual environment and install dependencies:

   ```bash
   python -m venv .venv
   source .venv/bin/activate
   pip install -r requirements.txt
   ```

4. Run unit tests (no network; Kite is mocked):

   ```bash
   pytest -q
   ```

## Phase B — Kite Connect app (console)

Follow `docs/01-kite-connect-app.md` to:

1. Register an app at `https://developers.kite.trade` with API key/secret, redirect URL, and postback URL.
2. Note **static IP / API whitelist** requirements for placing orders (EC2 Elastic IP must match the server that calls order APIs).

Record `KITE_API_KEY`, `KITE_API_SECRET`, redirect/postback URLs in `.env` using placeholders in docs — never real values in git.

## Phase C — AWS EC2 + Elastic IP

Follow `docs/02-aws-ec2-static-ip.md` to:

1. Launch Amazon Linux 2023 or Ubuntu; attach security group allowing SSH (22) from **your IP only** and HTTPS (443) from intended clients.
2. Allocate and associate an **Elastic IP**; whitelist that IP in the Kite developer console (primary; add secondary if documented).
3. Verify outbound IP on the instance: `curl -s https://ifconfig.me` must match the whitelisted Elastic IP.
4. Understand Elastic IP billing (charges when **unassociated** in some regions/account types) and pitfalls (orders must originate from the whitelisted machine).

## Phase D — TOTP and daily token refresh

Follow `docs/03-totp-automated-login.md` to:

1. Enable TOTP 2FA on Zerodha.
2. Store `ZERODHA_USER_ID`, `ZERODHA_PASSWORD`, `KITE_TOTP_SECRET` only in root-owned env files or a secrets manager — **never** in the repo.
3. Use the provided `kite_starter.auth` helpers: TOTP via `pyotp`, then obtain `request_token` and call `generate_session` → `access_token`. Prefer `EnvironmentFile=` in systemd pointing to `/root/.config/kite-starter.env` (mode `600`).

The implementation includes an **optional** automated credential login helper that may break if Zerodha changes web APIs — monitor logs and fall back to manual `request_token` from the official login URL when needed.

## Phase E — Run the app (development)

1. Export required variables (see `.env.example`).
2. Start the API:

   ```bash
   uvicorn kite_starter.app:app --host 127.0.0.1 --port 8000
   ```

3. Open `http://127.0.0.1:8000` — use dashboard user/pass from `DASHBOARD_USER` / `DASHBOARD_PASSWORD`.

4. Confirm **paper mode** in the status panel before any live testing.

## Phase F — Production deploy

Follow `docs/04-deployment.md` to:

1. Install the app under `/opt/kite-starter` (or similar) with a dedicated user; use systemd unit from `deploy/kite-starter.service`.
2. Put nginx in front with TLS (Let’s Encrypt or self-signed for private use); enable basic proxy to Uvicorn.
3. Restrict firewall (`firewalld` / `ufw`), enable log rotation, schedule **daily token refresh** timer, and backup SQLite DB + config.

## Phase G — Operations checklist

- [ ] Elastic IP still associated and whitelisted in Kite console.
- [ ] `PAPER_TRADING` remains default until consciously disabled.
- [ ] Risk limits set: `MAX_DAILY_LOSS_INR`, `MAX_ORDERS_PER_DAY`, kill switch file path.
- [ ] Monitor logs under `/var/log/kite-starter/` (see deploy docs).
- [ ] Review Zerodha circulars / API changes regularly.

## Phase H — Going live (only after paper validation)

Read `docs/05-going-live-safely.md` and confirm:

- `PAPER_TRADING=false` **and** `ENABLE_LIVE_ORDERS=true` together (no half-enabled states).
- `ORDER_TAG_PREFIX` scopes mass-cancel / square-off to **your** orders only.
- Postback URL registered to `https://YOUR_DOMAIN/postback/kite` with optional shared secret.

## Troubleshooting (short)

| Symptom | Check |
|--------|--------|
| Order rejected / IP error | Outbound IP vs Kite whitelist; NAT vs Elastic IP association |
| 403 on login helper | Zerodha changed login flow — use manual `request_token` flow |
| Dashboard 401 | `DASHBOARD_USER` / `DASHBOARD_PASSWORD` and nginx proxy headers |

## Where code lives

- Python package: `src/kite_starter/`
- Demo strategy: `src/kite_starter/strategies/demo_ema_crossover.py`
- Tests: `tests/`

When modifying behavior, **keep the demo strategy generic** (no real trading playbook, no production-style options rules).
