Skip to content

buzuweidao/WhenTrade

Repository files navigation

⚑ When.Trade

AI-Powered Multi-Agent Investment Analysis Platform

Intelligent market analysis through collaborative AI agents β€’ Inspired by TradingAgents

πŸ‡ΊπŸ‡Έ English | πŸ‡¨πŸ‡³ δΈ­ζ–‡

Python Version FastAPI Vue.js License PRs Welcome

GitHub Stars GitHub Forks GitHub Watchers

πŸ“‹ Table of Contents

✨ Overview

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

πŸš€ Key Features

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

πŸ—οΈ Architecture

System Overview

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
Loading

Four-Layer Architecture

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
Loading

Multi-Agent Workflow

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
Loading

πŸ’» Tech Stack

🐍 Backend Technologies

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

🎨 Frontend Technologies

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

πŸ€– LLM Integrations

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

⚑ Quick Start

Prerequisites

πŸ“‹ System Requirements
Component Minimum Recommended
Python 3.9+ 3.11+
Node.js 16+ 18+
PostgreSQL 15+ 16+
Redis 7+ 7+

πŸ› οΈ Manual Installation

1️⃣ Clone Repository
git clone https://github.com/foldedcode/when.trade.git
cd when.trade
2️⃣ 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 head
3️⃣ Frontend Setup
cd web
npm install
# or use yarn
yarn install
4️⃣ Environment Configuration
# Copy environment template
cp .env.example .env

# Edit configuration (required)
nano .env  # Add your API keys and database settings

Optional API Keys (Configure based on your needs):

πŸš€ Launch Application

Option 1: Using Start Scripts

# Start backend
./start.sh

# Start frontend (new terminal)
cd web && npm run dev

Option 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 dev

Option 3: Production Mode

# Build and start production
npm run build
python -m uvicorn core.main:app --host 0.0.0.0 --port 8000

πŸ”— Access Points

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

βœ… Verification

# 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

πŸ“Έ Screenshots

πŸ–₯️ Product Interface

English Interface Screenshot 2
English Interface Screenshot 5
English Interface Screenshot 6

🎬 Product Features

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

🏒 Project Structure

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

πŸ“Š Key Metrics

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

⚠️ Large File Navigation

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

⭐ Star History

Star History Chart

πŸ™ Acknowledgments

🎯 Core Inspiration

TradingAgents - The pioneering project that inspired our multi-agent approach to financial analysis.

πŸ› οΈ Technology Partners

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

πŸ“’ Disclaimer

⚠️ 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

πŸ“„ License

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

About

AI-Powered Multi-Agent Crypto Investment Analysis Platform

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •