Back to Projects

Crypto Swing Trading Bot

LLM-Assisted, Fully Deterministic BTC/ETH Trading on Binance

Role

Solo Developer

Timeline

2026

Status

Paper trading (live-gated)

Languages
TypeScript Python
Tools & Frameworks
Docker OpenClaw MCP Binance API LM Studio
Concepts
Deterministic Strategy Risk Management Regime Detection Backtesting

TL;DR — Built to Win in Trends, Lose Small Everywhere Else

A swing trading bot for BTC and ETH whose trading decisions are 100% deterministic TypeScript — the LLM only routes Telegram commands, never picks trades. Backtested across 10 historical market regimes, it profits in clean trends (+6.52% over the last 6 months, +3.34% shorting an ETF-outflow downtrend) and bleeds slowly in chop and crashes — while max drawdown never exceeds ~5%, even through the FTX collapse and the Oct-2025 flash crash. Paper-only by design until graduation gates pass.

  NET P&L BY SCENARIO  (backtest replay of one deterministic engine)

  6-Month Window      ████████████████████  +6.52%   ◀ flagship trend run
  ETF Outflow (short) ██████████             +3.34%
  Carry Unwind        █████                  +1.81%
  Early 2024 Bull     ███                    +0.97%
  Failed Breakout     ██                     +0.65%
                    ──┼──────────────────────────────  0%
  Post-Crash Range   ▕█                      -0.51%
  FTX Catastrophe    █▏                      -0.93%   ◀ worst tail in crypto
  Mid-2023 Chop     ██▏                      -1.79%
  Flash Crash 2025  ███                      -2.31%
  12-Month Window  ████▏                     -4.21%   ◀ honest worst case

The Problem

Most "AI trading bots" hand the trading decision to an LLM — which makes them non-reproducible, hard to audit, and prone to hallucinated reasoning at the worst possible moment. Crypto is also brutally regime-dependent: a strategy that prints money in a bull run can quietly give it all back in six months of chop. The goal was a bot that is fully auditable, behaves identically on the same inputs, and — above all — preserves capital when the market turns against it.

The Approach — LLM at the Edge, Math at the Core

The LLM is pushed to the very edge of the system. Every trading decision is deterministic TypeScript, fully logged to append-only JSONL.

  ┌──────────────┐   /run, /status     ┌───────────────────────────┐
  │   Telegram   │────────────────────▶│  LLM (OpenClaw + LM Studio)│
  └──────────────┘                     │  ONLY routes the command   │
                                       └─────────────┬─────────────┘
                                          run_pipeline (called once)
                                                     ▼
  ┌──────────────────────────────────────────────────────────────────┐
  │  DETERMINISTIC TYPESCRIPT PIPELINE  (one 4H cycle)                │
  │                                                                  │
  │  1. Manage open positions  ─ stops, partial TP, trailing runner  │
  │  2. Safety brakes          ─ circuit breaker, cooldowns, heat cap │
  │  3. Build signals          ─ trend, ATR, CVD, OI, funding, F&G    │
  │  4. analyzeSignal()        ─ long / short / no_trade             │
  │  5. Regime + family router ─ block chase, downsize chop          │
  │  6. applyRisk()            ─ size so a full stop ≈ 0.5% of equity │
  │  7. Paper execute          ─ positions.json + trade_log.jsonl     │
  └──────────────────────────────────────────────────────────────────┘
  • Defensive risk model: every trade is sized so a full stop-out loses only ~0.5% of capital, with a minimum 2:1 reward-to-risk and a portfolio heat cap.
  • Regime-aware gating: a market-mode router classifies bull / bear / range / stress and blocks counter-trend trades and over-extended chases — the engine refuses to overtrade sideways tape.
  • Trailing runner: takes 50% profit early, then trails the rest with a volatility-scaled Chandelier stop to let winners run while locking in gains.
  • Fully auditable: every signal value, rejection reason, and trade is written to append-only JSONL — nothing is hidden inside the model.

Results — Regime-Dependent, Not a Money Printer

Each scenario replays the same engine over a different historical regime, generated from committed backtest data:

  Scenario              Window            Trades  Net P&L  Win%  Max DD
  ──────────────────────────────────────────────────────────────────────
  6-Month Window        2025-11 → 2026-05   26    +6.52%   54%   4.55%
  ETF Outflow Downtrend 2025-12 → 2026-02   13    +3.34%   62%   1.98%
  Carry Unwind          2024-07 → 2024-08    3    +1.81%   67%   0.58%
  Early 2024 Bull       2024-01 → 2024-06   12    +0.97%   50%   3.82%
  Failed Breakout       2026-04 → 2026-05    1    +0.65%  100%   0.01%
  Post-Crash Range      2026-02 → 2026-04   13    -0.51%   46%   2.89%
  FTX Catastrophe       2022-10 → 2022-12    3    -0.93%   33%   2.03%
  Mid-2023 Chop         2023-04 → 2023-09    2    -1.79%    0%   1.79%
  Flash Crash 2025      2025-09 → 2025-10    5    -2.31%   20%   2.45%
  12-Month Window       2025-05 → 2026-05   14    -4.21%   29%   5.00%
  • Capital preservation holds: max drawdown stayed under ~5% in every single window — including the FTX implosion and the Oct-2025 liquidation cascade.
  • The edge is directional: profitable both long (6-Month +6.52%) and short (ETF Outflow +3.34%) when trend structure is clean.
  • The honest worst case is the full 12-Month mixed-regime window at -4.21% — proof the edge is regime-dependent, and the reason the bot stays in paper mode.
  • The chop tax: in directionless markets it takes few trades and loses small (Mid-2023 Chop -1.79% on just 2 trades) rather than churning capital.

Philosophy: missing a large winner is acceptable if the alternative is clustered losses or oversized drawdown.