解冲突说明:pr84 分支基于较旧的 main,据此误判 v0.3.0 漏更版本号与 CHANGELOG。 实际 main 已有正确的 0.3.0 条目与 version=0.3.0,本次合并保留之,仅叠加 0.3.1。
简体中文 | English
TradingAgents-Astock
A China A-share deep-specialization fork of TauricResearch/TradingAgents (65K ⭐)
Fully Apache 2.0 open source · pip install and run · zero external service dependencies
⚠️ This project is an engineering implementation and research reproduction of the TradingAgents paper, intended for research and educational use.
It does not constitute investment advice, nor does it provide any investment service.
Why This Fork · Comparison · Architecture · Analyst Roles · Data Sources · Quick Start · Web UI · Troubleshooting
Why This Fork
The original TradingAgents is an excellent multi-agent research framework, but it's designed for the US stock market: data comes from Yahoo Finance / Alpha Vantage, analysts don't understand the A-share system, and the debates and decision-making are entirely geared toward the US market.
Goal of this Fork: To truly adapt TradingAgents' multi-agent debate architecture to the A-share market. This is not a simple translation, but a deep specialization across three dimensions: data layer, agent roles, and trading rules.
Core Modifications
| Dimension | Original | This Fork |
|---|---|---|
| Data Source | Yahoo Finance / Alpha Vantage | mootdx + Eastmoney + Sina + Tonghuashun (all free direct connections) |
| Analyst Roles | 4 (Market / Sentiment / News / Fundamentals) | 7 (+Policy Analyst / Hot Money Tracker / Lock-up Expiry Monitor) |
| Trading Rules | US Market (T+0, no price limits) | A-share Market (T+1, price limits, minimum lot size, trading hours) |
| Output Language | English | Chinese reports (internal debates remain in English to maintain reasoning quality) |
| Alpha Benchmark | SPY | CSI 300 (沪深300) |
Comparison with Upstream
| Feature | Original TradingAgents | This Fork |
|---|---|---|
| License | Apache 2.0 | Full Apache 2.0 |
| Deployment Dependency | pip install | Ready to use |
| A-share Data | ❌ | mootdx + East Money + Sina + Tonghuashun (direct HTTP) |
| A-share Specialized Roles | ❌ | 3 deep roles: Policy / Hot Money / Lockup Expiry |
| A-share Trading Constraints | ❌ | Full coverage: T+1 / Price Limits / Lot Size / ST |
Architecture Overview
┌─────────────────────────────────────────────────────────┐
│ 7 Analyst Research Report Generation │
│ Market → Social → News → Fundamentals │
│ → Policy → Hot Money → Lockup │
│ (Each Analyst has tool loop) │
├─────────────────────────────────────────────────────────┤
│ Bull vs Bear Investment Research Debate │
│ Bull Researcher ←→ Bear Researcher │
│ (Up to N rounds of debate) │
├─────────────────────────────────────────────────────────┤
│ Research Manager Comprehensive Assessment │
│ (Deep thinking LLM, outputs investment plan) │
├─────────────────────────────────────────────────────────┤
│ Trader Trading Plan │
│ (A-share constraints: T+1/price limit/lot size) │
├─────────────────────────────────────────────────────────┤
│ Aggressive ←→ Conservative ←→ Neutral │
│ Three-way Risk Debate │
├─────────────────────────────────────────────────────────┤
│ Portfolio Manager Final Decision │
│ (Deep thinking LLM, outputs rating + rationale) │
└─────────────────────────────────────────────────────────┘
Dual LLM Design:
quick_think_llm: All Analysts, Researchers, Traders, Risk Debatersdeep_think_llm: Research Manager and Portfolio Manager (requires comprehensive global information for decision making)
7 Analyst Roles
Original 4 Roles (A-share Adapted)
| Role | Responsibilities | Data Tools |
|---|---|---|
| 🏪 Market Analyst | K-line patterns, technical indicators, volume-price analysis | get_stock_data, get_indicators |
| 💬 Sentiment Analyst | Social media sentiment, retail investor discussion heat | get_news |
| 📰 News Analyst | Industry news, announcements, macro events | get_news, get_global_news, get_insider_transactions |
| 📊 Fundamental Analyst | Financial statement triad, profitability, valuation | get_fundamentals, get_balance_sheet, get_cashflow, get_income_statement |
A-share Specific 3 Roles (New)
| Role | Responsibilities | Data Tools | Why It's Needed |
|---|---|---|---|
| 🏛️ Policy Analyst | Regulatory policy, industrial policy, window guidance | get_news, get_global_news |
A-share is a policy-driven market, policy changes directly impact sector rotation |
| 🔥 Hot Money Tracker | Dragon-Tiger lists, large order flow, main force capital dynamics | get_stock_data, get_news, get_insider_transactions |
Hot money is the core force behind short-term A-share pricing |
| 🔓 Lock-up Monitor | Restricted share unlocks, major shareholder reductions, equity pledges | get_insider_transactions, get_news, get_fundamentals |
Lock-up expiration is a unique, major supply shock factor for A-shares |
The reports from all 7 analysts will feed into subsequent Bull/Bear debates and three-way risk debates, ensuring A-share specific factors are integrated throughout the entire decision-making chain.
Data Sources
All free, no API key, no point wall:
| Source | Protocol | Content Provided |
|---|---|---|
| mootdx | TCP 7709 | OHLCV K-lines, financial snapshots, F10 text |
| Tencent Finance | HTTP (qt.gtimg.cn) |
PE / PB / Market Cap / Turnover Rate (real-time) |
| East Money | HTTP (datacenter / push2) | Dragon & Tiger List, Restricted Share Unlocking, Sector Quotes, Individual Stock Info |
| Sina Finance | HTTP | K-line history, Financial Statements (3 tables) |
| Tonghuashun | HTTP (10jqka) | EPS Consensus Estimates |
| Cailianshe | HTTP (cls.cn) | Global Financial News Flash |
| Baidu Stock Market | HTTP (finance.pae.baidu) | Concept Sector Classification, Capital Flow |
Completely independent of Tushare (point wall), Alpha Vantage (overseas API), Yahoo Finance (does not support A-shares).
Data Source Priority & East Money Anti-blocking (v0.2.11): If quotes / K-lines / market cap / financials can be obtained from mootdx (Tongdaxin TCP, IP not blocked) or Tencent, always use them; East Money is only used for its unique data (Dragon & Tiger List / Unlocking / Capital Flow / Sector / Individual Stock News, etc.). All East Money requests go through the built-in throttling entry
_em_get(): serial rate limiting (default interval ≥1s + 0.1~0.5s random jitter) + reusing Keep-Alive sessions. Multiple agents running batch analysis will no longer trigger temporary IP blocking (East Money risk control tested: >5 requests per second / concurrency ≥10 / ≥200 requests in 1 minute triggers blocking). For batch scenarios, set the environment variableEM_MIN_INTERVAL=1.5~2to further reduce speed. Only East Money is rate-limited; mootdx / Tencent / Sina / Tonghuashun / Cailianshe / Baidu are unaffected.
Quick Start
1. Environment Setup
# Python >= 3.10
git clone https://github.com/simonlin1212/tradingagents-astock.git
cd tradingagents-astock
pip install -e .
# (Optional) If you want to use Google Gemini models:
pip install -e ".[google]"
Ready to use after installation, no Docker required. After installing, run
streamlit run web/app.py(Web UI) ortradingagents(CLI) directly. See the "Web UI" and "CLI" sections below. Docker is only an optional deployment method and not needed for local development.
2. Configure LLM
API Key is required. Subscription-based plans like Claude or ChatGPT cannot be used. Each analysis requires 30-50 LLM calls, which only the API mode supports.
Create a .env file in the project root and configure it based on your chosen provider:
# ── Option A: MiniMax (Recommended for direct China access, cost-effective) ──
MINIMAX_API_KEY=sk-xxx
# Apply at: https://platform.minimaxi.com/
# ── Option B: DeepSeek ─────────────────────────────────────────────────────
DEEPSEEK_API_KEY=sk-xxx
# Apply at: https://platform.deepseek.com/
# ── Option C: Zhipu GLM ────────────────────────────────────────────────────
ZHIPU_API_KEY=xxx
# Apply at: https://open.bigmodel.cn/
# ── Option D: Tongyi Qianwen Qwen ──────────────────────────────────────────
DASHSCOPE_API_KEY=sk-xxx
# Apply at: https://dashscope.console.aliyun.com/
# ── Option E: OpenAI ───────────────────────────────────────────────────────
OPENAI_API_KEY=sk-xxx
# ── Option F: Anthropic ────────────────────────────────────────────────────
ANTHROPIC_API_KEY=sk-ant-xxx
# ── Option G: Kimi (Anthropic-compatible API) ───────────────────────────────
ANTHROPIC_AUTH_TOKEN=your-kimi-token
# ── Option H: Any OpenAI-compatible gateway (9Router / AI Router / self-hosted proxy) ──
OPENAI_COMPATIBLE_API_KEY=sk-xxx # Also accepts OPENAI_API_KEY
BACKEND_URL=https://your-relay.example/v1 # Your gateway URL (can also be set in the Web sidebar "API Base URL")
3. Run Analysis
Modify the configuration based on your chosen provider:
from tradingagents.graph.trading_graph import TradingAgentsGraph
# ── MiniMax Example (Recommended) ──────────────────────────────────────────
config = {
"llm_provider": "minimax",
"deep_think_llm": "MiniMax-M2.7",
"quick_think_llm": "MiniMax-M2.7-highspeed",
"output_language": "Chinese",
}
# ── DeepSeek Example ───────────────────────────────────────────────────────
# config = {
# "llm_provider": "deepseek",
# "deep_think_llm": "deepseek-chat",
# "quick_think_llm": "deepseek-chat",
# "output_language": "Chinese",
# }
# ── Anthropic + Kimi Example ───────────────────────────────────────────────
# config = {
# "llm_provider": "anthropic",
# "deep_think_llm": "claude-sonnet-4-6",
# "quick_think_llm": "claude-sonnet-4-6",
# "backend_url": "https://api.kimi.com/coding/",
# "output_language": "Chinese",
# }
ta = TradingAgentsGraph(debug=True, config=config)
final_state, decision = ta.propagate("688017", "2026-05-12")
print(decision)
4. CLI Mode
tradingagents # Interactive CLI
tradingagents --help # Show all options
Web UI
Built-in Streamlit visualization interface allows selecting LLM providers and models in the sidebar. Enter a stock code to perform one-click analysis, ideal for users who prefer not to write code.
Startup
# Option 1: Start via command line (recommended)
tradingagents-web
# Option 2: Run directly
streamlit run web/app.py
Open your browser and navigate to http://localhost:8501.
Features
- Model Selection: Sidebar supports switching between 10 LLM providers (MiniMax/DeepSeek/Qwen/GLM/OpenAI/Anthropic/Google/xAI/OpenRouter/Ollama), plus "OpenAI Compatible (custom base_url)" for connecting to any OpenAI-compatible gateway (9Router / AI Router / self-hosted proxy)
- One-Click Analysis: Enter a 6-digit A-share stock code + analysis date + "Data Start Date" (defaults to the first day of the current month, allows customizing the technical analysis lookback period, supports monthly/custom period analysis), then click "Start Analysis"
- Real-Time Progress: 12-stage pipeline displayed in real-time (7 Analysts → Quality Gate → Debate → Risk Control → Decision), with expandable reports for all completed stages
- Complete Report: Signal cards (Buy/Hold/Sell), 7 analyst reports, bull-bear debate, risk control assessment
- Report Export: One-click download of Markdown (zero dependencies, always available) or PDF full analysis reports (PDF automatically adapts to Chinese fonts on Windows/macOS/Linux)
- History: Automatically saves and displays all historical analyses
Screenshot
Configuration
All configuration is passed in through the config dictionary. Complete options:
| Parameter | Default Value | Description |
|---|---|---|
llm_provider |
"minimax" |
LLM provider: minimax / deepseek / qwen / glm / openai / anthropic / google / xai / ollama |
deep_think_llm |
"MiniMax-M2.7" |
Model used by the Research Manager + Portfolio Manager |
quick_think_llm |
"MiniMax-M2.7-highspeed" |
Model used by all Analysts / Researchers / Traders |
backend_url |
None |
Custom API endpoint / third-party relay gateway. Can be filled in via the Web UI sidebar or the .env file's BACKEND_URL; useful for accessing Claude / OpenAI from within China via a proxy |
output_language |
"Chinese" |
Language for report output (internal debates are always in English) |
market_lookback_days |
None |
Lookback period in days for technical analysis (analysis range = start date → analysis date). Automatically calculated from the "data start date" in Web/CLI; None = model chooses (~30 days). #16 |
max_debate_rounds |
1 |
Number of Bull vs Bear debate rounds |
max_risk_discuss_rounds |
1 |
Number of risk three-way debate rounds |
data_vendors |
All "a_stock" |
Data vendor routing |
checkpoint_enabled |
False |
Enable SQLite checkpoint/resume |
memory_log_max_entries |
None |
Maximum number of entries in trading memory |
Common Troubleshooting
Q: Using DeepSeek/Tongyi/Zhipu but getting OpenAIError: The api_key client option must be set ... OPENAI_API_KEY?
Each provider uses its own environment variable, not OPENAI_API_KEY: DeepSeek=DEEPSEEK_API_KEY, Tongyi=DASHSCOPE_API_KEY, Zhipu=ZHIPU_API_KEY, MiniMax=MINIMAX_API_KEY, xAI=XAI_API_KEY, OpenRouter=OPENROUTER_API_KEY, OpenAI-Compatible (Custom)=OPENAI_COMPATIBLE_API_KEY. Set the corresponding variable in the .env file at the project root and restart the program. (Starting from v0.2.12, if the key is missing, it will directly prompt which variable name to use.)
Q: Want to connect to an OpenAI-compatible third-party gateway/relay (9Router, AI Router, self-built proxy) with a custom base_url + model?
Use the 「OpenAI-Compatible (Custom base_url)」 option (added in v0.2.20). In the Web sidebar, select it under "LLM Provider" → Manually enter the model name supported by your gateway under "Fast/Deep Think Model ID" → Enter your gateway address under "API Base URL" (e.g., https://your-relay.example/v1) → Set OPENAI_COMPATIBLE_API_KEY=your_key in .env (it also accepts OPENAI_API_KEY). For CLI, after selecting OpenAI-Compatible, it will prompt for the Base URL. It uses standard Chat Completions (not OpenAI Responses API, for best compatibility), and the model name can be freely entered without being restricted by the built-in list. The equivalent configuration is: llm_provider="openai_compatible" + backend_url="<your_gateway>" + deep_think_llm/quick_think_llm="<your_model>".
Q: Exporting PDF gives UnicodeEncodeError: 'latin-1' codec can't encode?
Your environment has an old version of fpdf (pyfpdf) installed, which conflicts with the fpdf2 used by this project, as both are imported under the name fpdf. Execute: pip uninstall -y fpdf && pip install "fpdf2>=2.8.6". If this doesn't work, you can use the "Download Markdown" export option instead (zero dependencies, always available).
Q: In Docker, exporting PDF gives "Chinese font not found"?
Starting from v0.2.12, the Dockerfile includes fonts-noto-cjk built-in. Simply rebuild with docker build. For older images, you can temporarily run apt install fonts-noto-cjk, or switch to Markdown export.
Q: Docker startup fails with [Errno 13] Permission denied: /home/appuser/.tradingagents/cache?
Older images did not pre-create the data directory. When the docker-compose named volume is mounted, Docker creates it as root-owned, but the process inside the container runs as appuser and cannot write to it. Starting from v0.2.14, the Dockerfile pre-creates /home/appuser/.tradingagents (cache/logs/memory) and sets ownership to appuser, so named volumes inherit this ownership. To upgrade: after git pull, rebuild the image with docker compose build --no-cache. If you want to keep the old data volume, first run docker run --rm -v tradingagents_data:/d alpine chown -R 1000:1000 /d to fix the ownership; otherwise, simply remove the volume with docker volume rm tradingagents_data and rebuild.
Q: Some analyst reports (Sentiment/News/Fundamentals/Policy/Hot Money/Lock-up Expiry) are blank and not displayed? These reports are generated after the corresponding Analyst calls data tools. Empty reports are automatically skipped and not displayed. The data sources themselves are healthy (Tencent/mootdx/Tonghuashun/Dongcai have been tested and return data). Reports are usually empty because the selected model has weak tool-call capabilities (e.g., some lightweight deepseek/minimax models are unstable when calling tools). It is recommended to switch to a model with more stable tool-calls (deepseek-chat / Tongyi / GLM-4 / Claude / GPT, etc.), or retry.
Q: After installing [google] (Gemini), pip reports an httpx conflict: mootdx requires httpx<0.26 but google-genai requires httpx>=0.28?
First, a clarification: litellm / mcp are not dependencies of this project—if they are mentioned in the error, they are brought in by other packages in your environment and are unrelated to TradingAgents. The core installation of this project (pip install -e .) does not depend on httpx≥0.28, and there is no conflict by default; the conflict only arises when installing [google] for Gemini (mootdx and google-genai have mutually exclusive httpx version ranges). Solutions: ① mootdx fetches quotes via TCP protocol and does not call httpx at runtime, so httpx can be upgraded to a version that satisfies google-genai. The incompatible pip warning is just a warning and does not affect mootdx's operation (tested mootdx 0.11.7 works normally with httpx 0.28.1); ② Or separate the environment for running Gemini from the mootdx data layer into different venvs; ③ The simplest solution is to use domestic direct-connect models like MiniMax / DeepSeek / Tongyi, etc., avoiding the problem altogether by not installing [google].
Q: How to batch-run multiple tickers and get the same complete reports as the CLI without entering the CLI interactive mode?
See examples/run_cases.py: It reuses the CLI's save_report_to_disk() function, outputting for each ticker the same complete_report.md (with Analyst / Research / Trading / Risk / Portfolio five sections) and a fully-fledged summary.json. Usage: uv run python examples/run_cases.py (run all) or uv run python examples/run_cases.py 688017 (single ticker); modify build_config() to switch providers/models.
Project Structure
TradingAgents-Astock/
├── tradingagents/
│ ├── agents/
│ │ ├── analysts/ # 7 analysts
│ │ │ ├── market_analyst.py
│ │ │ ├── social_media_analyst.py
│ │ │ ├── news_analyst.py
│ │ │ ├── fundamentals_analyst.py
│ │ │ ├── policy_analyst.py # A-share specialized
│ │ │ ├── hot_money_tracker.py # A-share specialized
│ │ │ └── lockup_watcher.py # A-share specialized
│ │ ├── researchers/ # Bull / Bear researchers
│ │ ├── risk_mgmt/ # Aggressive / Conservative / Neutral debaters
│ │ ├── managers/ # Research Manager + Portfolio Manager
│ │ ├── trader/ # Trader (A-share trading constraints)
│ │ └── utils/ # State definitions, utility functions
│ ├── dataflows/
│ │ ├── a_stock.py # A-share data vendor (direct HTTP API, zero third-party libraries)
│ │ ├── interface.py # Data interface abstraction layer
│ │ └── ...
│ └── graph/
│ ├── trading_graph.py # Main entry point: TradingAgentsGraph
│ ├── setup.py # LangGraph topology definition
│ ├── propagation.py # State initialization and propagation
│ ├── reflection.py # Trading reflection (CSI 300 benchmark)
│ └── conditional_logic.py
├── web/
│ ├── app.py # Streamlit main entry
│ ├── runner.py # Backend thread running analysis
│ ├── progress.py # Thread-safe progress tracking
│ ├── history.py # History record scanning
│ ├── pdf_export.py # PDF report generation
│ ├── launch.py # CLI launcher
│ └── components/ # UI components
│ ├── sidebar.py # Sidebar (inputs + history)
│ ├── progress_panel.py # Real-time progress panel
│ └── report_viewer.py # Report display
├── test_astock.py # E2E integration tests
├── CHANGES_FROM_UPSTREAM.md # Complete change log versus upstream
├── NOTICE # Apache 2.0 attribution notice
├── LICENSE # Apache 2.0 license
└── pyproject.toml # Package definition and dependencies
Acknowledgments
This project is based on the TauricResearch/TradingAgents open-source project, adapted for China's A-share market. We thank the original authors for their outstanding work and the Apache 2.0 open-source spirit.
Original Paper: TradingAgents: Multi-Agents LLM Financial Trading Framework
Project Positioning
This is an engineering implementation of a framework, not an investment product.
- What it is: An A-share engineering implementation of the multi-agent architecture from the TradingAgents paper (TauricResearch), designed for research and teaching—specifically for studying multi-agent debate behavior on financial texts, how to integrate A-share data sources, and how to realize structured outputs.
- What it is not: It is not an investment advisor, not a stock recommendation service, and does not provide any investment services. This repository does not publish analysis reports, ratings, or buy/sell recommendations for specific securities. The
examples/directory only contains scripts you can run yourself; there are no pre-generated conclusions about individual stocks. - Models and data are yours: You configure your own LLM API keys, run it on your own machine, and the output content belongs to you, is judged by you, and is your responsibility. The project itself does not host services, perform analysis on your behalf, or access your run results.
- No executable price levels are generated: The framework does not output positions like entry prices, stop-loss levels, position sizes, or target prices—this isn't a default-off feature; it's simply not present in the code. The Trader and Portfolio Manager only provide direction, ratings, and rationale. Users requiring this capability can fork the code and add it themselves (allowed under Apache-2.0), while assuming all related responsibilities and verifying their own jurisdiction's qualification requirements.
⚠️ Disclaimer
- All content generated by this system is automatically produced by AI and may contain errors or biases.
- This project does not constitute any investment advice. Please consult a professional institution holding qualifications issued by the China Securities Regulatory Commission for investment decisions.
- The author assumes no responsibility for any investment losses incurred from using this tool.
- Stock markets are risky. Invest cautiously.
Support
If this tool saved you time, a coffee is appreciated ☕
Want a feature that isn't here? Open an Issue; sponsors' issues go first.
License
This project is a fork of TauricResearch/TradingAgents and inherits the Apache 2.0 license. See NOTICE.
Author: Simon Lin · X @linsizhen · Email: simonlin0423@gmail.com

