feat: add Zerodha Kite Connect broker support for Indian equities - #1193
feat: add Zerodha Kite Connect broker support for Indian equities#1193ashutoshsinghpr7 wants to merge 6 commits into
Conversation
- New connector at agent/src/trading/connectors/zerodha/{__init__,sdk,classification,profiles}.py
implementing the read path (get_historical_bars) via kiteconnect, with
interval mapping, 2000-day pagination, and IST->UTC normalization.
- Wire zerodha into the india_broker loader _resolve_broker() so the
india_equity backtest can be fed Kite data (opt-in, requires_auth).
- Register zerodha profiles in trading/profiles.py and live classification in
live/registry.py (paper-only order guard, default-deny live gate).
- Add test_zerodha_broker_loader.py (discovery, symbol/exchange mapping,
envelope parse + window clip). All 11 broker-loader tests pass.
Resolves upstream feature request HKUDS#1192.
|
cc @santhreal — you built the Dhan integration and the It follows the same pattern as your Dhan/Shoonya connectors ( Specific things I'd value your review on:
|
it was only a surface level review. I think @warren618 will provide a deeper review and decide if these are worth fixing and whether the overall pr is fine. |
i think so |
…closed, interval-aware pagination, cred-gated availability, cached instruments, service-layer surface Addresses the review findings on PR HKUDS#1193: - day bars keep their IST calendar date instead of shifting -1 day to UTC - 4h rejected (fail closed) instead of silently returning daily candles - per-interval Kite request caps (1m 60d / 5m 100d / 15m·30m 200d / 60m 400d / day 2000d); 1h window no longer truncated to 5 days - pagination advances past the inclusive chunk boundary (no duplicate bars) - zerodha_available() gates on credentials so an unconfigured install never shadows Shoonya/Dhan - instrument dump cached per exchange; token resolved once per fetch - service.py broker_sdk dispatch entry + get_account_snapshot/get_positions/get_open_orders/cancel_order and service-surface place_order kwargs - unit tests for all fixed behaviors
|
Thanks for the review @santhreal — all four points are addressed in the updated branch, plus a few more found in a deeper pass:
Also fixed in the same pass: Day-bar timezone: Kite day candles (midnight IST) keep their IST calendar date instead of shifting −1 day to UTC, so the loader's date-range clip no longer drops the first day of a window. |
…at/zerodha-kite-connect
Summary
Resolves #1191. Adds Zerodha Kite Connect as a third India-equity broker alongside Shoonya and Dhan, so the
india_equitybacktest can be fed Kite historical data (and live read paths exposed behind the existing paper-only / default-deny gates).Changes
agent/src/trading/connectors/zerodha/(__init__.py,sdk.py,classification.py,profiles.py):get_historical_bars(symbol, *, exchange, period, limit)viakiteconnect, with project-interval to Kite-interval mapping (1m/5m/15m/30m/1h/4h/1d), 2000-day pagination (Kite hard cap), and IST to UTC index normalization matching the existing loaders.RELIANCE.NS/500325.BOto Kiteexchange=NSE/BSE,tradingsymbol=RELIANCE; instrument token resolved viakite.instruments.requires_auth(needs an access token); paper-only order guard (Kite has no sandbox), so live order placement is structurally refused.india_broker_loader._resolve_broker()now preferszerodha(then shoonya, then dhan).trading/profiles.pygains the three Zerodha profiles;live/registry.pygains the curated READ/WRITE classification (default-deny).test_zerodha_broker_loader.py(discovery, symbol/exchange mapping, envelope parse + window clip).Validation
pytest agent/tests/test_zerodha_broker_loader.py agent/tests/test_india_broker_loader.py-> 11 passed, no regressions.zerodha_available()correctly degrades to False whenkiteconnectis absent (loader stays inert in CI/unconfigured runs).get_quote('RELIANCE', NSE)returned live LTP;get_historical_bars('RELIANCE', NSE, 1d)returned real daily OHLCV+volume;get_historical_bars('INFY', NSE, 1m)returned intraday bars (interval mapping works). All read-only calls — no order-placement path was exercised (the connector structurally refuses non-paper orders).Privacy / no credentials in this PR
This diff contains no real credentials, tokens, client IDs, or personal account data — only code identifiers (
api_key,access_token, etc.). Connector config lives in a user-levelzerodha.json(0600 perms, git-ignored) and is never committed.Notes for maintainers
kiteconnectis an optional dependency (not added to core requirements); the connector imports defensively.access_tokendirectly inzerodha.json.Happy to adjust to repo conventions if any differ.