A multi-agent LLM-based Chinese financial trading decision-making framework that utilizes a team of professional analysts to collaborate on stock analysis and investment decisions.
TradingAgents-CN Project Details
Project Overview
TradingAgents-CN is a multi-agent large language model (LLM)-based financial trading decision-making framework for the Chinese market. This project is developed based on the well-known TauricResearch/TradingAgents project, specifically optimized to provide complete localization support for Chinese users.
Core Features
- 🤖 Multi-Agent Collaboration: Simulates the professional division of labor in real trading firms, with multiple AI agents collaborating to evaluate market conditions.
- 🇨🇳 Chinese Optimization: Full Chinese interface, documentation system, and A-share market support.
- 🧠 Domestic LLM Integration: Deep integration with various large language models, including Alibaba and Google AI.
- 🌐 Web Interface: A modern web management interface based on Streamlit.
- 📊 Database Support: MongoDB + Redis dual-database architecture, providing intelligent caching and data persistence.
System Architecture
Agent Team Structure
TradingAgents-CN adopts a multi-agent collaborative architecture, comprising the following specialized teams:
1. Analyst Team
- Fundamental Analyst: Analyzes company financial status, industry trends, and macroeconomic factors.
- Technical Analyst: Analyzes price trends, technical indicators, and chart patterns.
- News Analyst: Analyzes financial news, company announcements, and market dynamics.
- Social Media Analyst: Analyzes market sentiment, investor sentiment, and social media discussions.
2. Researcher Team
- Bullish Researcher: Analyzes investment opportunities from an optimistic perspective.
- Bearish Researcher: Analyzes investment risks from a cautious perspective.
- Structured Debate: Improves decision quality through the collision of viewpoints.
3. Trading Decision Layer
- Trader Agent: Makes final trading decisions based on all analytical inputs.
- Risk Management: Multi-level risk assessment and management mechanisms.
- Management Layer: Coordinates the work of various teams to ensure decision quality.
Technical Architecture
Core Technology Stack
Technology Area | Used Technology | Version Requirement |
---|---|---|
🐍 Core Language | Python | 3.10+ |
🧠 AI Framework | LangChain, LangGraph | Latest Version |
🌐 Web Interface | Streamlit | 1.28+ |
🗄️ Databases | MongoDB, Redis | 4.4+, 6.0+ |
📊 Data Processing | Pandas, NumPy | Latest Version |
🔌 API Integration | TongdaXing API, FinnHub, Google News | - |
Data Flow Architecture
- Data Acquisition: Multi-source data access (A-shares, US stocks, news, social media).
- Intelligent Caching: Redis millisecond-level caching + MongoDB persistent storage.
- Multi-Agent Processing: Parallel analysis, collaborative decision-making.
- Result Output: Structured investment advice and risk assessment.
Core Functions
1. Multi-Market Support
A-share Market (🇨🇳)
- Real-time Quotes: TongdaXing API provides real-time stock price data.
- Historical Data: Supports historical K-lines and technical indicator calculations.
- Stock Codes: Supports Shanghai and Shenzhen stock codes (e.g., 000001, 600519, 300750).
US Stock Market (🇺🇸)
- Real-time Data: FinnHub, Yahoo Finance provide US stock data.
- Supported Stocks: Mainstream US stocks like AAPL, TSLA, NVDA, MSFT, etc.
2. Large Language Model Integration
Domestic LLM (Recommended)
# Alibaba DashScope configuration
config = {
"llm_provider": "dashscope",
"deep_think_llm": "qwen-plus", # Deep analysis
"quick_think_llm": "qwen-turbo" # Quick tasks
}
International LLM
# OpenAI configuration
config = {
"llm_provider": "openai",
"deep_think_llm": "gpt-4o",
"quick_think_llm": "gpt-4o-mini"
}
3. Intelligent Analysis Levels
The system provides 5 levels of research depth:
Level | Analysis Time | Applicable Scenario | Cost |
---|---|---|---|
1 | 2-4 minutes | Daily monitoring | Low |
2 | 4-6 minutes | Regular investment | Medium-low |
3 | 6-10 minutes | Important decisions (Recommended) | Medium |
4 | 10-15 minutes | Major investment | Medium-high |
5 | 15-25 minutes | Most critical decisions | High |
4. Web Management Interface
Main Functions
- 🎛️ Configuration Management: API key management, model selection, system configuration.
- 💰 Cost Control: Real-time token usage statistics and cost tracking.
- 📊 Analysis Monitoring: Real-time display of analysis process and progress.
- 💾 Cache Management: Data cache status monitoring and management.
Interface Features
- Fully Localized to Chinese: Interface and analysis results displayed entirely in Chinese.
- Real-time Progress: Visualized analysis process to reduce waiting anxiety.
- Structured Output: Investment advice, target price, confidence level, risk assessment.
Installation and Deployment
System Requirements
- Python 3.10+
- 4GB+ RAM (8GB+ recommended)
- Stable network connection
Quick Installation
# 1. Clone the project
git clone https://github.com/hsliuping/TradingAgents-CN.git
cd TradingAgents-CN
# 2. Create a virtual environment
python -m venv env
source env/bin/activate # Linux/macOS
# Or env\Scripts\activate # Windows
# 3. Install dependencies
pip install -r requirements.txt
# 4. Configure environment variables
cp .env.example .env
# Edit the .env file to configure API keys
Environment Configuration
# Required configurations
DASHSCOPE_API_KEY=your_dashscope_api_key_here
FINNHUB_API_KEY=your_finnhub_api_key_here
# Optional configurations
GOOGLE_API_KEY=your_google_api_key_here
OPENAI_API_KEY=your_openai_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key
# Database configurations (optional)
MONGODB_ENABLED=false
REDIS_ENABLED=false
Starting the Service
# Start the Web interface
streamlit run web/app.py
# Access address: http://localhost:8501
Usage Examples
1. Web Interface Usage
- Visit
http://localhost:8501
in your browser. - Enter a stock code (e.g., AAPL or 000001).
- Select the research depth (Level 3 recommended).
- Click "Start Analysis".
- View the structured analysis results.
2. Programmatic Calling
from tradingagents.graph.trading_graph import TradingAgentsGraph
from tradingagents.default_config import DEFAULT_CONFIG
# Configure the system
config = DEFAULT_CONFIG.copy()
config["llm_provider"] = "dashscope"
config["deep_think_llm"] = "qwen-plus"
# Create the trading agent
ta = TradingAgentsGraph(debug=True, config=config)
# Analyze a stock
state, decision = ta.propagate("AAPL", "2024-01-15")
# Output results
print(f"Recommended Action: {decision['action']}")
print(f"Confidence: {decision['confidence']:.1%}")
print(f"Risk Score: {decision['risk_score']:.1%}")
3. Cost Optimization Configuration
# Low-cost configuration
cost_optimized_config = {
"deep_think_llm": "qwen-turbo", # Use a cheaper model
"quick_think_llm": "qwen-turbo",
"max_debate_rounds": 1, # Reduce debate rounds
"online_tools": False # Use cached data
}
# Cost estimation
# Economy Mode: $0.01-0.05/analysis
# Standard Mode: $0.05-0.15/analysis
# High Precision Mode: $0.10-0.30/analysis
Database Integration
MongoDB + Redis Architecture
# Start databases using Docker
docker-compose up -d
# Check service status
docker-compose ps
Multi-Layer Data Source Strategy
The system employs an intelligent fallback strategy to ensure high availability:
- Redis Cache (millisecond-level): Fast access for hot data.
- MongoDB Storage (second-level): Persistent storage for historical data.
- TongdaXing API (second-level): Real-time data acquisition.
- Local Cache (fallback): Offline data support.
Documentation System
The project provides over 50,000 words of detailed Chinese documentation:
- 📋 Project Overview: Quickly understand the project's core value.
- 🏛️ System Architecture: In-depth analysis of the multi-agent collaboration mechanism.
- 🤖 Agent Details: Functional descriptions of various agents.
- 📊 Data Processing: Data source integration and processing flow.
- 💡 Example Tutorials: Practical tutorials from basic to advanced.
- 🆘 FAQ: Common questions and solutions.
Contribution Guide
Contributions in all forms are welcome:
- Fork the project
- Create a feature branch:
git checkout -b feature/AmazingFeature
- Commit your changes:
git commit -m 'Add some AmazingFeature'
- Push to the branch:
git push origin feature/AmazingFeature
- Create a Pull Request
Risk Disclaimer
⚠️ Important Reminder:
- This framework is for research and educational purposes only.
- It does not constitute investment advice.
- AI model predictions have uncertainties.
- Investments carry risks, and decisions must be made with caution.
- It is recommended to consult a professional financial advisor.
TradingAgents-CN is dedicated to providing world-class AI financial trading decision-making framework for Chinese users, promoting innovation and application of AI technology in China's FinTech sector.