Intelligent Multi-Agent Quantitative Trading Bot based on the Adversarial Decision Framework (ADF). Achieves high win rates and low drawdown in automated futures trading through market regime detection, price position awareness, dynamic score calibration, and multi-layer physical auditing.
- ๐ต๏ธ Perception First: Unlike strict indicator-based systems, this framework prioritizes judging "IF we should trade" before deciding "HOW to trade".
- ๐ค Multi-Agent Collaboration: 4 highly specialized Agents operating independently to form an adversarial verification chain.
- โก Async Concurrency: Currently fetches multi-timeframe data (5m/15m/1h) concurrently, ensuring data alignment at the snapshot moment.
- ๐ก๏ธ Safety First: Stop-loss direction correction, capital pre-rehearsal, and veto mechanisms to safeguard live trading.
- ๐ Full-Link Auditing: Every decision's adversarial process and confidence penalty details are recorded, achieving true "White-Box" decision-making.
pip install -r requirements.txt# Copy environment variable template
cp .env.example .env
# Set API Keys
./set_api_keys.sh# Copy config template
cp config.example.yaml config.yamlEdit config.yaml to set parameters:
- Trading pair (symbol)
- Max position size (max_position_size)
- Leverage (leverage)
- Stop loss/Take profit % (stop_loss_pct, take_profit_pct)
Built-in modern real-time monitoring dashboard.
# Start main program (automatically starts Web server)
python main.py --mode continuousAfter startup, visit: http://localhost:8000
Dashboard Features:
- ๐ Real-time K-Line: Integrated TradingView widget, 1-minute real-time updates
- ๐ Net Value Curve: Real-time equity tracking
- ๐ Decision Audit: Full history of decision records, including detailed Agent scores (Strategist, Trend, Oscillator, Sentiment)
- ๐ Trade History: Complete record of all trades and PnL statistics
- ๐ก Live Log Output: Real-time scrolling logs with highlighted Agent tags (Oracle, Strategist, Critic, Guardian), 500-line history buffer
LLM-TradeBot/
โโโ src/ # Core Source Code
โ โโโ agents/ # Multi-Agent Definitions (DataSync, Quant, Decision, Risk)
โ โโโ api/ # Binance API Client
โ โโโ data/ # Data Processing (processor, validator)
โ โโโ execution/ # Order Execution Engine
โ โโโ features/ # Feature Engineering
โ โโโ monitoring/ # Monitoring & Logging
โ โโโ risk/ # Risk Management
โ โโโ strategy/ # LLM Decision Engine
โ โโโ utils/ # Utilities (DataSaver, TradeLogger, etc.)
โ
โโโ docs/ # Documentation
โ โโโ data_flow_analysis.md # Data Flow Analysis
โ โโโ *.png # Architecture & Flow Diagrams
โ
โโโ data/ # Structured Data Storage (Archived by Date)
โ โโโ market_data/ # Raw K-Line Data
โ โโโ indicators/ # Technical Indicators
โ โโโ features/ # Feature Snapshots
โ โโโ decisions/ # Final Decision Results
โ โโโ execution/ # Execution Records
โ
โโโ logs/ # System Runtime Logs
โโโ tests/ # Unit Tests
โโโ config/ # Configuration Files
โ
โโโ main.py # Main Entry Point (Multi-Agent Loop)
โโโ config.yaml # Trading Parameters
โโโ .env # API Key Configuration
โโโ requirements.txt # Python Dependencies
-
๐ต๏ธ DataSyncAgent (The Oracle)
- Role: Unified Data Provider.
- Action: Asynchronously fetches and aligns multi-timeframe K-lines (5m, 15m, 1h) and external quant data (Netflow, LSR) to ensure a consistent market snapshot.
-
๐จโ๐ฌ QuantAnalystAgent (The Strategist)
- Role: Signal Generator (Technical Analysis).
- Composition:
TrendSubAgent: Analyzes EMA/MACD across timeframes.OscillatorSubAgent: Detects reversal zones using RSI/Bollinger Bands.SentimentSubAgent: Incorporates external data like Funding Rates and Open Interest.
- Output: A raw comprehensive score and detailed sub-signal breakdown.
-
๐ฎ PredictAgent (The Prophet)
- Role: Future Predictor (ML Model).
- Action:
- Uses LightGBM machine learning model trained on historical data.
- Analyzes 50+ technical features to predict price direction for the next 30 minutes.
- Supports auto-retraining (every 2h) to adapt to changing market conditions.
- Output: Probability of price increase (P_Up) and confidence score.
-
โ๏ธ DecisionCoreAgent (The Critic)
- Role: Adversarial Judge.
- Action:
- Contextualization: Uses
RegimeDetectorto identify market state (Trending/Choppy) andPositionAnalyzerto locate price relative to history. - Integration: Combines Strategist's technical signals with Prophet's ML predictions.
- Weighted Voting: Re-evaluates granular signals with dynamic weights adapted to the current regime.
- Output: The final trading intent (Long/Short/Wait) with a confidence score.
- Contextualization: Uses
-
๐ก๏ธ RiskAuditAgent (The Guardian)
- Role: Risk Controller.
- Action: Physically independent audit layer. Checks Max Drawdown protection, R/R requirements, and exposure limits. Has Veto Power to block high-risk trades regardless of high confidence.
-
๐ ExecutionEngine
- Role: Sniper.
- Action: Precision execution within the closing seconds of the candle, handling order lifecycle and state updates.
Architecture Details:
- Data Collection Layer (Blue): DataSyncAgent async concurrent collection
- Quant Analysis Layer (Green): QuantAnalystAgent with 3 parallel Sub-Agents
- Prediction Layer (Magenta): PredictAgent with LightGBM ML model
- Decision Adversarial Layer (Orange): DecisionCoreAgent with regime-aware weighted voting
- Risk Audit Layer (Red): RiskAuditAgent final check and auto-correction
- Execution Layer (Purple): ExecutionEngine order execution
- Visualization Layer: Recent Decisions table showing full Agent data (16 columns)
graph TB
subgraph "1๏ธโฃ Data Collection Layer"
A[๐ต๏ธ DataSyncAgent] --> MS[MarketSnapshot<br/>5m/15m/1h + External Data]
end
subgraph "2๏ธโฃ Quant Analysis Layer"
MS --> QA[๐จโ๐ฌ QuantAnalystAgent]
QA --> TS[TrendSubAgent]
QA --> OS[OscillatorSubAgent]
QA --> SS[SentimentSubAgent]
TS & OS & SS --> QR[quant_analysis]
end
subgraph "3๏ธโฃ Prediction Layer"
MS --> PA[๐ฎ PredictAgent]
PA --> ML[LightGBM Model<br/>Auto-Train 2h]
ML --> PR[Prediction<br/>P_Up, Conf]
end
subgraph "4๏ธโฃ Decision Adversarial Layer"
QR & PR --> DC[โ๏ธ DecisionCoreAgent<br/>Weighted Voting]
DC --> RD[RegimeDetector]
DC --> POS[PositionAnalyzer]
RD & POS --> VR[VoteResult<br/>Action, Conf]
end
subgraph "5๏ธโฃ Risk Audit Layer"
VR --> RA[๐ก๏ธ RiskAuditAgent<br/>Veto Power]
RA --> AR[AuditResult<br/>Risk, Guard]
end
subgraph "6๏ธโฃ Execution Layer"
AR --> EE[๐ ExecutionEngine]
end
style A fill:#4A90E2,color:#fff
style QA fill:#7ED321,color:#fff
style PA fill:#BD10E0,color:#fff
style DC fill:#F5A623,color:#fff
style RA fill:#D0021B,color:#fff
style EE fill:#9013FE,color:#fff
๐ Detailed Docs: See Data Flow Analysis for complete mechanisms.
The system automatically records intermediate processes for each cycle in the data/ directory, organized by date for easy review and debugging:
data/
โโโ market_data/ # Raw Multi-Timeframe K-Lines
โ โโโ {date}/
โ โโโ BTCUSDT_5m_{timestamp}.json
โ โโโ BTCUSDT_5m_{timestamp}.csv
โ โโโ BTCUSDT_5m_{timestamp}.parquet
โ โโโ BTCUSDT_15m_{timestamp}.json
โ โโโ BTCUSDT_1h_{timestamp}.json
โ
โโโ indicators/ # Full Technical Indicators DataFrames
โ โโโ {date}/
โ โโโ BTCUSDT_5m_{snapshot_id}.parquet
โ โโโ BTCUSDT_15m_{snapshot_id}.parquet
โ โโโ BTCUSDT_1h_{snapshot_id}.parquet
โ
โโโ features/ # Feature Snapshots
โ โโโ {date}/
โ โโโ BTCUSDT_5m_{snapshot_id}_v1.parquet
โ โโโ BTCUSDT_15m_{snapshot_id}_v1.parquet
โ โโโ BTCUSDT_1h_{snapshot_id}_v1.parquet
โ
โโโ context/ # Quant Analysis Summary
โ โโโ {date}/
โ โโโ BTCUSDT_quant_analysis_{snapshot_id}.json
โ
โโโ llm_logs/ # LLM Input Context & Voting Process
โ โโโ {date}/
โ โโโ BTCUSDT_{snapshot_id}.md
โ
โโโ decisions/ # Final Weighted Vote Results
โ โโโ {date}/
โ โโโ BTCUSDT_{snapshot_id}.json
โ
โโโ execution/ # Execution Tracking
โโโ {date}/
โโโ BTCUSDT_{timestamp}.json
- JSON: Human-readable, used for configuration and decision results
- CSV: High compatibility, easy for Excel import
- Parquet: Efficient compression, used for large-scale time-series data
- API Keys: Keep them safe, DO NOT commit to version control.
- Test First: Use
--testargument to run simulations first. - Risk Control: Set reasonable stop-loss and position limits in
config.yaml. - Minimal Permissions: Grant only necessary Futures Trading permissions to API keys.
- Monitoring: Regularly check the
logs/directory for anomalies.
| Document | Description |
|---|---|
| README.md | Project Overview & Quick Start |
| Data Flow Analysis | Complete Data Flow Mechanisms |
| API Key Guide | API Key Configuration Guide |
| Config Example | Trading Parameters Template |
| Env Example | Environment Variables Template |
2025-12-23:
- โ Trade History Enhanced: Added Open/Close Cycle columns, PnL % with color indicators.
- โ Net Value Curve: Dashed initial capital baseline with centered Y-axis logic.
- โ Decision Table Refactor: Removed Active PnL column, added tooltip for Guardian block reasons.
- โ
Strategy Improvements: Added
add_positionaction for "buy the dip", confidence calibration rules. - โ Documentation: Translated dashboard agent descriptions to English.
2025-12-21:
- โ
ML Model Upgrade: Upgraded
PredictAgentto use LightGBM machine learning model. - โ Auto-Training: Implemented automatic model retraining every 2 hours to adapt to market drifts.
- โ Dashboard Refinement: Enhanced dashboard with auto-scrolling logs, robust scrollbars, and ML probability display.
- โ Cycle Optimization: Optimized decision cycle to 3 minutes for faster response.
2025-12-20:
- โ
Adversarial Decision Framework: Introduced
PositionAnalyzerandRegimeDetector. - โ Confidence Score Refactor: Implemented dynamic confidence penalties.
- โ Documentation Optimization: Updated README to highlight adversarial architecture.
- โ
Project Renamed: Officially renamed to
LLM-TradeBot. - โ Full-Link Auditing: Implemented complete intermediate state archiving.
Issues and Pull Requests are welcome!
This project is licensed under the GNU Affero General Public License v3.0. See the LICENSE file for details.
Empowered by AI, Focused on Precision, Starting a New Era of Intelligent Quant! ๐





