How to Build an AI Trading Bot: Complete Architecture Guide
Data layer, LLM decision engine, critic agent, risk management, infrastructure. Complete guide with real code and lessons from 21 days of live paper trading.
What you'll build: A 24/7 autonomous trading bot with LLM decision-making, adversarial risk review, and hard-coded safety controls. We've been running this architecture in paper mode for 21 days. Here's every component.
The Architecture (Overview)
Our trading bot has 5 layers. Each layer is independent — you can swap components without breaking the whole system.
1. Data Layer
12+ APIs (crypto, Polymarket, sentiment, on-chain)
2. Strategy Layer
9 independent strategies (mean reversion, momentum, RSI, etc.)
3. Decision Layer
LLM (Qwen/GPT) + critic agent validation
4. Risk Layer
12 hard-coded rules (position limits, circuit breakers, cooldowns)
5. Execution Layer
Paper trading engine → live (gated after 90 days)
Let's build each layer.
Layer 1: Data Layer
The data layer polls market data from multiple sources. We use 12+ APIs across 4 categories:
Price Data
- • Binance API (BTC, ETH, SOL spot + futures)
- • Coinbase Pro API (backup price source)
- • Polymarket API (prediction market odds)
Sentiment Data
- • Twitter API v2 (crypto influencer sentiment)
- • CryptoPanic API (news aggregation)
- • LunarCrush API (social volume metrics)
On-Chain Data
- • Etherscan API (whale movements, large transfers)
- • Glassnode API (exchange flows, holder metrics)
Market Regime
- • Fear & Greed Index API
- • TradingView technical analysis (via scraping)
- • Polymarket event probabilities (macro risk)
Key implementation detail: Rate limit management is critical. Each API has different limits. We use a priority queue:
1. Price data (highest priority)
2. Regime data
3. Sentiment data
4. On-chain data (lowest priority)
Poll interval: every 15 minutes. Fast enough to catch opportunities, slow enough to stay within rate limits. Each of these automated polling loops is an autonomous AI agent consuming live web data — exactly the kind of autonomous traffic reshaping how the internet works.
Layer 2: Strategy Layer
Each strategy runs independently and generates signals with confidence scores. We run 9 strategies:
Each strategy outputs a signal object:
{ strategy: "mean_reversion", asset: "BTC-USD", action: "BUY", confidence: 0.82, entry_price: 68420, stop_loss: 67200, take_profit: 71000, reasoning: "RSI < 30, price below lower BB" }
Layer 3: Decision Layer (LLM + Critic)
This is where AI comes in. The LLM reviews every signal before it executes.
Step 1: Primary LLM Review
We send the signal to an LLM (Qwen3.5-plus or GPT) with this prompt:
"You are reviewing a trading signal. Context: Strategy is [strategy_name], Asset is [asset], Signal is [action]. Technical indicators: [indicators]. Market regime: [regime]. Recent P&L: [recent_pnl]. Task: 1. Identify contradictions. 2. Assess confidence (0-100%). 3. Recommend: Execute, Queue for Review, or Reject. Reasoning first. Decision second."
The LLM returns a confidence score and recommendation. If confidence is >85%, the trade auto-executes. If 65-84%, it queues for human review. If <65%, it's rejected.
Step 2: Critic Agent Validation
Here's where we're different. After the primary LLM approves a trade, a second LLM (the critic) reviews it adversarially.
The critic can return 5 verdicts:
Trade proceeds
Proceed but flag for post-trade watch
Suggests smaller size or tighter stop
Blocks trade entirely
Sends to human review
The critic vetoes ~18% of trades. Common reasons: trend disagreement, consecutive loss escalation, OI squeeze risk, cluster detection.
Layer 4: Risk Layer
Even if the LLM and critic approve a trade, the risk layer can still veto it. We have 12 hard-coded rules:
Position Limits:
- • Max 5% per trade
- • Max 7% total exposure per asset
- • Max 10% crypto exposure
Circuit Breakers:
- • Pause after 3 consecutive losses
- • Halt after 4% daily drawdown
Trading Limits:
- • 45-minute cooldown per asset
- • 65% min LLM confidence
- • 85%+ for auto-execute
Market Conditions:
- • Regime-based strategy suspension
- • OI squeeze veto (score ≥ 80)
- • Polymarket min $10K volume
- • Ambiguous resolution veto
These rules can't be overridden. No config flags. No "just this once" exceptions.
Layer 5: Execution Layer
If a trade passes all 4 previous layers, it reaches execution. We have two modes:
Paper Mode (Current)
Trades are logged but not sent to the exchange. We model slippage realistically:
• 0.1% slippage on major pairs (BTC, ETH)
• 0.3% on mid-cap alts
• 0.5-2% on thin Polymarket order books
Live Mode (After 90 Days)
Same execution logic, but orders go to the exchange. We're not live yet — we're waiting until we complete 90 days of paper trading with positive Sharpe and <10% drawdown.
Infrastructure (How It Runs 24/7)
We don't use AWS or cloud infrastructure. Here's what we use:
- WSL2: Windows Subsystem for Linux (runs Ubuntu inside Windows)
- tmux: Terminal multiplexer (keeps processes running after you disconnect)
- Python 3.11: Async polling every 15 minutes
- Telegram Bot: All alerts and control commands
- Next.js: Dashboard for viewing equity curves and analytics
Total cost: ~$20/month (electricity + LLM API calls). Compare that to ~$175/month for equivalent cloud infrastructure. This is the coffee-budget infrastructure philosophy in practice — production AI systems running on pocket change.
That kind of leverage is the whole idea behind AI automation for founders: small teams running production systems at infrastructure costs that would have required a headcount budget five years ago. The full operator stack shows how we stitch trading, content, and monitoring into one governance layer.
What We'd Do Differently
Building this from scratch, here's what we'd change:
- Start with paper trading: Don't go live until you've tested for 30+ days. We're doing 90.
- Code risk rules first: Before any strategies, code the circuit breakers and position limits. Survival first.
- Use Telegram for alerts: Dashboards are passive. Telegram pushes alerts to you.
- Log everything: Every decision, every veto, every bug. You'll need this data to debug.
- Build the critic early: The adversarial LLM layer catches mistakes the primary LLM misses.
The Results (21 Days In)
90-Day Challenge — Week 3 Summary
21
Days Elapsed
+$244.40
Cumulative P&L
60%
Win Rate
-0.9%
Max Drawdown
Paper trading only. Not indicative of future performance.
Is +$244 impressive? No. It's 2.44% in 21 days on simulated capital.
What's impressive: zero days of downtime, cluster detection blocked a correlated loss (~$50 saved), regime classifier worked on first real test, every decision logged and published.
Next Steps
If you're building your own trading bot, here's a suggested order:
- Set up data layer (start with 2-3 APIs, expand later)
- Code 1-2 simple strategies (mean reversion, momentum)
- Implement risk layer (position limits, circuit breakers)
- Add LLM decision layer (start with simple prompts)
- Build critic agent (adversarial review)
- Run in paper mode for 30+ days
- Iterate based on bugs and edge cases
- Consider live mode only after proven track record
We're at step 7. Step 8 is 69 days away.
Follow the 90-Day Challenge
This architecture runs our entire 90-day challenge — 9 strategies, 12+ APIs, LLM + critic decision layer, 12 hard-coded risk rules. Every Monday: new transparency report with full trade history.