Skip to content

Autonomous Crypto Trading Bot

I wanted a trading bot that runs with real money, fully autonomous — no manual approval per trade. But “autonomous” and “real money” is a dangerous combination. Most trading bots are either too dumb (rigid rules, no adaptation) or too opaque (black-box ML models you can’t inspect). I wanted something in between: simple strategies with hard safety guardrails, and a learning system that improves over time by analyzing its own mistakes in plain language.

Crypto trading bot architecture

Telegram to OpenClaw trading bot

The bot runs as an OpenClaw skill on a self-hosted Hetzner VPS inside Docker. A cron job triggers it every 5 minutes. It reads its config, checks the market via CCXT (connected to Coinbase), evaluates whether to trade, enforces safety limits, and logs everything.

Three strategies, one active at a time

  • Momentum (RSI + Moving Averages) — buy when RSI drops below 30 (oversold), sell when it rises above 70 (overbought), confirmed by moving average crossover. RSI period 14, short MA 10, long MA 50.
  • Grid Trading — place buy/sell orders at regular price intervals (5 levels, 1% spacing). Profits from price oscillating within a range. Best suited for low-priced coins like DOGE or XRP.
  • Dollar-Cost Averaging (DCA) — buy a fixed dollar amount daily regardless of price. Currently active: $5/day split 50/50 between BTC and ETH.

Strategy is selected in config.json and can be changed without redeploying.

Hard safety limits — no exceptions

These are checked before every single trade and cannot be overridden by strategy logic:

Limit Value
Minimum cash reserve $10 USD always held back
Max single order $20
Max position in one coin 50% of portfolio (20% for altcoins)
Daily loss limit 5% of portfolio → halt until tomorrow
Stop loss -10% from entry → immediate sell
Halt mechanism Sets halted: true in state, cancels all open orders, requires manual resume

The design principle is fail closed — if anything unexpected happens (API error, bad data, timeout), the bot stops trading and logs the issue. It never places an order when uncertain.

Adaptive learning system

This is the part that makes it more than a simple rule-based bot. Three components work together:

  1. Trade journal (journal.jsonl) — every closed trade gets a structured entry: entry/exit price, P&L, strategy, signal reason, market conditions at the time, and a lesson field — a plain-language analysis of why the trade lost (or won).

  2. Lessons file (lessons.md) — a curated, running list of rules derived from losing trades. Before every trade, the bot reads this file and checks whether current market conditions match any past losing pattern. If there’s a match, the trade is skipped and the skip is logged.

  3. Periodic review — every 7 days or 20 trades (whichever comes first), the bot reviews the full journal, looks for recurring loss patterns (same time of day, same coin, same market condition), updates lessons.md with new rules, and writes a summary to reviews/.

The goal is a bot that gets better over time. A strategy that loses money in month 1 but learns and adapts is more valuable than one that’s static.

Example lessons the system is designed to capture:

  • “Don’t buy oversold dips during broad selloffs — RSI is low because everything is dumping, not because the coin is undervalued”
  • “Grid bot fails in trending markets — price breaks the range and you accumulate a losing position at every level”
  • “Low volume = wide spreads = bad fills — use limit orders during weekends”
  • Bot runs fully autonomously on Coinbase with real money ($100 budget)
  • Currently trading BTC/USD and ETH/USD via DCA strategy
  • 5-minute execution cycle via OpenClaw cron, running on a Hetzner VPS in Docker
  • All trades, signals, errors, and risk checks logged to structured JSON
  • Safety halt system tested and functional — the bot stops itself and waits for manual intervention when something is wrong
  • Strategy switchable via config without redeployment