Overview
TradingAgents-CN is a Chinese-enhanced fork of TauricResearch/TradingAgents — a multi-agent stock analysis system positioned as an education and research platform. It does not provide live trading signals. It supports A-share, Hong Kong, and US markets, with full Chinese localization and multi-LLM integration. The project has evolved from a Streamlit monolith (v0.1.x) to an enterprise-grade FastAPI + Vue 3 architecture (v1.0.0-preview).
Key points
Architecture evolution
- v0.1.x: Streamlit single-app prototype
- v1.0.0-preview: Vue 3 + Vite frontend, FastAPI + Uvicorn backend (~10x performance claim), WebSocket/SSE real-time progress, MongoDB + Redis storage, multi-arch Docker with GitHub Actions CI/CD (x86_64 and ARM64)
- Analysis layer: Market, Fundamentals, News, Social analysts
- Research layer: Bull vs. Bear researchers using a debate mechanism, resolved by a Research Manager
- Decision layer: Trader
- Risk layer: Risky/Safe/Neutral analysts feeding a Risk Judge
- Unified state via
AgentState, plus dedicatedInvestDebateStateandRiskDebateState; vector memory based on ChromaDB for experience accumulation - Strategy-pattern unified interface (
dataflows/interface.py) that auto-selects sources: Tushare → AKShare → BaoStock for China, yfinance for US - Three-tier cache: Redis (L1) → MongoDB (L2) → file cache (L3), with adaptive caching, TTL, intelligent fallback, version/hash consistency checks, and cache warm-up
- Extensible data source registry (
constants/data_sources.py) with priority and per-market configuration - 10+ providers: OpenAI, Anthropic, Google AI, Alibaba DashScope (Bailian), DeepSeek, Zhipu AI, SiliconFlow, OpenRouter, Ollama, and any OpenAI-compatible API
- Hybrid mode: quick-think and deep-think models can come from different providers, e.g.
qwen-turbofor fast tasks andgpt-4for deep reasoning — enabling cost optimization, performance balancing, and provider-failure risk diversification - Migration from deprecated JSON-file config (
config_manager.py) to database-driven configuration (MongoDB) with live updates, versioning, and multi-tenant support - Environment variables follow 12-Factor principles (API keys, DB URLs, feature flags)
- Plugin-style
Toolkitfor agent tools andBaseProviderabstraction for data sources with auto-discovery - Docker Compose services: backend (multi-arch), frontend (Nginx), MongoDB, Redis
- Health checks:
/api/healthendpoint, MongoDB ping,redis-cli ping - Structured JSON logging with ELK integration; per-node performance reports (execution time, token usage, cache hit rate)
- Adapter: LLM provider abstraction
- Strategy: data source selection, cache strategies
- Factory: agent/tool-node creation
- Observer: progress callbacks (
_send_progress_update) - Decorator: logging and performance monitoring
- LangGraph async streaming (
astream), connection pooling (MongoDB pool ~100, Redis, httpx), cache pre-warming of hot tickers, LRU/TTL eviction - LLM call optimization: batching, exponential-backoff retries, timeouts, token truncation/compression
- API keys via environment variables, AES-256 encrypted DB storage, runtime key rotation
- Data isolation (MongoDB collections, Redis key prefixes), log redaction, JWT auth, RBAC, rate limiting
- Explicit research-only positioning: no live trading advice, user bears investment risk
- Incomplete migration from legacy JSON config to database config
- Duplicated code across some data source implementations
- Test coverage needs improvement
- Engine:
tradingagents/graph/trading_graph.py,graph/setup.py,graph/conditional_logic.py - Agents:
tradingagents/agents/(analysts, researchers, risk_mgmt) - Data:
tradingagents/dataflows/interface.py,data_source_manager.py,cache/ - LLM:
tradingagents/llm_adapters/(base:openai_compatible_base.py) - Config:
tradingagents/default_config.py(legacyconfig/config_manager.pydeprecated)