Fintech · Trading Automation

TrendEdge

Real-time Supertrend trading platform with automated Zerodha order execution, multi-symbol support, and forward testing.

PythonFastAPINext.jsTypeScriptZerodha KiteTickerSocket.IOPostgreSQLStockStatsKeycloakDocker

Status

Completed

Login

Auto 8:30 AM

Indicators

Supertrend · ATR

Segments

Equity · FNO · Options

Testing

Forward test mode

The Problem

Manually trading on Zerodha across multiple symbols requires constant attention, error-prone order placement, and slow reaction times — especially for options strategies that depend on rapid Supertrend signal reversals at exact price levels.

The Solution

A FastAPI backend auto-logs into Zerodha at 8:30 AM, saves access tokens to PostgreSQL for reuse, subscribes to live KiteTicker WebSocket feeds, computes Supertrend/ATR via StockStats, and executes orders automatically. A Socket.IO bridge streams everything to the Next.js frontend — including trade logs, positions, and P&L — in real time.

Features

Zerodha Integration

  • Automated Zerodha login exactly at 8:30 AM daily
  • Access token stored in PostgreSQL — reused to avoid redundant logins
  • Historical data fetched at 2+ req/sec with Zerodha rate limit management
  • KiteTicker WebSocket for live tick streaming as indicator source
  • Instrument fetch on login — NFO filtered and stored per exchange
  • Multi-symbol concurrent subscription with one-by-one rate-limited registration

Indicator & Signal Engine

  • Supertrend and ATR computed using StockStats library
  • Incremental historical data fetch in loop on startup
  • Signals generated on Supertrend reversal crossovers
  • Option chain integration — auto strike selection based on spot price and level
  • Auto expiry detection for derivatives with strike price logic
  • Volume EMA indicator (v2) for reversal confirmation at high volume

Order Execution

  • Live equity, FNO, and options order placement via Zerodha REST API
  • Forward test mode with virtual capital — simulates execution without real orders
  • Exit condition per individual trade with immediate position close
  • Cancel order logic for live mode
  • Order fill confirmation with IST timestamp saved to PostgreSQL
  • Margin validation before order placement
  • Auto lot-size fill for derivatives in quantity field

Frontend Dashboard

  • Real-time dashboard with market time, open positions, and P&L
  • Trade logs page — live + historical, IST formatted, responsive
  • Portfolio page — holdings and positions from Zerodha DEMAT
  • Settings page — indicator config, symbol selector, timeframe
  • Sidebar navigation with pages: Dashboard, Logs, Portfolio, Settings
  • Candlestick animation landing page with Keycloak SSO login
  • Fully responsive across mobile, tablet, and desktop
  • Theme support (dark/light) across all components

Architecture

FastAPI backend with Keycloak JWT auth manages Zerodha session, indicator computation, and order execution. Socket.IO bridges backend events (ticks, signals, orders, positions) to the Next.js frontend in real time. PostgreSQL stores tokens, instruments, trade history, and strategy configs. Forward test broker and live Zerodha broker share the same BrokerABC interface for seamless switching. Docker Compose handles all services.