Lines of Python
Modules
Stocks Analyzed Daily
Hard Risk Rules
What It Does
A production-grade automated trading system for Indian equities (NSE). It runs 3 scheduled jobs daily (9:30 AM, 1 PM, 3 PM IST) plus a continuous real-time WebSocket monitor during market hours. Claude AI acts as the strategic brain, receiving 150+ data points per decision including technical indicators, portfolio state, and market regime. But AI operates within 8 hard-coded risk rules it cannot override - max 4 positions, 25% cap per position, 20% cash reserve, no trades in the first 15 minutes, and more.
Architecture
The system runs as a single process with concurrent threads:
- Scheduler Thread - APScheduler runs 3 daily trading jobs + auth reminder
- WebSocket Monitor Thread - Real-time position tracking (9:15 AM - 3:31 PM)
- Flask Dashboard Thread - Web UI with portfolio views, decision logs, trade history
Modular layers: API Integration (Upstox SDK, OAuth2) | Data Analysis (RSI, MACD, EMA, Bollinger, ATR) | AI Brain (Claude) | Risk Engine (8 hard rules) | Position State Machine | Notifications (Telegram) | Database (PostgreSQL/SQLite) | Web Dashboard (Flask)
Key Technical Highlights
OPEN_WATCHING -> FIRST_TARGET_HIT -> TRAILING -> CLOSED. Half-selling at +15%, trailing stop ratcheting, breakeven protection after target hit.
Each stock scored 0-100 across trend strength, momentum, volume confirmation, and relative strength vs Nifty. Sector momentum ranking feeds into Claude's context.
Sub-second price ticks drive target detection and trailing stop updates. 10-second debouncing prevents order thrashing. GTT reconciliation detects broker-triggered stops.
Single environment variable switches between paper and live mode. Same code path, same risk rules, only the executor changes.
Tech Stack
Core implementation
Trading decisions
Web dashboard
Dual database
Real-time market data
Cloud deployment
Notifications
Broker integration