Smart Crypto Trader: AI-assisted trading platform

Self-hosted crypto trading. TA strategies produce signals, Claude approves or rejects each one and manages open positions, and orders go to real exchanges or a paper simulator. Built with Claude Code, running in production on Docker.

Solo Developer (built with Claude Code) · 2026 · Fintech / Algorithmic Trading

Tech: TypeScript, Next.js 14, Node.js, Claude Agent SDK, Prisma, PostgreSQL, Redis, NSQ, ccxt, NextAuth, Turborepo, Docker, Tailwind CSS, Vitest

The problem

Retail traders can't watch the market 24/7. Pure technical-analysis bots are noisy and fire false signals, and handing everything to an LLM is non-deterministic and expensive. I wanted deterministic TA signals plus an AI second opinion that checks entries and manages exits.

The approach

A Turborepo monorepo with a Next.js web app, a background worker and shared packages (Prisma DB, ccxt exchange adapters, types). Strategies publish signals to NSQ, Claude approves or rejects each one with a confidence score and reasoning, approved trades go through one exchange adapter, and a monitor loop keeps re-checking open positions.

The architecture

Services talk over NSQ, with Postgres for state and Redis for caching. A pool of Claude Agent SDK instances sits behind a router that points one instance at signal validation and the rest at trade monitoring.

Outcomes

  • Self-hosted and running in production on Docker
  • TA signals plus AI decisions, with every AI call stored along with its tokens and cost
  • 8 technical strategies, each with unit tests
  • Paper-trading mode uses the same execution path as live trading, so changes can be tried with no money at risk

How it works

Smart Crypto Trader is a self-hosted, automated crypto trading platform with an AI advisor. Technical-analysis strategies scan the market and emit trade signals. Claude checks each signal and returns a confidence score with its reasoning, then keeps re-assessing open positions and decides whether to hold, partially close or exit. Approved trades execute on real exchanges through one adapter, or against a built-in paper-trading simulator.

I wrote the platform with Claude Code, and at runtime it uses the Claude Agent SDK as its trading advisor. So the same AI that wrote the code also makes the calls inside it. It's 100% self-hosted on Docker and running in production.

Why a hybrid

Algorithmic crypto trading tends to fail in one of two ways:

  • Pure technical-analysis bots are deterministic and cheap to run, but noisy. They fire on every indicator crossover and pile up false signals in choppy markets.
  • Pure-LLM trading can reason about context, but it's non-deterministic, slow and expensive if it has to do everything.

So I split the work. Fast, testable TA strategies find candidate setups, and the AI acts as a strict second opinion that filters noise and manages risk on live positions. Every decision is logged and costed.

Goals:

  • Scan many pairs across several strategies and timeframes, continuously.
  • Only act on signals the AI approves, with a confidence score and reasoning.
  • Manage open trades actively (hold, partial close, close) instead of relying on fixed TP/SL.
  • Support spot, futures and margin, multiple exchanges, and a safe paper mode.
  • Per-user accounts, encrypted exchange keys, and a credit system that meters AI cost.

Monorepo and infrastructure

A Turborepo + pnpm monorepo splits the code into deployable apps and shared packages, all in containers behind a reverse proxy.

flowchart TB
  subgraph Apps
    WEB[apps/web<br/>Next.js 14 + NextAuth]
    WORKER[apps/worker<br/>signals - AI - execution]
  end
  subgraph Packages
    DB[packages/db<br/>Prisma schema]
    EX[packages/exchange<br/>ccxt adapters]
    TY[packages/types]
  end
  subgraph Infra
    PG[(PostgreSQL)]
    RD[(Redis)]
    NSQ[NSQ message queue]
    NPM[Nginx Proxy Manager]
  end
  EXCH[Exchanges<br/>Binance / CoinEx / Paper]

  NPM --> WEB
  WEB --> DB
  WORKER --> DB
  WORKER --> RD
  WORKER <--> NSQ
  WORKER --> EX
  EX --> EXCH
  WEB --> EX

The trading pipeline

Each stage is its own service and they talk over NSQ, so signal detection, AI validation, execution and monitoring scale and fail independently.

sequenceDiagram
  participant SC as Signal Scanner (cron)
  participant ST as Strategy Engine
  participant Q as NSQ
  participant AI as AI Validator (Claude)
  participant EX as Trade Executor
  participant XCH as Exchange (ccxt)
  participant MON as Trade Monitor (Claude)

  SC->>ST: Fetch OHLCV, run strategies
  ST-->>SC: Candidate signal (direction, strength)
  SC->>Q: publish signal.detected
  Q->>AI: consume signal.detected
  AI->>AI: validateSignal -> approved? confidence + TP/SL
  alt approved
    AI->>Q: publish signal.validated
    Q->>EX: consume signal.validated
    EX->>XCH: Place order
    XCH-->>EX: Order id / fill
  else rejected
    AI-->>Q: mark signal REJECTED (reasoning stored)
  end
  loop every monitor interval
    MON->>XCH: Read current price / PnL
    MON->>MON: assessTrade -> HOLD / PARTIAL_CLOSE / CLOSE
    MON->>XCH: Close or reduce when warranted
  end

A pool of Claude instances

The worker starts N Claude Agent SDK server instances and routes work through a dynamic pool. Instance 0 leans toward signal validation, which is time-sensitive. The others lean toward trade monitoring. Idle instances pick up overflow from the other workload, and requests carry priorities so a one-off signal never waits behind the steady stream of monitoring calls.

flowchart LR
  REQ[Validation / Assessment request]
  ROUTER{Dynamic Pool Router<br/>least-loaded + preference bias}
  S0[Claude SDK #0<br/>prefers signals]
  S1[Claude SDK #1<br/>prefers monitoring]
  S2[Claude SDK #2<br/>prefers monitoring]

  REQ --> ROUTER
  ROUTER -->|signal, priority 10| S0
  ROUTER -->|trade assess| S1
  ROUTER -->|overflow when busy| S2

There are two advisor backends behind a common AIAdvisor interface: the local Claude Agent SDK (the default) and the hosted Anthropic SDK. Switching provider is a config change, and the pipeline doesn't need to know.

Strategies

Eight independent strategies implement a common interface and register themselves in a registry. Each has its own unit tests, and the shared indicator math (RSI, MACD, EMA, ADX, Bollinger, Stochastic, VWAP, Ichimoku, volume) lives in a tested indicators utility.

flowchart TB
  REG[Strategy Registry]
  REG --> A[RSI + MACD]
  REG --> B[EMA Crossover]
  REG --> C[Bollinger Bands]
  REG --> D[Stochastic RSI]
  REG --> E[ADX / DI Trend]
  REG --> F[Ichimoku Cloud]
  REG --> G[VWAP Deviation]
  REG --> H[Volume Momentum]

Core data model

erDiagram
  User ||--o{ UserExchangeCredentials : owns
  User ||--o{ Trade : places
  User ||--o{ CreditTransaction : has
  User ||--o{ AIConsultation : incurs
  CryptoPair ||--o{ Signal : produces
  Strategy ||--o{ Signal : generates
  Signal ||--o{ Trade : triggers
  Trade ||--o{ TradeMonitorEvent : logs
  Signal ||--o{ AIConsultation : justifies

  User { string email Float credits Role role }
  UserExchangeCredentials { string apiKey_encrypted string apiSecret_encrypted }
  Signal { SignalDirection direction Float strength Float confidence SignalStatus status }
  Trade { TradeType tradeType Float entryPrice Float targetTP Float targetSL Float pnl }
  AIConsultation { int inputTokens int outputTokens Float costUsd Float creditsDeducted }

Trade states

stateDiagram-v2
  [*] --> PENDING: signal detected
  PENDING --> VALIDATED: AI approves
  PENDING --> REJECTED: AI rejects
  VALIDATED --> OPEN: order filled
  OPEN --> OPEN: monitor -> HOLD
  OPEN --> OPEN: monitor -> PARTIAL_CLOSE
  OPEN --> CLOSED: TP / SL / AI CLOSE / max-age
  REJECTED --> [*]
  CLOSED --> [*]

Keys, AI cost and paper trading

  • Exchange API keys and secrets are stored AES-256-GCM encrypted and only decrypted in memory at execution time.
  • Every Claude call is saved as an AIConsultation with input and output tokens, USD cost and credits deducted. AI spend is auditable per user and enforced through a credit ledger.
  • A paper-trading adapter follows the live execution path, so strategies and AI behaviour can be tested with no money at risk.

Deployment

The whole stack is one docker compose file: Postgres, Redis, NSQ (lookupd + nsqd), the web app, the worker, and Nginx Proxy Manager for TLS. The worker mounts the host's ~/.claude config so the Claude Agent SDK runs locally as the trading brain. A setup-vps.sh script provisions a fresh VPS, and Prisma migrations run as a one-shot container on boot.

Results

  • A complete trading platform, self-hosted and running in production.
  • TA signals plus AI decisions, with a full audit trail for every AI call.
  • 8 strategies, each unit-tested, plus a tested indicator library.
  • Paper trading that matches the live path, and a credit system that keeps AI cost visible and capped.