A comprehensive algorithmic trading system for Indian F&O markets (NSE) with AI-powered multi-agent orchestration, database-driven prompt configuration, risk management, and real-time pipeline visualization.
Conservative trading system focused on:
- Multi-Agent AI Pipeline β 5 coordinated agents (Research β Signal β Risk β Execution β Monitor) with real-time status tracking
- Database-Driven Prompt Config β All agent system messages and prompt templates stored in PostgreSQL with versioning, live editing, and full audit history
- Risk Management β Circuit breakers, position sizing, daily/weekly loss limits
- Conservative Strategy β Capital preservation with controlled growth
- Backtesting β Multi-strategy comparison with historical data
- Paper Trading β Test strategies without real capital
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Agent Coordinator β
β (Orchestrates pipeline with real-time status tracking) β
β β
β βββββββββββββ βββββββββββββ ββββββββββββ ββββββββββββββββ β
β β Research ββ β Signal ββ β Risk ββ β Execution β β
β β Agent β β Agent β β Agent β β (Order Svc) β β
β βββββββββββββ βββββββββββββ ββββββββββββ ββββββββββββββββ β
β β β β
β βββββββββββββ ββββββββββββββββ β
β βCategoricalβ β Monitor β β
β β Agent β β Agent β β
β βββββββββββββ ββββββββββββββββ β
β β
β AgentStatusTracker: IDLE β RUNNING β COMPLETED/ERROR per agent β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
ββββββββββββββββββββββββ ββββββββββββββββββββββββββββ
β Strategy Engine β β Risk Management β
β - Trend Following β β - Circuit Breaker β
β - Mean Reversion β β - Position Sizing β
β - Breakout β β - Daily/Weekly Limits β
ββββββββββββββββββββββββ ββββββββββββββββββββββββββββ
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Order Execution Service β
β (Paper Trading / Live Trading) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MCP Market Data Service (Groww API) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββ
β agent_prompt_configs (DB) β
β ββββββββββββββββββββββββββββββββββββββββββ β
β β agent_name β config_key β config_value β β
β β RISK_AGENT β system_msg β "You are..." β β
β β RISK_AGENT β prompt_tpl β "{signal}..."β β
β ββββββββββββββββββββββββββββββββββββββββββ β
β - Versioned (v1, v2, v3...) β
β - Active/inactive flag β
β - ConcurrentHashMap in-memory cache β
βββββββββββββββββββββββββββββββββββββββββββββββ
β on update
βββββββββββββββββββββββββββββββββββββββββββββββ
β agent_prompt_config_audit (DB) β
β - old_value β new_value β
β - changed_by, change_reason β
β - Full audit trail of all changes β
βββββββββββββββββββββββββββββββββββββββββββββββ
- Framework: Spring Boot 3.4.2
- AI: Spring AI 1.0.0-M5 (OpenAI GPT-4o integration)
- Database: PostgreSQL
- Build: Gradle 8.12
- Java: 21
# Java 21
export JAVA_HOME=/opt/homebrew/Cellar/openjdk@21/21.0.10/libexec/openjdk.jdk/Contents/Home
# PostgreSQL
brew install postgresql@17
brew services start postgresql@17Edit src/main/resources/application.properties:
# OpenAI API Key (for AI-powered analysis)
spring.ai.openai.api-key=your-openai-api-key-here
# Trading Configuration
trading.mode=semi-auto
trading.capital=50000
trading.instruments=NIFTY,BANKNIFTY
# Risk Management
trading.risk.daily-loss-limit=1500
trading.risk.weekly-loss-limit=3500./gradlew bootRun
# Server starts on port 8080On first startup, the AgentPromptSeeder automatically seeds all 5 agent configurations from classpath defaults into the database.
- AgentStatusTracker β In-memory
ConcurrentHashMaptracking each agent's state (IDLE/RUNNING/COMPLETED/ERROR), run duration, result summary, and error details - AgentCoordinator β Wraps each pipeline step with status tracking calls (
markRunning()βmarkCompleted()/markError()) - Real-time visibility β Pipeline state exposed via REST API, consumed by dashboard for live visualization
- AgentPromptConfig entity β Stores
system_messageandprompt_templateper agent with versioning - AgentPromptConfigAudit entity β Full change history with old/new values, change reason, and who made the change
- AgentPromptConfigService β Cached config access (ConcurrentHashMap) with
@Transactionalupdates that deactivate old versions and create new ones - AgentPromptSeeder β Seeds defaults from classpath
.txtfiles on first startup - All 5 agents modified β Each agent uses
getSystemMessage()andgetPromptTemplate()methods that check DB first, fallback to hardcoded defaults
- Market sentiment analysis
- Volatility assessment
- Trading recommendations
- Context-aware analysis (includes current holdings)
Comprehensive equity analysis across:
- Market Cap (Large/Mid/Small)
- Industries (Banking, IT, Pharma, etc.)
- Tech Sector
- Recent IPOs
Conservative strategy:
- 60-70% Large Cap
- 20-30% Mid Cap
- 0-10% Small Cap
- Circuit Breaker with daily/weekly limits
- Position Sizing based on risk
- Emergency Stop functionality
- Real-time monitoring
Multi-agent coordination:
- Research Agent β Market analysis
- Signal Agent β Entry/exit signals with confidence scoring
- Risk Agent β Hard rule checks + AI-enhanced assessment
- Execution β Order placement (paper or live)
- Monitor Agent β Position monitoring and exit signals
- Multiple strategies (Trend Following, Mean Reversion, Breakout)
- Historical performance analysis
- Multi-strategy comparison
- Instrument sync from Groww API with DB persistence
- Historical candle data storage with DB-first lookup
- Rate-limited API calls with exponential backoff
GET /api/dashboard/overviewβ Main metricsGET /api/dashboard/positionsβ Current positionsGET /api/dashboard/tradesβ Trade historyGET /api/dashboard/metricsβ Trading metrics
POST /api/dashboard/agents/researchβ Market researchPOST /api/dashboard/agents/categorical-analysisβ Stock analysisPOST /api/dashboard/agents/pipelineβ Run full trading pipelineGET /api/dashboard/agents/decisionsβ Recent agent decisions
GET /api/dashboard/agents/statusβ Real-time pipeline state (all agent statuses)
GET /api/dashboard/agents/configsβ All active configsGET /api/dashboard/agents/configs/{agentName}β Configs for a specific agentPUT /api/dashboard/agents/configs/{agentName}/{configKey}β Update config (body:{value, reason, changedBy})GET /api/dashboard/agents/configs/auditβ Recent 50 audit entriesGET /api/dashboard/agents/configs/audit/{agentName}β Audit trail for specific agent
POST /api/dashboard/emergency-stopβ Emergency haltPOST /api/dashboard/resume-tradingβ Resume tradingPOST /api/dashboard/mode/{mode}β Set mode (semi-auto/full-auto)
POST /api/dashboard/backtest/{symbol}?days=180&capital=50000&strategy=TREND_FOLLOWINGPOST /api/dashboard/backtest/compare/{symbol}?days=180&capital=50000β Multi-strategy comparison
GET /api/dashboard/instrumentsβ Tradable instrumentsGET /api/dashboard/instruments/search?query=NIFTYβ Search instrumentsPOST /api/dashboard/instruments/syncβ Sync from Groww API
src/main/java/com/navneet/fnotrading/
βββ agent/
β βββ config/ # AgentPromptConfigService, AgentPromptSeeder
β βββ coordinator/ # AgentCoordinator (pipeline orchestration)
β βββ monitor/ # TradeMonitorAgent
β βββ research/ # MarketResearchAgent, CategoricalAnalysisAgent
β βββ risk/ # RiskAssessmentAgent
β βββ signal/ # SignalGenerationAgent
β βββ status/ # AgentStatusTracker (pipeline state tracking)
βββ backtest/ # Backtesting engine
βββ config/ # TradingConfig, RiskConfig, McpClientConfig
βββ dashboard/
β βββ controller/ # DashboardController (REST endpoints)
β βββ service/ # MetricsService, ReportService, PerformanceTrackingService
βββ execution/ # OrderExecutionService, PaperTradingService, PositionManager
βββ market/ # TechnicalIndicatorService, market models
βββ mcp/ # Groww API integration (McpMarketDataService, McpOrderService)
βββ persistence/
β βββ entity/ # Trade, Signal, Instrument, AgentPromptConfig, AgentDecision, etc.
β βββ repository/ # JPA repositories
βββ risk/ # RiskManagementService, CircuitBreakerService, PositionSizingService
βββ strategy/ # StrategyEngine (Trend, MeanReversion, Breakout)
- β Core trading engine
- β Multi-agent system with 5 AI agents
- β Agent pipeline status tracking (real-time)
- β Database-driven prompt configuration with versioning & audit
- β AI-powered research & categorical analysis
- β Risk management & circuit breaker
- β Paper trading
- β Backtesting (single & multi-strategy)
- β Historical candle data persistence
- β Instrument sync & management
- β Dashboard REST API (30+ endpoints)
- β³ Live trading (testing in paper mode)
- fno-dashboard β React UI for monitoring, control, pipeline visualization, and prompt management
- stock-exchange-trade β Groww API wrapper (MCP server)
Version: 1.1.0 Author: Navneet Prabhakar Last Updated: 2026-02-12