Zerodha Signal Bridge
A TradingView → Zerodha Kite execution platform for Indian markets — with fully automated daily broker login.
Client engagement — source code stays private. Shown: architecture, flows and UI.
This platform bridges TradingView strategy alerts to Zerodha Kite, India's largest retail broker — NSE and BSE cash equity plus NFO/BFO options and futures, including automatic conversion of TradingView's option symbols into Kite's own format.
Trades enter through two lanes. Webhook alerts execute immediately with bracket-style exits: a market entry (with a smart limit fallback), a limit take-profit and a stop-loss, all tick-size-compliant. A dashboard scheduler covers the second lane — stock and option orders pre-booked to fire at an exact IST date and time, with a last-price sanity check before commitment.
The genuinely hard problem here is authentication: Zerodha expires every API session daily by design. The platform solves it with zero-touch re-login — headless Chrome walks the broker's login flow, generates the two-factor TOTP code itself, and exchanges the request token for a fresh session. It triggers lazily, only when a session check fails mid-signal, so trading never waits on auth that isn't needed.
Three cooperating processes — web server, trading engine and scheduler — coordinate over file-based queues with UUID deduplication, and every entry, exit and error is mirrored to Telegram in real time.
System architecture
The modules that make it up, and how data flows between them.
Dashboard · webhook · instrument cache
Time-matched pre-booked orders
Headless daily broker login (TOTP)
Signal queue · bracket orders
Confirmations & rejections
Hover a module to trace what it feeds.
Signal flow
One TradingView alert, end to end — from webhook to bracket exits.
- 1
Alert arrives
TradingView posts the strategy alert — symbol, side, type, quantity, take-profit and stop percentages — to the webhook endpoint.
- 2
Validate & normalize
Clean signalQuantities and percentages parsed, derivatives auto-detected, TradingView option symbols converted to Kite format, exchange assigned — queued with a UUID.
InvalidThe signal is dropped and the exact reason lands in Telegram immediately.
- 3
Session check
Session liveThe broker session answers the health check — straight to execution.
Token expiredHeadless Chrome logs in with self-generated TOTP and exchanges a fresh token; if even that fails, the trade aborts with a Telegram alert.
- 4
Entry routing
Buy signalMarket entry; if the exchange blocks market orders (common in illiquid F&O), a marketable limit is computed from order-book depth, tick-rounded, and retried.
Sell signalNet position queried and closed with the same fallback, and all outstanding exit orders cancelled.
- 5
Bracket exits
Take-profit and stop prices are computed from the entry with decimal-precision tick rounding — ceiling for targets, floor for stops — and placed as limit and stop orders.
- 6
Scheduler lane
In parallel, pre-booked orders fire when the IST clock enters their tolerance window — after a live-price sanity check that aborts and alerts if the market has run away.
- 7
Telegram audit
Every entry, exit, rejection and session event is mirrored to Telegram with the computed prices.
Engineering highlights
The details that keep it alive with real money on the line.
Zero-touch daily auth
Headless Chrome login with self-generated TOTP, unique browser profiles per run and anti-automation-detection flags — the daily token expiry the broker enforces just disappears.
Lazy session refresh
The session is validated on every signal and regenerated only on failure — no scheduled logins, no stale-token windows.
Exchange-compliance pricing
Per-instrument tick sizes are cached and every exit price rounded directionally with decimal math — orders the exchange can't reject.
Marketable-limit fallback
When market orders are blocked, the engine builds an aggressive limit from live order-book depth instead of giving up the fill.
Idempotent by design
Every signal carries a UUID and the half-second poll loop dedupes on it — replays and double-posts can never double-trade.
Crash-safe settings
Atomic write-then-rename on every settings change and a thread-safe, weekly-refreshed instrument cache shared across processes.
Under the hood
The stack, and the system in numbers.