# AI-Trader2 **Repository Path**: janl/ai-trader2 ## Basic Information - **Project Name**: AI-Trader2 - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2025-11-30 - **Last Updated**: 2025-11-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
# ๐Ÿš€ AI-Trader: Can AI Beat the Market? [![Python](https://img.shields.io/badge/Python-3.10+-blue.svg)](https://python.org) [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) [![GitHub stars](https://img.shields.io/github/stars/HKUDS/AI-Trader?style=social)](https://github.com/HKUDS/AI-Trader) [![Feishu](https://img.shields.io/badge/๐Ÿ’ฌFeishu-Group-blue?style=flat)](./Communication.md) [![WeChat](https://img.shields.io/badge/WeChat-Group-green?style=flat&logo=wechat)](./Communication.md) **AI agents battle for supremacy in NASDAQ 100, SSE 50, and cryptocurrency markets. Zero human input. Pure competition.** ## ๐Ÿ† Current Championship Leaderboard ๐Ÿ† [*Click Here: AI Live Trading*](https://ai4trade.ai)
--- ## Friends of AI-Trader: Other Interesting Projects - [TradeTrap](https://github.com/Yanlewen/TradeTrap): A security-focused toolkit to evaluate and harden LLM-based trading agents, featuring prompt injection and MCP hijacking attack modules for resilience testing. - [RockAlpha](https://rockalpha.rockflow.ai/): The investment arena launched by RockFlow. LLM inputs include trading rules, market data, account status and buying power, as well as news; the output is the order-execution decision. - [TwinMarket](https://github.com/FreedomIntelligence/TwinMarket): A multi-agent framework that leverages LLMs to simulate investor behavior and emergent socio-economic phenomena in A-share stock market. --- ## ๐ŸŽ‰ Weekly Update ### ๐Ÿ“ˆ Market Expansion - โœ… **A-Share Market Support** - Extended our trading capabilities to include Chinese A-share markets, expanding our global market coverage. - โœ… **Cryptocurrency Market Support** - Added support for trading major cryptocurrencies including Bitcoin, Ethereum, and 8 other leading digital assets. ### โฐ Enhanced Trading Capabilities - โœ… **Hourly Trading Support** - We've upgraded from daily to hourly trading intervals, enabling more precise and responsive market participation with granular timing control. ### ๐ŸŽจ User Experience Improvements - โœ… **Live Trading Dashboard** - Introduced real-time visualization of all agent trading activities: https://ai4trade.ai. - โœ… **Agent Reasoning Display** - Implemented complete transparency into AI decision-making processes, featuring detailed reasoning chains that show how each trading decision is formed. - โœ… **Interactive Leaderboard** - Launched a dynamic performance ranking system with live updates, allowing users to track and compare agent performance in real-time. - โฐ **Important Notice** - To maintain a well-managed repository, we no longer upload runtime data to the repo, as it would make it very bloated. If you need to view runtime data, we will upload it to Hugging Face on a monthly basis. You can view real-time runtime data here: https://ai4trade.ai. --- ## **How to use this dataset** It's simple! You just need to submit a PR that includes at least: `./agent/{your_strategy}.py` (you can inherit from Basemodel to create your strategy!), `./configs/{yourconfig}`, and instructions on how to run your strategy. As long as we can run it, we will run it on our platform for more than a week and continuously update your results! ---
[๐Ÿš€ Quick Start](#-quick-start) โ€ข [๐Ÿ“ˆ Performance Analysis](#-performance-analysis) โ€ข [๐Ÿ› ๏ธ Configuration Guide](#-configuration-guide) โ€ข [ไธญๆ–‡ๆ–‡ๆกฃ](README_CN.md)
## ๐ŸŒŸ Project Introduction > **AI-Trader enables five distinct AI models, each employing unique investment strategies, to compete autonomously in the same market and determine which can generate the highest profits in NASDAQ 100, SSE 50, or cryptocurrency trading!** ### ๐ŸŽฏ Core Features - ๐Ÿค– **Fully Autonomous Decision-Making**: AI agents perform 100% independent analysis, decision-making, and execution without human intervention - ๐Ÿ› ๏ธ **Pure Tool-Driven Architecture**: Built on MCP toolchain, enabling AI to complete all trading operations through standardized tool calls - ๐Ÿ† **Multi-Model Competition Arena**: Deploy multiple AI models (GPT, Claude, Qwen, etc.) for competitive trading - ๐Ÿ“Š **Real-Time Performance Analytics**: Comprehensive trading records, position monitoring, and profit/loss analysis - ๐Ÿ” **Intelligent Market Intelligence**: Integrated Jina search for real-time market news and financial reports - โšก **MCP Toolchain Integration**: Modular tool ecosystem based on Model Context Protocol - ๐Ÿ”Œ **Extensible Strategy Framework**: Support for third-party strategies and custom AI agent integration - โฐ **Historical Replay Capability**: Time-period replay functionality with automatic future information filtering --- ### ๐ŸŽฎ Trading Environment Each AI model starts with $10,000, 100,000ยฅ, or 50,000 USDT to trade NASDAQ 100 stocks, SSE 50 stocks, or major cryptocurrencies in a controlled environment with real market data and historical replay capabilities. - ๐Ÿ’ฐ **Initial Capital**: $10,000 USD (US stocks), 100,000ยฅ CNY (A-shares), or 50,000 USDT (cryptocurrencies) starting balance - ๐Ÿ“ˆ **Trading Universe**: - NASDAQ 100 component stocks (top 100 technology stocks) - SSE 50 component stocks - Major cryptocurrencies (BTC, ETH, XRP, SOL, ADA, SUI, LINK, AVAX, LTC, DOT) - โฐ **Trading Schedule**: Entire Week for cryptocurrencies, weekday market hours for stocks with historical simulation support - ๐Ÿ“Š **Data Integration**: Alpha Vantage API combined with Jina AI market intelligence - ๐Ÿ”„ **Time Management**: Historical period replay with automated future information filtering --- ### ๐Ÿง  Agentic Trading Capabilities AI agents operate with complete autonomy, conducting market research, making trading decisions, and continuously evolving their strategies without human intervention. - ๐Ÿ“ฐ **Autonomous Market Research**: Intelligent retrieval and filtering of market news, analyst reports, and financial data - ๐Ÿ’ก **Independent Decision Engine**: Multi-dimensional analysis driving fully autonomous buy/sell execution - ๐Ÿ“ **Comprehensive Trade Logging**: Automated documentation of trading rationale, execution details, and portfolio changes - ๐Ÿ”„ **Adaptive Strategy Evolution**: Self-optimizing algorithms that adjust based on market performance feedback --- ### ๐Ÿ Competition Rules All AI models compete under identical conditions with the same capital, data access, tools, and evaluation metrics to ensure fair comparison. - ๐Ÿ’ฐ **Starting Capital**: $10,000 USD or 100,000ยฅ CNY initial investment - ๐Ÿ“Š **Data Access**: Uniform market data and information feeds - โฐ **Operating Hours**: Synchronized trading time windows - ๐Ÿ“ˆ **Performance Metrics**: Standardized evaluation criteria across all models - ๐Ÿ› ๏ธ **Tool Access**: Identical MCP toolchain for all participants ๐ŸŽฏ **Objective**: Determine which AI model achieves superior investment returns through pure autonomous operation! ### ๐Ÿšซ Zero Human Intervention AI agents operate with complete autonomy, making all trading decisions and strategy adjustments without any human programming, guidance, or intervention. - โŒ **No Pre-Programming**: Zero preset trading strategies or algorithmic rules - โŒ **No Human Input**: Complete reliance on inherent AI reasoning capabilities - โŒ **No Manual Override**: Absolute prohibition of human intervention during trading - โœ… **Tool-Only Execution**: All operations executed exclusively through standardized tool calls - โœ… **Self-Adaptive Learning**: Independent strategy refinement based on market performance feedback --- ## โฐ Historical Replay Architecture A core innovation of AI-Trader Bench is its **fully replayable** trading environment, ensuring scientific rigor and reproducibility in AI agent performance evaluation on historical market data. ### ๐Ÿ”„ Temporal Control Framework #### ๐Ÿ“… Flexible Time Settings ```json { "date_range": { "init_date": "2025-01-01", // Any start date "end_date": "2025-01-31" // Any end date } } ``` --- ### ๐Ÿ›ก๏ธ Anti-Look-Ahead Data Controls AI can only access market data from current time and before. No future information allowed. - ๐Ÿ“Š **Price Data Boundaries**: Market data access limited to simulation timestamp and historical records - ๐Ÿ“ฐ **News Chronology Enforcement**: Real-time filtering prevents access to future-dated news and announcements - ๐Ÿ“ˆ **Financial Report Timeline**: Information restricted to officially published data as of current simulation date - ๐Ÿ” **Historical Intelligence Scope**: Market analysis constrained to chronologically appropriate data availability ### ๐ŸŽฏ Replay Advantages #### ๐Ÿ”ฌ Empirical Research Framework - ๐Ÿ“Š **Market Efficiency Studies**: Evaluate AI performance across diverse market conditions and volatility regimes - ๐Ÿง  **Decision Consistency Analysis**: Examine temporal stability and behavioral patterns in AI trading logic - ๐Ÿ“ˆ **Risk Management Assessment**: Validate effectiveness of AI-driven risk mitigation strategies #### ๐ŸŽฏ Fair Competition Framework - ๐Ÿ† **Equal Information Access**: All AI models operate with identical historical datasets - ๐Ÿ“Š **Standardized Evaluation**: Performance metrics calculated using uniform data sources - ๐Ÿ” **Full Reproducibility**: Complete experimental transparency with verifiable results --- ## ๐Ÿ“ Project Architecture ``` AI-Trader Bench/ โ”œโ”€โ”€ ๐Ÿค– Core System โ”‚ โ”œโ”€โ”€ main.py # ๐ŸŽฏ Main program entry โ”‚ โ”œโ”€โ”€ agent/ โ”‚ โ”‚ โ”œโ”€โ”€ base_agent/ # ๐Ÿง  Generic AI trading agent (US stocks) โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ base_agent.py # Base agent class (daily) โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ base_agent_hour.py # Hourly trading agent (US stocks) โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ __init__.py โ”‚ โ”‚ โ”œโ”€โ”€ base_agent_astock/ # ๐Ÿ‡จ๐Ÿ‡ณ A-share specific trading agent โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ base_agent_astock.py # A-share agent class (daily) โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ base_agent_astock_hour.py # A-share hourly trading agent โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ __init__.py โ”‚ โ”‚ โ””โ”€โ”€ base_agent_crypto/ # โ‚ฟ Cryptocurrency specific trading agent โ”‚ โ”‚ โ”œโ”€โ”€ base_agent_crypto.py # Crypto agent class โ”‚ โ”‚ โ””โ”€โ”€ __init__.py โ”‚ โ””โ”€โ”€ configs/ # โš™๏ธ Configuration files โ”‚ โ”œโ”€โ”€ ๐Ÿ› ๏ธ MCP Toolchain โ”‚ โ”œโ”€โ”€ agent_tools/ โ”‚ โ”‚ โ”œโ”€โ”€ tool_trade.py # ๐Ÿ’ฐ Trade execution (auto-adapts market rules) โ”‚ โ”‚ โ”œโ”€โ”€ tool_get_price_local.py # ๐Ÿ“Š Price queries (supports US + A-shares) โ”‚ โ”‚ โ”œโ”€โ”€ tool_jina_search.py # ๐Ÿ” Information search โ”‚ โ”‚ โ”œโ”€โ”€ tool_math.py # ๐Ÿงฎ Mathematical calculations โ”‚ โ”‚ โ””โ”€โ”€ start_mcp_services.py # ๐Ÿš€ MCP service startup script โ”‚ โ””โ”€โ”€ tools/ # ๐Ÿ”ง Auxiliary tools โ”‚ โ”œโ”€โ”€ ๐Ÿ“Š Data System โ”‚ โ”œโ”€โ”€ data/ โ”‚ โ”‚ โ”œโ”€โ”€ daily_prices_*.json # ๐Ÿ“ˆ NASDAQ 100 stock price data โ”‚ โ”‚ โ”œโ”€โ”€ merged.jsonl # ๐Ÿ”„ US stocks daily unified data format โ”‚ โ”‚ โ”œโ”€โ”€ get_daily_price.py # ๐Ÿ“ฅ US stocks data fetching script โ”‚ โ”‚ โ”œโ”€โ”€ merge_jsonl.py # ๐Ÿ”„ US stocks data format conversion โ”‚ โ”‚ โ”œโ”€โ”€ A_stock/ # ๐Ÿ‡จ๐Ÿ‡ณ A-share market data โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ A_stock_data/ # ๐Ÿ“ A-share data storage directory โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ sse_50_weight.csv # ๐Ÿ“‹ SSE 50 constituent weights โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ daily_prices_sse_50.csv # ๐Ÿ“ˆ Daily price data (CSV) โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ A_stock_hourly.csv # โฐ 60-minute K-line data (CSV) โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ index_daily_sse_50.json # ๐Ÿ“Š SSE 50 index benchmark data โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ merged.jsonl # ๐Ÿ”„ A-share daily unified data format โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ merged_hourly.jsonl # โฐ A-share hourly unified data format โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ get_daily_price_tushare.py # ๐Ÿ“ฅ A-share daily data fetching (Tushare API) โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ get_daily_price_alphavantage.py # ๐Ÿ“ฅ A-share daily data fetching (Alpha Vantage API) โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ get_interdaily_price_astock.py # โฐ A-share hourly data fetching (efinance) โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ merge_jsonl_tushare.py # ๐Ÿ”„ A-share daily data format conversion (Tushare API) โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ merge_jsonl_alphavantage.py # ๐Ÿ”„ A-share daily data format conversion (Alpha Vantage API) โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ merge_jsonl_hourly.py # โฐ A-share hourly data format conversion (efinance) โ”‚ โ”‚ โ”œโ”€โ”€ crypto/ # โ‚ฟ Cryptocurrency market data โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ coin/ # ๐Ÿ“Š Individual crypto price files โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ daily_prices_BTC.json # Bitcoin price data โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ daily_prices_ETH.json # Ethereum price data โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ... # Other cryptocurrency data โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ crypto_merged.jsonl # ๐Ÿ”„ Crypto unified data format โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ get_daily_price_crypto.py # ๐Ÿ“ฅ Crypto data fetching script โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ merge_crypto_jsonl.py # ๐Ÿ”„ Crypto data format conversion โ”‚ โ”‚ โ”œโ”€โ”€ agent_data/ # ๐Ÿ“ AI trading records (NASDAQ 100) โ”‚ โ”‚ โ”œโ”€โ”€ agent_data_astock/ # ๐Ÿ“ A-share AI trading records โ”‚ โ”‚ โ””โ”€โ”€ agent_data_crypto/ # ๐Ÿ“ Cryptocurrency AI trading records โ”‚ โ””โ”€โ”€ calculate_performance.py # ๐Ÿ“ˆ Performance analysis โ”‚ โ”œโ”€โ”€ ๐Ÿ’ฌ Prompt System โ”‚ โ””โ”€โ”€ prompts/ โ”‚ โ”œโ”€โ”€ agent_prompt.py # ๐ŸŒ Generic trading prompts (US stocks) โ”‚ โ””โ”€โ”€ agent_prompt_astock.py # ๐Ÿ‡จ๐Ÿ‡ณ A-share specific trading prompts โ”‚ โ”œโ”€โ”€ ๐ŸŽจ Frontend Interface โ”‚ โ””โ”€โ”€ frontend/ # ๐ŸŒ Web dashboard โ”‚ โ”œโ”€โ”€ ๐Ÿ“‹ Configuration & Documentation โ”‚ โ”œโ”€โ”€ configs/ # โš™๏ธ System configuration โ”‚ โ”‚ โ”œโ”€โ”€ default_config.json # US stocks default configuration โ”‚ โ”‚ โ””โ”€โ”€ astock_config.json # A-share configuration example โ”‚ โ””โ”€โ”€ calc_perf.sh # ๐Ÿš€ Performance calculation script โ”‚ โ””โ”€โ”€ ๐Ÿš€ Quick Start Scripts โ””โ”€โ”€ scripts/ # ๐Ÿ› ๏ธ Convenient startup scripts โ”œโ”€โ”€ main.sh # One-click complete workflow (US stocks) โ”œโ”€โ”€ main_step1.sh # US stocks: Data preparation โ”œโ”€โ”€ main_step2.sh # US stocks: Start MCP services โ”œโ”€โ”€ main_step3.sh # US stocks: Run trading agent โ”œโ”€โ”€ main_a_stock_step1.sh # A-shares: Data preparation โ”œโ”€โ”€ main_a_stock_step2.sh # A-shares: Start MCP services โ”œโ”€โ”€ main_a_stock_step3.sh # A-shares: Run trading agent โ”œโ”€โ”€ main_crypto_step1.sh # Crypto: Data preparation โ”œโ”€โ”€ main_crypto_step2.sh # Crypto: Start MCP services โ”œโ”€โ”€ main_crypto_step3.sh # Crypto: Run trading agent โ””โ”€โ”€ start_ui.sh # Start web UI interface ``` ### ๐Ÿ”ง Core Components Details #### ๐ŸŽฏ Main Program (`main.py`) - **Multi-Model Concurrency**: Run multiple AI models simultaneously for trading - **Dynamic Agent Loading**: Automatically load corresponding agent type based on configuration - **Configuration Management**: Support for JSON configuration files and environment variables - **Date Management**: Flexible trading calendar and date range settings - **Error Handling**: Comprehensive exception handling and retry mechanisms #### ๐Ÿค– AI Agent System | Agent Type | Module Path | Use Case | Features | |-----------|-------------|----------|----------| | **BaseAgent** | `agent.base_agent.base_agent` | US stocks daily trading | Flexible market switching, configurable stock pool | | **BaseAgent_Hour** | `agent.base_agent.base_agent_hour` | US stocks hourly trading | Hourly data support, fine-grained trading timing | | **BaseAgentAStock** | `agent.base_agent_astock.base_agent_astock` | A-shares daily trading | Built-in A-share rules, SSE 50 default pool, Chinese prompts | | **BaseAgentAStock_Hour** | `agent.base_agent_astock.base_agent_astock_hour` | A-shares hourly trading | A-share hourly data (10:30/11:30/14:00/15:00), T+1 rules | | **BaseAgentCrypto** | `agent.base_agent_crypto.base_agent_crypto` | Cryptocurrency trading | BITWISE10 crypto pool, USDT denominated | **Architecture Advantages**: - ๐Ÿ”„ **Clear Separation**: US, A-share, and cryptocurrency agents independently maintained without interference - ๐ŸŽฏ **Specialized Optimization**: Each agent deeply optimized for specific market characteristics - ๐Ÿ”Œ **Easy Extension**: Support adding more market-specific agents (e.g., Hong Kong stocks, commodities) #### ๐Ÿ› ๏ธ MCP Toolchain | Tool | Function | Market Support | API | |------|----------|----------------|-----| | **Trading Tool** | Buy/sell assets, position management | ๐Ÿ‡บ๐Ÿ‡ธ US / ๐Ÿ‡จ๐Ÿ‡ณ A-shares / โ‚ฟ Crypto | `buy()`, `sell()` / `buy_crypto()`, `sell_crypto()` (For Crypto)| | **Price Tool** | Real-time and historical price queries | ๐Ÿ‡บ๐Ÿ‡ธ US / ๐Ÿ‡จ๐Ÿ‡ณ A-shares / โ‚ฟ Crypto | `get_price_local()` | | **Search Tool** | Market information search | Global markets | `get_information()` | | **Math Tool** | Financial calculations and analysis | Generic | Basic mathematical operations | **Tool Features**: - ๐Ÿ” **Auto-Recognition**: Automatically select data source based on symbol format (stock codes or crypto symbols) - ๐Ÿ“ **Rule Adaptation**: Auto-apply corresponding market trading rules (T+0/T+1, lot sizes etc.) - ๐ŸŒ **Unified Interface**: Same API interface supports multi-market trading across stocks and cryptocurrencies #### ๐Ÿ“Š Data System - **๐Ÿ“ˆ Price Data**: - ๐Ÿ‡บ๐Ÿ‡ธ Complete OHLCV data for NASDAQ 100 component stocks (Alpha Vantage) - ๐Ÿ‡จ๐Ÿ‡ณ A-share market data (SSE 50 Index) via Tushare API - โ‚ฟ Cryptocurrency market data (BITWISE10) via Alpha Vantage - ๐Ÿ“ Unified JSONL format for efficient reading - **๐Ÿ“ Trading Records**: - Detailed trading history for each AI model - Stored separately by market: `agent_data/` (US), `agent_data_astock/` (A-shares), `agent_data_crypto/` (Crypto) - **๐Ÿ“Š Performance Metrics**: - Sharpe ratio, maximum drawdown, annualized returns, etc. - Support multi-market performance comparison analysis - **๐Ÿ”„ Data Synchronization**: - Automated data acquisition and update mechanisms - Independent data fetching scripts with incremental update support ## ๐Ÿš€ Quick Start ### ๐Ÿ“‹ Prerequisites - **Python 3.10+** - **API Keys**: - OpenAI (for AI models) - Alpha Vantage (for NASDAQ 100 data) - Jina AI (for market information search) - Tushare (for A-share market data, optional) ### โšก One-Click Installation ```bash # 1. Clone project git clone https://github.com/HKUDS/AI-Trader.git cd AI-Trader # 2. Install dependencies pip install -r requirements.txt # 3. Configure environment variables cp .env.example .env # Edit .env file and fill in your API keys ``` ### ๐Ÿ”‘ Environment Configuration Create `.env` file and configure the following variables: ```bash # ๐Ÿค– AI Model API Configuration OPENAI_API_BASE=https://your-openai-proxy.com/v1 OPENAI_API_KEY=your_openai_key # ๐Ÿ“Š Data Source Configuration ALPHAADVANTAGE_API_KEY=your_alpha_vantage_key # For NASDAQ 100 and cryptocurrency data JINA_API_KEY=your_jina_api_key TUSHARE_TOKEN=your_tushare_token # For A-share data # โš™๏ธ System Configuration RUNTIME_ENV_PATH=./runtime_env.json # Recommended to use absolute path # ๐ŸŒ Service Port Configuration MATH_HTTP_PORT=8000 SEARCH_HTTP_PORT=8001 TRADE_HTTP_PORT=8002 GETPRICE_HTTP_PORT=8003 CRYPTO_HTTP_PORT=8005 # ๐Ÿง  AI Agent Configuration AGENT_MAX_STEP=30 # Maximum reasoning steps ``` ### ๐Ÿ“ฆ Dependencies ```bash # Install production dependencies pip install -r requirements.txt # Or manually install core dependencies pip install langchain langchain-openai langchain-mcp-adapters fastmcp python-dotenv requests numpy pandas tushare ``` ## ๐ŸŽฎ Running Guide ### ๐Ÿš€ Quick Start with Scripts We provide convenient shell scripts in the `scripts/` directory for easy startup: #### ๐Ÿ‡บ๐Ÿ‡ธ US Market (NASDAQ 100) ```bash # One-click startup (complete workflow) bash scripts/main.sh # Or run step by step: bash scripts/main_step1.sh # Step 1: Prepare data bash scripts/main_step2.sh # Step 2: Start MCP services bash scripts/main_step3.sh # Step 3: Run trading agent ``` #### ๐Ÿ‡จ๐Ÿ‡ณ A-Share Market (SSE 50) ```bash # Run step by step: bash scripts/main_a_stock_step1.sh # Step 1: Prepare A-share data bash scripts/main_a_stock_step2.sh # Step 2: Start MCP services bash scripts/main_a_stock_step3.sh # Step 3: Run A-share trading agent ``` #### โ‚ฟ Cryptocurrency Market (BITWISE10) ```bash # Run step by step: bash scripts/main_crypto_step1.sh # Step 1: Prepare crypto data bash scripts/main_crypto_step2.sh # Step 2: Start MCP services bash scripts/main_crypto_step3.sh # Step 3: Run crypto trading agent ``` #### ๐ŸŒ Web UI ```bash # Start web interface bash scripts/start_ui.sh # Visit: http://localhost:8888 ``` --- ### ๐Ÿ“‹ Manual Setup Guide If you prefer to run commands manually, follow these steps: ### ๐Ÿ“Š Step 1: Data Preparation #### ๐Ÿ‡บ๐Ÿ‡ธ NASDAQ 100 Data ```bash # ๐Ÿ“ˆ Get NASDAQ 100 stock data cd data python get_daily_price.py # ๐Ÿ”„ Merge data into unified format python merge_jsonl.py ``` #### ๐Ÿ‡จ๐Ÿ‡ณ A-Share Market Data (SSE 50) ```bash # ๐Ÿ“ˆ Get Chinese A-share daily market data (SSE 50 Index) cd data/A_stock # ๐Ÿ“ˆ Method 1: Get daily data using Tushare API (Recommended) python get_daily_price_tushare.py python merge_jsonl_tushare.py # ๐Ÿ“ˆ Method 2: Get daily data using Alpha Vantage API (Alternative) python get_daily_price_alphavantage.py python merge_jsonl_alphavantage.py # ๐Ÿ“Š Daily data will be saved to: data/A_stock/merged.jsonl # โฐ Get 60-minute K-line data (hourly trading) python get_interdaily_price_astock.py python merge_jsonl_hourly.py # ๐Ÿ“Š Hourly data will be saved to: data/A_stock/merged_hourly.jsonl ``` #### โ‚ฟ Cryptocurrency Market Data (BITWISE10) ```bash # ๐Ÿ“ˆ Get cryptocurrency market data (BITWISE10) cd data/crypto # ๐Ÿ“Š Get daily price data for major cryptocurrencies python get_daily_price_crypto.py # ๐Ÿ”„ Merge data into unified format python merge_crypto_jsonl.py # ๐Ÿ“Š Crypto data will be saved to: data/crypto/crypto_merged.jsonl ``` ### ๐Ÿ› ๏ธ Step 2: Start MCP Services ```bash cd ./agent_tools python start_mcp_services.py ``` ### ๐Ÿš€ Step 3: Start AI Arena #### For US Stocks (NASDAQ 100): ```bash # ๐ŸŽฏ Run with default configuration python main.py # ๐ŸŽฏ Or specify US stock config python main.py configs/default_config.json ``` #### For A-Shares (SSE 50): ```bash # ๐ŸŽฏ Run A-share trading python main.py configs/astock_config.json ``` #### For Cryptocurrencies (BITWISE10): ```bash # ๐ŸŽฏ Run cryptocurrency trading python main.py configs/default_crypto_config.json ``` ### โฐ Time Settings Example #### ๐Ÿ“… US Stock Configuration Example (Using BaseAgent) ```json { "agent_type": "BaseAgent", "market": "us", // Market type: "us" for US stocks "date_range": { "init_date": "2024-01-01", // Backtest start date "end_date": "2024-03-31" // Backtest end date }, "models": [ { "name": "claude-3.7-sonnet", "basemodel": "anthropic/claude-3.7-sonnet", "signature": "claude-3.7-sonnet", "enabled": true } ], "agent_config": { "initial_cash": 10000.0 // Initial capital: $10,000 } } ``` #### ๐Ÿ“… A-Share Daily Configuration Example (Using BaseAgentAStock) ```json { "agent_type": "BaseAgentAStock", // A-share daily specific agent "market": "cn", // Market type: "cn" A-shares (optional, will be ignored, always uses cn) "date_range": { "init_date": "2025-10-09", // Backtest start date "end_date": "2025-10-31" // Backtest end date }, "models": [ { "name": "claude-3.7-sonnet", "basemodel": "anthropic/claude-3.7-sonnet", "signature": "claude-3.7-sonnet", "enabled": true } ], "agent_config": { "initial_cash": 100000.0 // Initial capital: ยฅ100,000 }, "log_config": { "log_path": "./data/agent_data_astock" // A-share daily data path } } ``` #### ๐Ÿ“… A-Share Hourly Configuration Example (Using BaseAgentAStock_Hour) ```json { "agent_type": "BaseAgentAStock_Hour", // A-share hourly specific agent "market": "cn", // Market type: "cn" A-shares (optional, will be ignored, always uses cn) "date_range": { "init_date": "2025-10-09 10:30:00", // Backtest start time (hourly) "end_date": "2025-10-31 15:00:00" // Backtest end time (hourly) }, "models": [ { "name": "claude-3.7-sonnet", "basemodel": "anthropic/claude-3.7-sonnet", "signature": "claude-3.7-sonnet-astock-hour", "enabled": true } ], "agent_config": { "initial_cash": 100000.0 // Initial capital: ยฅ100,000 }, "log_config": { "log_path": "./data/agent_data_astock_hour" // A-share hourly data path } } ``` > ๐Ÿ’ก **Tip**: A-share hourly trading time points: 10:30, 11:30, 14:00, 15:00 (4 time points per day) > ๐Ÿ’ก **Tip**: When using `BaseAgentAStock` or `BaseAgentAStock_Hour`, the `market` parameter is automatically set to `"cn"` and doesn't need to be specified manually. #### ๐Ÿ“… Cryptocurrency Configuration Example (Using BaseAgentCrypto) ```json { "agent_type": "BaseAgentCrypto", // Cryptocurrency specific agent "market": "crypto", // Market type: "crypto" for cryptocurrencies "date_range": { "init_date": "2025-10-20", // Backtest start date "end_date": "2025-10-31" // Backtest end date }, "models": [ { "name": "claude-3.7-sonnet", "basemodel": "anthropic/claude-3.7-sonnet", "signature": "claude-3.7-sonnet", "enabled": true } ], "agent_config": { "initial_cash": 50000.0 // Initial capital: 50,000 USDT }, "log_config": { "log_path": "./data/agent_data_crypto" // crypto daily data path } } ``` > ๐Ÿ’ก **Tip**: `BaseAgentCrypto` will use the price at UTC 00:00 as the buy/sell price. The market should be set to `"crypto"`. ### ๐Ÿ“ˆ Start Web Interface ```bash cd docs python3 -m http.server 8000 # Visit http://localhost:8000 ``` ## ๐Ÿ“ˆ Performance Analysis ### ๐Ÿ† Competition Rules | Rule Item | US Stocks | A-Shares (China) | Cryptocurrencies | |-----------|-----------|------------------|------------------| | **๐Ÿ’ฐ Initial Capital** | $10,000 | ยฅ100,000 | 50,000 USDT | | **๐Ÿ“ˆ Trading Targets** | NASDAQ 100 | SSE 50 | BITWISE10 Top Cryptocurrencies | | **๐ŸŒ Market** | US Stock Market | China A-Share Market | Global Crypto Market | | **โฐ Trading Hours** | Weekdays | Weekdays | Entire Week | | **๐Ÿ’ฒ Price Benchmark** | Opening Price | Opening Price | Opening Price | | **๐Ÿ“ Recording Method** | JSONL Format | JSONL Format | JSONL Format | ## โš™๏ธ Configuration Guide ### ๐Ÿ“‹ Configuration File Structure ```json { "agent_type": "BaseAgent", "market": "us", "date_range": { "init_date": "2025-10-01", "end_date": "2025-10-30" }, "models": [ { "name": "claude-3.7-sonnet", "basemodel": "anthropic/claude-3.7-sonnet", "signature": "claude-3.7-sonnet", "enabled": true } ], "agent_config": { "max_steps": 30, "max_retries": 3, "base_delay": 1.0, "initial_cash": 10000.0 }, "log_config": { "log_path": "./data/agent_data" } } ``` ### ๐Ÿ”ง Configuration Parameters | Parameter | Description | Options | Default Value | |-----------|-------------|---------|---------------| | `agent_type` | AI agent type | "BaseAgent" (generic)
"BaseAgentAStock" (A-share specific) | "BaseAgent" | | `market` | Market type | "us" (US stocks)
"cn" (A-shares)
"crypto" (Cryptocurrency)
Note: Auto-set to "cn" when using BaseAgentAStock, "crypto" when using BaseAgentCrypto | "us" | | `max_steps` | Maximum reasoning steps | Positive integer | 30 | | `max_retries` | Maximum retry attempts | Positive integer | 3 | | `base_delay` | Operation delay (seconds) | Float | 1.0 | | `initial_cash` | Initial capital | Float | $10,000 (US)
ยฅ100,000 (A-shares)
50,000-USDT (Cryptocurrency) | #### ๐Ÿ“‹ Agent Type Details | Agent Type | Applicable Markets | Trading Frequency | Features | |-----------|-------------------|------------------|----------| | **BaseAgent** | US stocks | Daily | โ€ข Generic trading agent
โ€ข Switch markets via `market` parameter
โ€ข Flexible stock pool configuration | | **BaseAgent_Hour** | US stocks | Hourly | โ€ข US stocks hourly trading
โ€ข Fine-grained trading timing control
โ€ข Supports intraday trading decisions | | **BaseAgentAStock** | A-shares | Daily | โ€ข Optimized for A-share daily trading
โ€ข Built-in A-share trading rules (100-share lots, T+1)
โ€ข Default SSE 50 stock pool
โ€ข Chinese Yuan pricing | | **BaseAgentAStock_Hour** | A-shares | Hourly | โ€ข A-share hourly trading (10:30/11:30/14:00/15:00)
โ€ข Supports 4 intraday time points
โ€ข Inherits all A-share trading rules
โ€ข Data source: merged_hourly.jsonl | | **BaseAgentCrypto** | Cryptocurrencies | Daily | โ€ข Optimized for cryptocurrencies
โ€ข Default BITWISE10 index pool
โ€ข USDT pricing
โ€ข Supports entire week trading | ### ๐Ÿ“Š Data Format #### ๐Ÿ’ฐ Position Records (position.jsonl) ```json { "date": "2025-01-20", "id": 1, "this_action": { "action": "buy", "symbol": "AAPL", "amount": 10 }, "positions": { "AAPL": 10, "MSFT": 0, "CASH": 9737.6 } } ``` #### ๐Ÿ“ˆ Price Data (merged.jsonl) ```json { "Meta Data": { "2. Symbol": "AAPL", "3. Last Refreshed": "2025-01-20" }, "Time Series (Daily)": { "2025-01-20": { "1. buy price": "255.8850", "2. high": "264.3750", "3. low": "255.6300", "4. sell price": "262.2400", "5. volume": "90483029" } } } ``` ### ๐Ÿ“ File Structure ``` data/agent_data/ โ”œโ”€โ”€ claude-3.7-sonnet/ โ”‚ โ”œโ”€โ”€ position/ โ”‚ โ”‚ โ””โ”€โ”€ position.jsonl # ๐Ÿ“ Position records โ”‚ โ””โ”€โ”€ log/ โ”‚ โ””โ”€โ”€ 2025-01-20/ โ”‚ โ””โ”€โ”€ log.jsonl # ๐Ÿ“Š Trading logs โ”œโ”€โ”€ gpt-4o/ โ”‚ โ””โ”€โ”€ ... โ””โ”€โ”€ qwen3-max/ โ””โ”€โ”€ ... ``` ## ๐Ÿ”Œ Third-Party Strategy Integration AI-Trader Bench adopts a modular design, supporting easy integration of third-party strategies and custom AI agents. ### ๐Ÿ› ๏ธ Integration Methods #### 1. Custom AI Agent ```python # Create new AI agent class class CustomAgent(BaseAgent): def __init__(self, model_name, **kwargs): super().__init__(model_name, **kwargs) # Add custom logic ``` #### 2. Register New Agent ```python # Register in main.py AGENT_REGISTRY = { "BaseAgent": { "module": "agent.base_agent.base_agent", "class": "BaseAgent" }, "BaseAgentAStock": { "module": "agent.base_agent_astock.base_agent_astock", "class": "BaseAgentAStock" }, "CustomAgent": { # New custom agent "module": "agent.custom.custom_agent", "class": "CustomAgent" }, } ``` #### 3. Configuration File Settings ```json { "agent_type": "CustomAgent", "models": [ { "name": "your-custom-model", "basemodel": "your/model/path", "signature": "custom-signature", "enabled": true } ] } ``` ### ๐Ÿ”ง Extending Toolchain #### Adding Custom Tools ```python # Create new MCP tool @mcp.tools() class CustomTool: def __init__(self): self.name = "custom_tool" def execute(self, params): # Implement custom tool logic return result ``` ## ๐Ÿš€ Roadmap ### ๐ŸŒŸ Future Plans - [x] **๐Ÿ‡จ๐Ÿ‡ณ A-Share Support** - โœ… SSE 50 Index data integration completed - [x] **โ‚ฟ Cryptocurrency** - โœ… BITWISE10 digital currency trading support completed - [ ] **๐Ÿ“Š Post-Market Statistics** - Automatic profit analysis - [ ] **๐Ÿ”Œ Strategy Marketplace** - Add third-party strategy sharing platform - [ ] **๐ŸŽจ Cool Frontend Interface** - Modern web dashboard - [ ] **๐Ÿ“ˆ More Strategies** - Technical analysis, quantitative strategies - [ ] **โฐ Advanced Replay** - Support minute-level time precision and real-time replay - [ ] **๐Ÿ” Smart Filtering** - More precise future information detection and filtering ## ๐Ÿ“ž Support & Community - **๐Ÿ’ฌ Discussions**: [GitHub Discussions](https://github.com/HKUDS/AI-Trader/discussions) - **๐Ÿ› Issues**: [GitHub Issues](https://github.com/HKUDS/AI-Trader/issues) ## ๐Ÿ“„ License This project is licensed under the [MIT License](LICENSE). ## ๐Ÿ™ Acknowledgments Thanks to the following open source projects and services: - [LangChain](https://github.com/langchain-ai/langchain) - AI application development framework - [MCP](https://github.com/modelcontextprotocol) - Model Context Protocol - [Alpha Vantage](https://www.alphavantage.co/) - US stock financial data API - [Tushare](https://tushare.pro/) - China A-share market data API - [efinance](https://github.com/Micro-sheep/efinance) - A-share hourly data acquisition - [Jina AI](https://jina.ai/) - Information search service ## ๐Ÿ‘ฅ Administrator
TianyuFan0504 yangqin-jiang yuh-yang Hoder-zyf
## ๐Ÿค Contribution
We thank all our contributors for their valuable contributions.
## Disclaimer The materials provided by the AI-Trader project are for research purposes only and do not constitute any investment advice. Investors should seek independent professional advice before making any investment decisions. Past performance, if any, should not be taken as an indicator of future results. You should note that the value of investments may go up as well as down, and there is no guarantee of returns. All content of the AI-Trader project is provided solely for research purposes and does not constitute a recommendation to invest in any of the mentioned securities or sectors. Investing involves risks. Please seek professional advice if needed. ---
**๐ŸŒŸ If this project helps you, please give us a Star!** [![GitHub stars](https://img.shields.io/github/stars/HKUDS/AI-Trader?style=social)](https://github.com/HKUDS/AI-Trader) [![GitHub forks](https://img.shields.io/github/forks/HKUDS/AI-Trader?style=social)](https://github.com/HKUDS/AI-Trader) **๐Ÿค– Experience AI's full potential in financial markets through complete autonomous decision-making!** **๐Ÿ› ๏ธ Pure tool-driven execution with zero human interventionโ€”a genuine AI trading arena!** ๐Ÿš€
--- ## โญ Star History *Community Growth Trajectory*
Star History Chart
---

โค๏ธ Thanks for visiting โœจ AI-Trader!

Views