Skip to the content.

AI-Powered Stock Trading Agent

Automated Indian equity delivery trading with Claude AI and real-time market processing

7,700+

Lines of Python

33

Modules

50+

Stocks Analyzed Daily

8

Hard Risk Rules

1

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.

2

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)

3

Key Technical Highlights

Position State Machine

OPEN_WATCHING -> FIRST_TARGET_HIT -> TRAILING -> CLOSED. Half-selling at +15%, trailing stop ratcheting, breakeven protection after target hit.

Multi-Dimensional Scoring

Each stock scored 0-100 across trend strength, momentum, volume confirmation, and relative strength vs Nifty. Sector momentum ranking feeds into Claude's context.

Real-Time WebSocket Execution

Sub-second price ticks drive target detection and trailing stop updates. 10-second debouncing prevents order thrashing. GTT reconciliation detects broker-triggered stops.

Paper/Live Trading Switch

Single environment variable switches between paper and live mode. Same code path, same risk rules, only the executor changes.

4

Tech Stack

Python 3.10+

Core implementation

Claude AI API

Trading decisions

Flask

Web dashboard

PostgreSQL / SQLite

Dual database

WebSocket

Real-time market data

Railway

Cloud deployment

Telegram Bot API

Notifications

Upstox SDK

Broker integration

---
Back to Home YouTube Pipeline (WealthCode)