How I Built an AI Crypto Trading Bot with Claude AI

How I Built an AI Crypto Trading Bot with Claude AI
This is the definitive guide to how an AI crypto trading bot built on Claude (Anthropic) actually works — the architecture, the design decisions, and the honest results — so you don’t have to piece it together from a dozen scattered tabs. It’s a real, running system: a multi-agent Claude pipeline for decisions, a machine-learning ensemble for a second opinion, layered risk controls, and a full Next.js dashboard. It trades BTC and ETH on Binance, is controlled from Telegram, and is open source on GitHub.
Part 1 of a 3-part series. This post covers the architecture. Part 2 is a full deploy-to-your-VPS walkthrough, and Part 3 is about contributing. If it’s useful, a ⭐ on the repo genuinely helps.
One honest note up front: this is a research and educational project, currently running in paper-trading (Binance testnet). It is not a get-rich-quick bot and nothing here is financial advice. I’ll show you exactly what my backtests reveal later in the post — the engineering is solid, but “does it print money” is still an open question.
What Is an AI Crypto Trading Bot?
An AI crypto trading bot is software that analyses the market and places trades automatically, using artificial intelligence to make the decisions a human trader normally would. The interesting question isn’t “can it place orders” — that’s trivial — it’s “can a large language model reason through a live, messy, adversarial market and act sensibly.” Crypto is about as messy and adversarial as markets get, which is exactly why it’s a good test.
Rather than one giant “should I buy?” prompt, this bot orchestrates several specialised components: three Claude agents, a quant ML model, and a strict risk-management layer that has the final say before any money moves. Here’s how they fit together.
How the AI Trading Bot Works: The 4-Hour Cycle
The simplest way to understand the system is to follow one cycle. Every four hours — and immediately if a flash crash is detected — the bot runs this loop:
Market data ─┐
News/social ─┼─▶ 3 Claude agents ─┐
On-chain ────┤ (Market · Sentiment · Decision)
Derivatives ─┘ ├─▶ Decision ─▶ Risk sizing ─▶ Binance
Historical ──────▶ ML ensemble ──────┘ │
└─▶ MySQL ─▶ Dashboard + TelegramIn words, each cycle:
- Gathers the market state — 20+ technical indicators, derivatives data (funding rate, open interest, long/short ratio), the Fear & Greed index, and multi-timeframe trend agreement.
- Grades its last decision against what the market actually did, and turns mistakes into one-line lessons.
- Checks a set of safety circuit breakers that can pause trading or shrink positions.
- Asks three specialised Claude agents what to do.
- Gets a second opinion from an ML model trained on thousands of historical candles.
- Sizes the trade with risk-managed position sizing and executes on Binance with a protective stop-loss (after Telegram approval, in live mode).
- Logs everything — every prompt, response, and number — to a database that feeds the dashboard and a Telegram message.
The Multi-Agent Claude Pipeline
The obvious way to use an LLM for trading is one mega-prompt: “here’s everything, tell me buy/sell/hold.” It works, but the reasoning gets shallow — the model tries to hold every consideration at once. So the bot runs three specialised Claude agents instead:
- Market Analyst — sees only the chart and the numbers: RSI, MACD, Bollinger Bands, ATR, VWAP, Ichimoku, funding rate, open interest, multi-timeframe regime. A pure technical read.
- Sentiment Analyst — sees only the context: news, social sentiment, on-chain flows, options positioning (put/call, max pain), whale transactions, and macro (DXY, S&P, gold, VIX). It runs in parallel with the Market Analyst.
- Decision Maker — sees both assessments, plus the ML prediction, the portfolio, and lessons from past mistakes. It has hard rules baked in (won’t over-allocate, won’t panic-sell an uptrend, defaults to HOLD when signals conflict) and produces the final decision as structured JSON:
{
"action": "buy",
"confidence": 0.72,
"trade_usd": 6.0,
"risk": "medium",
"reason": "RSI deeply oversold + OBV rising divergence + bullish options
positioning create an asymmetric reversal setup; macro is a
headwind but allocation is low, so a small buy is justified.",
"signals": ["rsi_oversold", "obv_divergence", "options_bullish"]
}Splitting the problem this way produces better, more legible decisions — each agent focuses, and the final synthesis weighs two clean expert opinions instead of one blurry one. Every call is logged in full, so the dashboard can show the entire chain of reasoning behind any trade. For the fast 4-hour loop I use Claude Haiku; for heavier reasoning (weekly reviews, deep research, reports) I use Claude Fable 5 with an automatic fallback to Claude Opus 4.8.

The Machine Learning Ensemble: A Quant Second Opinion
The Claude agents make the call, but they don’t get the last word alone. Running alongside them is a classic quant model:
- A stacking ensemble — XGBoost and LightGBM base learners feeding a logistic-regression meta-learner.
- Trained on 5,000+ candles across three timeframes (1h, 4h, 1d), with 60+ engineered features.
- Labelled with the triple-barrier method (target / stop / timeout) from Advances in Financial Machine Learning.
- Validated with purged walk-forward cross-validation — the honest way to test a time-series model, which stops the future leaking into the past.
A Hidden Markov Model also classifies the market into regimes (strong trend, weak trend, range, high volatility, crash) so the strategy can adapt. The Decision agent treats the ML prediction as one more expert at the table — sometimes it agrees, sometimes it overrides. Keeping them separate means neither a hallucinating LLM nor an overfit model can unilaterally move money.
Risk Management Is the Real Product
Here’s something I believe strongly: a 55%-accurate model with good risk management beats a 65%-accurate model with bad sizing. So most of the engineering went here, not into the “AI” headline. The bot uses quarter-Kelly position sizing, ATR-based stops that widen in losing streaks, protective stop-loss orders resting on the exchange, human approval for every live trade via Telegram, and five circuit breakers:
# Circuit-breaker thresholds (config.py)
DAILY_LOSS_HALT_PCT = 0.03 # 3% intraday loss -> pause for the day
DRAWDOWN_REDUCE_PCT = 0.10 # 10% drawdown -> halve position sizes
DRAWDOWN_HALT_PCT = 0.20 # 20% drawdown -> halt all trading
CONSECUTIVE_LOSS_HALT = 5 # 5 losses in a row -> pause
# + an equity moving-average filter that throttles sizing in a downtrendThe philosophy: it should be very hard for the bot to lose a lot quickly, even when the AI is wrong — because sometimes it will be.
Common Mistakes When Building an AI Trading Bot
Things I got wrong so you don’t have to:
- Trusting the LLM’s suggested trade size. The model would suggest a dollar amount that the risk layer then overrode — and for a while the two disagreed silently. Let one component own sizing.
- Ignoring exchange minimums. Binance rejects orders below a $5 minimum notional. Risk-managed sizing quietly produced sub-$5 orders that failed at $0 — roughly half the buy signals were lost before I caught it.
- Measuring “correct/wrong” on too short a window. A ±2% move in 4 hours almost never happens in a range-bound market, so every trade scored “neutral” and the win rate was undefined. Measure decisions by real profit-and-loss over a sensible horizon instead.
- Backtesting without a leakage check. A backtest that looks amazing is usually cheating. Always run a placebo test (below).
The Tech Stack
| Layer | Technology |
|---|---|
| AI | Claude Haiku 4.5 (fast analysis), Claude Fable 5 + Opus 4.8 (deep reasoning) |
| Machine learning | XGBoost + LightGBM stacking ensemble, Optuna tuning, HMM regime detection |
| Trading | Binance Spot API via CCXT, WebSocket for real-time data |
| Backend | Python 3.12 (bot), Laravel + FastAPI (APIs), MySQL 8 |
| Frontend | Next.js 16, React 19, Tailwind CSS |
| Control & infra | Telegram Bot API, Ubuntu VPS, systemd, nginx, PM2 |
Honest Results: What the Backtests Actually Show
This is the section most “I built a trading bot” posts leave out, and it’s the most important. I tested the strategy over 24 months with fees and slippage modelled, plus a placebo/leakage test — feed the model a fake, time-shifted signal; if it still “works,” your harness is cheating. The findings:
- No leakage. Under the placebo, the edge collapses — so the good results come from real signal, not a look-ahead bug. This is the check most backtests fail silently.
- It survives out-of-sample. On data the model never trained on, across multiple market windows, it stayed positive.
- But it’s a defensive, market-neutral scalper. It sidesteps crashes well (up while BTC fell 27%) but underperforms simple buy-and-hold in a bull market, and its absolute returns are small.
In plain terms: it’s a well-engineered platform that protects capital and trades with discipline — but whether it has meaningful, tradeable alpha is still an open research question. I’d rather tell you that than show a cherry-picked equity curve. It’s also exactly where contributions are most valuable.
Conclusion: Get the Code and Build With Me
An AI crypto trading bot is a genuinely fun way to combine LLM reasoning, machine learning, and real-world execution into one system — and building it in the open means the interesting problems (chiefly, “is there real alpha here?”) are shared. The entire project is MIT-licensed on GitHub:
👉 github.com/dineshstack/crypto_bot — ⭐ star it if this was useful.
- Want to deploy your own? That’s Part 2: Deploy an AI Crypto Trading Bot to Your VPS — with a real cost breakdown and every gotcha.
- Want to contribute? See Part 3: How to Contribute and the repo’s CONTRIBUTING.md.

Related posts
- Part 2 — Deploy an AI Crypto Trading Bot to Your Own VPS
- Part 3 — How to Contribute to the Project
Tags: AI Crypto Trading Bot, Claude AI, Machine Learning, Algorithmic Trading, Open Source
Disclaimer: This project is for educational and research purposes only. It is not financial advice and not a solicitation to trade. Cryptocurrency trading carries substantial risk of loss. Never trade with money you can’t afford to lose, and always start on testnet.
Frequently Asked Questions
What is an AI crypto trading bot?
Does the bot make money?
Is it open source?
Senior Full Stack Developer · Building SaaS products & teaching Laravel/React · 10+ years experience · Founder of Orion360 · Based in Dubai, UAE.
Was this post helpful?
Reviews & Ratings
Sign in to leave a review.

