AI-Powered Multi-Agent Investment Analysis Platform
Intelligent market analysis through collaborative AI agents β’ Inspired by TradingAgents
- β¨ Overview
- π Key Features
- ποΈ Architecture
- π» Tech Stack
- β‘ Quick Start
- πΈ Screenshots
- π Usage Examples
- π’ Project Structure
- β Star History
- π Acknowledgments
- π License
When.Trade is an open-source AI-powered investment analysis platform that revolutionizes market analysis through intelligent multi-agent collaboration.
Building upon the innovative foundation laid by TradingAgents, this project implements a sophisticated ecosystem where specialized AI agents work together to:
- π Analyze complex market data from multiple sources
- π Debate investment strategies through Bull vs Bear perspectives
- βοΈ Assess comprehensive risk scenarios
- π Generate actionable investment recommendations
| Feature | Description | Benefits |
|---|---|---|
| β‘ Real-time Analysis | WebSocket-based live data streaming and instant results | Up-to-the-minute market insights |
| π§ Multiple LLM Support | OpenAI, Anthropic, DeepSeek, Kimi, and other providers | Flexibility and redundancy in AI reasoning |
| π Unified Data Interface | Integrated multiple data sources with automatic failover | Reliable data access and consistency |
| π― Advanced Risk Management | Multi-perspective risk assessment and scenario analysis | Enhanced portfolio protection |
| π LangGraph Orchestration | Complex analysis workflows managed through state graphs | Scalable and maintainable agent coordination |
graph TB
subgraph "Frontend Layer"
UI[π₯οΈ Vue.js 3 + TypeScript]
WS[π WebSocket Client]
ST[π¦ Pinia State Management]
end
subgraph "Backend API Layer"
API[β‘ FastAPI Server]
WSS[π WebSocket Server]
RT[π Real-time Engine]
end
subgraph "Multi-Agent System"
GRAPH[π LangGraph Orchestrator]
subgraph "Analysis Agents"
MA[π Market Analyst]
NA[π° News Analyst]
SA[π¬ Social Analyst]
end
subgraph "Research Agents"
BR[π Bull Researcher]
BEAR[π» Bear Researcher]
end
subgraph "Decision Agents"
TR[π° Trader]
RM[βοΈ Risk Manager]
PM[π Portfolio Manager]
end
end
subgraph "Data Layer"
DB[(ποΈ PostgreSQL)]
REDIS[(β‘ Redis Cache)]
EXT[π External APIs]
end
UI --> API
WS --> WSS
API --> GRAPH
WSS --> RT
GRAPH --> MA
GRAPH --> NA
GRAPH --> SA
GRAPH --> BR
GRAPH --> BEAR
GRAPH --> TR
GRAPH --> RM
GRAPH --> PM
API --> DB
API --> REDIS
API --> EXT
graph LR
subgraph "π¨ UI Layer"
C[Components]
V[Views]
S[Stores]
end
subgraph "βοΈ Service Layer"
BL[Business Logic]
WF[Workflows]
VA[Validation]
end
subgraph "π Adapter Layer"
LLM[LLM Adapters]
API_A[API Adapters]
DATA[Data Adapters]
end
subgraph "π§ Port Layer"
INTF[Interfaces]
CONT[Contracts]
TYPES[Types]
end
C --> BL
V --> BL
S --> BL
BL --> LLM
WF --> API_A
VA --> DATA
LLM --> INTF
API_A --> CONT
DATA --> TYPES
sequenceDiagram
participant User
participant WebSocket
participant Orchestrator
participant DataAgents
participant ResearchAgents
participant DecisionAgents
User->>WebSocket: Start Analysis Request
WebSocket->>Orchestrator: Initialize Analysis
Note over Orchestrator: Phase 1: Data Collection
Orchestrator->>DataAgents: Gather Market Data
DataAgents-->>Orchestrator: Analysis Results
Note over Orchestrator: Phase 2: Investment Debate
Orchestrator->>ResearchAgents: Bull vs Bear Debate
ResearchAgents-->>Orchestrator: Debate Conclusions
Note over Orchestrator: Phase 3: Decision Making
Orchestrator->>DecisionAgents: Risk & Portfolio Analysis
DecisionAgents-->>Orchestrator: Final Recommendations
Orchestrator->>WebSocket: Stream Results
WebSocket->>User: Real-time Updates
| Category | Technology | Version | Purpose |
|---|---|---|---|
| π Framework | FastAPI | 0.109+ | High-performance async API |
| π§ AI/ML | LangChain + LangGraph | Latest | Multi-agent orchestration |
| ποΈ Database | PostgreSQL | 15+ | Primary data storage |
| β‘ Cache | Redis | 7+ | High-speed caching |
| π Queue | Celery | 5.3+ | Background task processing |
| π§ͺ Testing | pytest | 7.4+ | Comprehensive testing suite |
| Category | Technology | Version | Purpose |
|---|---|---|---|
| βοΈ Framework | Vue.js | 3.3+ | Reactive user interface |
| π Language | TypeScript | 5.6+ | Type-safe development |
| β‘ Build Tool | Vite | 7.0+ | Fast development and builds |
| π¨ Styling | Tailwind CSS | Latest | Utility-first CSS framework |
| π State | Pinia | Latest | Type-safe state management |
| π Charts | Chart.js | 4.4+ | Financial data visualization |
| Provider | Models | Features |
|---|---|---|
| π€ OpenAI | GPT-4, GPT-3.5-turbo | Tool calling, reasoning |
| π Google | Gemini Pro, Gemini | Multimodal, efficient reasoning |
| π¨π³ DeepSeek | DeepSeek | High performance, cost-effective |
| π Kimi | Moonshot-Kimi | Real-time data processing |
π System Requirements
| Component | Minimum | Recommended |
|---|---|---|
| Python | 3.9+ | 3.11+ |
| Node.js | 16+ | 18+ |
| PostgreSQL | 15+ | 16+ |
| Redis | 7+ | 7+ |
1οΈβ£ Clone Repository
git clone https://github.com/foldedcode/when.trade.git
cd when.trade2οΈβ£ Backend Setup
# Create conda environment
conda create -n whentrade python=3.11
conda activate whentrade
# Install dependencies
pip install -r requirements.txt
# Setup database
createdb whentrade_new
alembic upgrade head3οΈβ£ Frontend Setup
cd web
npm install
# or use yarn
yarn install4οΈβ£ Environment Configuration
# Copy environment template
cp .env.example .env
# Edit configuration (required)
nano .env # Add your API keys and database settingsOptional API Keys (Configure based on your needs):
OPENAI_API_KEY- Get from OpenAIDEEPSEEK_API_KEY- Get from DeepSeekKIMI_API_KEY- Get from Kimi (Moonshot AI)GOOGLE_API_KEY- Get from Google AI StudioFINNHUB_API_KEY- Get from FinnhubCOINGECKO_API_KEY- Get from CoinGeckoREDDIT_CLIENT_ID&REDDIT_CLIENT_SECRET- Get from Reddit Apps
Option 1: Using Start Scripts
# Start backend
./start.sh
# Start frontend (new terminal)
cd web && npm run devOption 2: Manual Start
# Terminal 1: Backend
conda activate whentrade
uvicorn core.main:app --reload --host 0.0.0.0 --port 8000
# Terminal 2: Frontend
cd web
npm run devOption 3: Production Mode
# Build and start production
npm run build
python -m uvicorn core.main:app --host 0.0.0.0 --port 8000| Service | URL | Description |
|---|---|---|
| π₯οΈ Frontend | http://localhost:3000 | Main application interface |
| π‘ API Server | http://localhost:8000 | Backend API endpoint |
| π API Docs | http://localhost:8000/docs | Interactive API documentation |
| π API Redoc | http://localhost:8000/redoc | Alternative API documentation |
# Check backend health
curl http://localhost:8000/health
# Check WebSocket connection
wscat -c ws://localhost:8000/ws/analysis
# Run tests
pytest # Backend tests
npm test # Frontend tests
![]() |
![]() |
![]() |
|
Real-time Multi-Agent Analysis - Collaborative AI agents working together Professional Investment Insights - Bull vs Bear research debates Comprehensive Risk Assessment - Multi-perspective scenario analysis Modern Web Interface - Vue.js 3 with responsive design
when.trade/ # π Project Root
βββ π core/ # Backend Application
β βββ π€ agents/ # Multi-Agent System
β β βββ π base.py # Agent Base Classes (β οΈ 1,344 lines)
β β βββ π analysts/ # Market Analysis Agents
β β β βββ market_analyst.py # Technical & Price Analysis
β β β βββ news_analyst.py # News Sentiment Analysis
β β β βββ fundamentals_analyst.py # Fundamental Analysis
β β βββ π¬ researchers/ # Investment Research Agents
β β β βββ bull_researcher.py # Bullish Case Research
β β β βββ bear_researcher.py # Bearish Case Research
β β βββ π₯ managers/ # Management Agents
β β β βββ research_manager.py # Research Coordination
β β β βββ risk_manager.py # Risk Assessment
β β β βββ portfolio_manager.py # Portfolio Management
β β βββ βοΈ risk_mgmt/ # Risk Management Agents
β β βββ π§° utils/ # Agent Utilities (β οΈ 1,602 lines)
β β βββ π factory.py # Dynamic Agent Factory
β βββ π api/ # API Layer
β β βββ v1/routes/ # API Routes
β β βββ analysis_ws.py # WebSocket Handler (β οΈ 2,510 lines)
β β βββ analysis.py # Analysis REST API
β β βββ agents.py # Agent Management API
β βββ π services/ # Business Logic Layer
β βββ π adapters/ # External Integrations
β β βββ llm_adapters/ # LLM Provider Adapters
β β βββ data_adapters/ # Market Data Adapters
β β βββ api_adapters/ # External API Adapters
β βββ π dataflows/ # Data Processing Layer
β β βββ interface.py # Unified Data Interface (β οΈ 1,624 lines)
β β βββ realtime_news_utils.py # Real-time News Processing
β βββ π graph/ # LangGraph Orchestration
β β βββ whentrade_graph.py # Main Workflow Graph
β βββ ποΈ database/ # Database Layer
β βββ βοΈ config/ # Configuration Management
β βββ π main.py # FastAPI Application Entry
β
βββ π¨ web/ # Frontend Application (197 files)
β βββ src/
β β βββ π§© components/ # Vue.js Components
β β β βββ analysis/ # Analysis Interface Components
β β β βββ common/ # Reusable Components
β β βββ π¦ stores/ # Pinia State Management
β β β βββ analysis.ts # Analysis State
β β β βββ agents.ts # Agent State
β β β βββ websocket.ts # WebSocket State
β β βββ π§ services/ # Frontend Business Logic
β β βββ π adapters/ # Frontend API Adapters
β β βββ π¨ assets/ # Static Assets
β β βββ π± views/ # Page Views
β βββ π¦ package.json # Node.js Dependencies
β βββ βοΈ vite.config.ts # Vite Configuration
β
βββ βοΈ configs/ # Configuration Files
βββ π scripts/ # Deployment & Utility Scripts
βββ π docs/ # Documentation
β βββ images/ # README Images & Screenshots
β βββ diagrams/ # Architecture Diagrams
βββ π§ͺ tests/ # Test Suites
βββ ποΈ alembic/ # Database Migrations
βββ π README.md # Project Documentation
| Category | Count | Notes |
|---|---|---|
| Python Files | 150+ | Backend implementation |
| TypeScript Files | 197 | Frontend implementation |
| Total Lines of Code | 50,000+ | Estimated project size |
| Large Files | 6 | Files >1,000 lines (see warnings) |
| Test Coverage | 80%+ | Comprehensive test suite |
For optimal development experience, use symbol-based navigation for these files:
| File | Lines | Navigation Strategy |
|---|---|---|
agents/base.py |
1,344 | Use class-based navigation |
agents/utils/agent_utils.py |
1,602 | Use function-based search |
api/v1/routes/analysis_ws.py |
2,510 | Use endpoint-based navigation |
dataflows/interface.py |
1,624 | Use method-based search |
TradingAgents - The pioneering project that inspired our multi-agent approach to financial analysis.
| Technology | Contribution |
|---|---|
| LangChain | Multi-agent orchestration framework |
| FastAPI | High-performance async web framework |
| Vue.js | Reactive frontend framework |
| PostgreSQL | Robust database system |
| Redis | High-speed caching solution |
β οΈ Important: This software is for educational and research purposes only.
- Do not use for actual trading without proper risk management
- Perform thorough due diligence before any investment decisions
- Past performance does not guarantee future results
- Authors are not responsible for any financial losses
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ by the When.Trade community
β Star us on GitHub β’ π Report Issues β’ π€ Contribute


