The Problem
LLM trading agents are hard to evaluate honestly: backtests overfit, and there is no standardized arena to compare strategies across markets. AI-Trader runs multiple LLM agents autonomously in live markets (NASDAQ 100, SSE 50, crypto) with zero human input, publishing results to a public leaderboard at ai4trade.ai.
What This Does
This is a fork of HKUDS/AI-Trader (21.5k stars upstream), a framework where you submit a strategy agent and it competes against others in live markets. agent/base_agent/ defines the base agent classes (daily and hourly variants); agent/base_agent_astock/ and agent/base_agent_crypto/ adapt them to A-share and crypto markets. agent_tools/ wraps trading, news, search, math, and price-lookup services. configs/ holds per-market JSON configs. The bulk of the repo — 1,714 of 1,796 files — is market data and agent run logs under data/.
How It Is Wired
Execution starts at main.py. The import graph is small — 58 internal modules, 39 edges — and it centers on two hubs. tools/general_tools.py is imported by 17 modules; tools/price_tools.py by 10. Both are high-blast-radius: a change in general_tools.py ripples across nearly a third of the codebase. The base agents in agent/base_agent/ sit mid-graph (Ca 2, Ce 3, instability 0.6). There is one import cycle: agent/base_agent_crypto/base_agent_crypto.py and prompts/agent_prompt_crypto.py are mutually reachable, which makes either file harder to change in isolation.
Agents reach the outside world through agent_tools/ — tool_trade.py, tool_alphavantage_news.py, tool_jina_search.py, tool_get_price_local.py — which is where effects leave the process (external APIs, trade execution). The function-level runtime path from main.py to those calls is not mapped by the available analysis; the import graph gives module edges only.
How To Use It
- Setup:
pip install -r requirements.txt. This is the only dependency manifest; there is no lockfile, so installs are not reproducible. - Configuration: copy
.env.exampleto.envand set API keys. Per-market settings live inconfigs/*.json(default_config.json,default_astock_config.json,default_crypto_config.json). - Running: invoke
main.py. Per the README, the intended contribution flow is a PR addingagent/{your_strategy}.py(inheriting from the base model), a config, and run instructions; the platform runs it for a week and publishes results.
Real-World Use
A team building a strategy-evaluation harness would subclass base_agent, register a config, and let the platform run the strategy against live markets alongside competitors. The public leaderboard provides a comparable benchmark instead of self-reported backtests, and the data/ logs give per-day JSONL traces of reasoning and positions for post-hoc analysis.
Code Health & Issues
Static analysis (measured, not opinion) found 61 findings: 16 high, 45 medium, across 7 kinds. Notable ones:
- High — duplicated code: 2,509 repeated 6-line blocks across 47 files, concentrated in
agent/base_agent/and its variants; the three base-agent families are near-copies of each other. - High — deep nesting: 38 instances, max indentation depth 9 in
tools/price_tools.pyand the base agents. - High — import cycle:
agent/base_agent_crypto/base_agent_crypto.py↔prompts/agent_prompt_crypto.py. - Medium — broad exception handling: 12 bare
exceptclauses intools/general_tools.pyandtools/price_tools.py. - Medium — hub module:
tools/general_tools.pyhas 17 dependents.
No test suite exists (39 source files, zero tests), so regressions ship undetected. CI runs GitHub Actions but has no dependency vulnerability scan, and the deploy workflow keeps persist-credentials at default with no job timeouts.
The Bottom Line
A functional LLM-trading competition framework with a real live leaderboard and public results — the data and logs are the asset. Code quality is research-grade: heavy duplication across market variants, a central hub module, and no tests. Use it to benchmark strategies, not as a base for production trading infrastructure.