A Rust crypto trading agent with persistent reflection memory and a double-entry audit ledger, built as a spec-driven research platform. Targets paper and (future) live trading on top-10 USDT-quote crypto pairs.
This README is the human entry point. AI agents should start at CLAUDE.md then AGENT.md.
| Dimension | State |
|---|---|
| Mode | Research (paper + backtest). Live trading not yet wired. |
| Workspace | Rust stable, edition 2024 |
| Test gates | 692 lib + 98 integration + 19 UI visual snapshots + 11 layout proptests + 34/34 anchored body-SHAs |
| UI | 14 screens shipped (cockpit_live binary, iced 0.14.0 + vendored iced_tiny_skia patch) |
| Strategies shipped | SMA, composed, cross-sectional momentum, mean-reversion pairs, multi-venue, LLM-as-analyst, LLM-as-forecaster (partial) |
| Strategy research retired | TCN, PatchTST, GARCH (4 retirement chains; see spec/dev-notes/v25-dl-journey-retrospective-2026-05-22.md) |
| Largest unfilled gap | Live order flow (no venue execution path yet). Risk envelope shipped as config caps only. |
For a comprehensive feature-by-feature audit see spec/dev-notes/feature-state-table-2026-05-22.md.
Core proposition. A single-operator trading research stack with two differentiators:
- Persistent reflection memory (
crates/reflection): every shipped strategy decision + outcome is stored as aLessonCardwith a 32-dim deterministic embedding, retrievable by symbol/regime viaretrieve_top_k. - Auditable double-entry ledger (
crates/audit): every fill, fee, slippage, LLM call, and strategy emit is recorded as journal transactions with full body-SHA-256 anchoring for byte-identical regression gates.
Cockpit. A native iced app (cockpit_live) surfaces strategy state, equity curves, drawdowns, positions, audit trail, reflection memory, and an Assistant slot for LLM reasoning traces. 14 screens; sidebar IA.
Spec-driven workflow. Every feature lives in spec/<slug>/ with a brief (feature.md), task breakdown (tasks.md), decomp (decomp.md), and anchored backtest reports under reports/. Multi-agent workflow (analyst → architect → developer → tester → presenter) is documented in AGENT.md.
# Workspace build (debug)
cargo build
# Cockpit (release; needs `live` feature)
cargo build --release -p ui --bin cockpit_live --features live
# Backtest binary (release)
cargo build --release -p backtest --features realdata,candle# 1. Set up local secrets file (git-ignored)
cp config/agent.toml.local.example config/agent.toml.local
# 2. Edit config/agent.toml.local with your real Anthropic/OpenAI/etc keys
# (only needed if running LLM-strategy code paths)
# 3. Toggle config/agent.toml [llm] enabled = true to activate LLM subsystemThe committed config/agent.toml carries the shape; config/agent.toml.local overlays secrets at startup. See config/agent.toml.local.example for the template.
# Canonical interactive run — ALWAYS use a release build.
cargo run -p ui --release --bin cockpit_live --features live
# (or run the prebuilt binary)
./target/release/cockpit_liveRun the cockpit in release. It renders through the CPU
tiny-skiarasterizer (chosen for snapshot-test determinism over GPUwgpu). At the dev defaultopt-level = 0a single Lab/Charts frame takes ~700 ms to rasterize vs ~17 ms in release — a measured 40× debug-tax that shows up as the "1–3 s per interaction" lag. The workspace[profile.dev.package."*"]override (rootCargo.toml) now compiles the rasterization dependencies atopt-level = 3even in dev, so a plaincargo run … --features fixturesis usable too — but--releaseremains the canonical, fastest path. Numbers:crates/ui/tests/render_timing_probe.rs.
Opens the iced window. Default screen is Lab (strategy experimentation). Other screens are reachable via the left sidebar: Live, Compare, Memory, Models, Trail, Strategies, Risk, Audit, Control, Settings, Charts, Home, Debug.
# Synthetic data (always works)
cargo run -p backtest --release -- --scenario top10-2023-fy-momentum --seed 0xC0FFEE
# Real Binance data (requires data/binance/ tree populated + --features realdata)
cargo run -p backtest --release --features realdata,candle --bin backtest -- \
--scenario top10-2023-fy-momentum-realdata --seed 0xC0FFEEBacktest reports land under spec/<feature>/reports/backtest-<stamp>-<scenario>.md with body-SHA-256 anchored for regression.
# All shipped backtest body-SHA-256 anchors
bash scripts/verify_anchors.sh
# Spec structural integrity (dead links, missing frontmatter, etc.)
uv run scripts/spec_lint.py
# Full Rust validation pipeline
cargo fmt --check
cargo clippy --workspace --features candle,realdata -- -D warnings
cargo test --workspace --lib --features candleFull audit: see spec/dev-notes/feature-state-table-2026-05-22.md for all 54 features.
| Feature | Version | Purpose |
|---|---|---|
v0-paper-sma |
0.1.0 | SMA crossover paper baseline |
v05-composed-strategies |
0.5.0 | with_* composition framework |
v1-cross-sectional-momentum |
1.0.0 | Production momentum on top-10 universe; the load-bearing baseline |
v15a-mean-reversion-pairs |
1.1.0 | Pairs trading framework |
v1-5b-multi-venue |
1.2.0 | Multi-venue execution support |
v2-llm-strategy |
2.0.0 | LLM-as-analyst infrastructure (RecordingProvider/ReplayProvider/BudgetedProvider/CachedSystemPromptBuilder) |
v3-llm-forecaster |
0.1.0-PARTIAL | LLM-as-forecaster with reasoning trace; Wave D deferred pending API key |
| Chain | Outcome |
|---|---|
v25-dl-forecast-overlay umbrella + TCN + PatchTST |
Joint F4-F4-F4 verdict; retired 2026-05-22 |
v3-volatility-forecaster + rebaseline |
MODEL-BROKEN / NO-ALPHA / NEGATIVE-NET-DELTA; retired 2026-05-22 after noop-fix |
v3-regime-classifier |
Draft only; never promoted |
Retired code stays in the tree (no deletion); anchors stay locked. See spec/dev-notes/retired-surface-inventory-2026-05-22.md for the inventory.
crates/audit/— double-entry ledger + journal transactions + per-symbol position accounts + audit-tick streamcrates/reflection/— LessonCard store + 32-dim embeddings +top_kretrieval + 3-state regime taggercrates/llm/—LlmProvidertrait + Anthropic/OpenAI-compat/Ollama providers + RecordingProvider/ReplayProvider for determinismcrates/backtest/—MatchingEngine+ scenarios + report rendering with body-SHA-256 anchorscrates/strategy/—Strategytrait +Strategy::quantity_scalesizing hook + all strategy implementationscrates/ui/— iced cockpit (14 screens; Lab/Live/Compare/Memory/Models/Trail/Strategies/Risk/Audit/Control/Settings/Charts/Home/Debug)crates/exec/— fill publisher shim (note: real matching engine still lives incrates/backtest/; architect-flagged for rename perspec/dev-notes/feature-state-architect-review-2026-05-22.md)
Native iced cockpit with operator-facing screens for strategy state, equity curves, drawdowns, positions, audit trail, reflection memory, and an Assistant slot for LLM reasoning. Kill switch (typed-confirm modal) is the load-bearing destructive control. Risk override + risk veto flows shipped Phase 5.
trading/
├── README.md # This file
├── CLAUDE.md # AI agent entry point — workflow + non-negotiables
├── AGENT.md # Multi-agent orchestration contract
├── Cargo.toml # Workspace root (16 crates)
├── config/
│ ├── agent.toml # Committed config (shape only; no secrets)
│ ├── agent.toml.local # Git-ignored secrets overlay (you create this)
│ └── strategies/ # Per-strategy TOML configs
├── crates/ # Rust workspace (audit, backtest, core, cost, data,
│ # exec, features, forecast, llm, models, reflection,
│ # reports, risk, strategy, ui)
├── data/
│ ├── binance/ # Parquet OHLCV (gitignored; populate manually)
│ ├── audit/ # SQLite audit ledger
│ ├── reflection/ # SQLite reflection store
│ └── llm-replay.db # Deterministic LLM response cache
├── scripts/
│ ├── verify_anchors.sh # Regression gate: 34 body-SHA-256 anchors
│ ├── spec_lint.py # Spec structural integrity
│ ├── hash_report.py # Canonical body-SHA hasher
│ └── check_presentation.sh
├── spec/
│ ├── product.md # Product requirements + moat statement
│ ├── architecture.md # System design
│ ├── architecture/ # Domain architecture + ADRs
│ │ └── adr/ # 0028-0039 architecture decision records
│ ├── backlog.md # Active / Queue / Recent
│ ├── anchors.toml # 34 locked body-SHA-256 regression anchors
│ ├── trace.toml # Requirement → feature → code traceability
│ ├── dev-notes/ # Cross-cutting memos + audits + retrospectives
│ │ └── archive/2026-Q2/ # Archived stale notes
│ ├── runbooks/ # Operational runbooks
│ ├── design/ # Lumen design system
│ └── <feature-slug>/ # Per-feature folders (~54 today)
│ ├── feature.md
│ ├── tasks.md
│ ├── decomp.md (when architect M-T1 closes)
│ ├── reports/ # Anchored backtest + test reports
│ └── presentations/ # Operator-approval decks
├── target/ # Cargo build output
└── vendor/
└── iced_tiny_skia/ # Long-term local fork (operator-locked per CLAUDE.md)
| File | Purpose |
|---|---|
| CLAUDE.md | Project rules + non-negotiables + coding conventions. AI agents read this first. |
| AGENT.md | Multi-agent orchestration: analyst → architect → developer ‖ ui-designer → tester → presenter loop. |
| spec/product.md | What this project is and isn't (analyst-owned). |
| spec/architecture.md | System design (architect-owned). |
| spec/backlog.md | What's Active / Queued / Recent. |
| Status | Meaning |
|---|---|
draft |
Analyst sketch; no code commitment |
proposed |
Brief authored + ready for operator decision |
in-progress |
Active work (architect / developer / tester) |
shipped |
Code on main, anchors locked, tests green |
shipped-partial |
Code gates clean; one wave deferred for external-dependency reasons (first used 2026-05-22 by v3-llm-forecaster) |
retired |
Research line closed; code stays in tree; anchors locked; no further effort |
deprecated |
Roadmap item never built (or superseded) |
candidate |
Under evaluation |
roadmap / active / reserved |
Multi-phase initiative phases |
Every shipped backtest report has a body-SHA-256 entry in spec/anchors.toml. The gate is bash scripts/verify_anchors.sh (must report ANCHORS PASS (N / N) before any ship). Bodies are byte-immutable; documentation-link cleanup sweeps MUST exclude anchored files (see CLAUDE.md non-negotiables).
Per AGENT.md: analyst → architect → (developer ‖ ui-designer) → tester → presenter → operator-approve. Every non-trivial change runs through this loop. The orchestrator runs sub-agents in parallel when independent. Trivial one-file edits skip the loop.
All spec/ file edits go through the spec-update skill — never raw Write/Edit. The skill enforces frontmatter + keeps a changelog stub.
- No secrets in git. Keys in
config/agent.toml.local(git-ignored) or env vars perspec/architecture.md. - No shipping on a
REGRESSIONverdict without an explicit human override. - No silent divergence from
spec/architecture.md. - Every strategy overlay or sizing-modifier ships with a baseline-equity-divergence e2e test from day 1 (precedent:
v3-volatility-forecaster-noop-fix2026-05-22; the noop bug went undetected by 5 sequential gates). - Anchored report files in
spec/*/reports/are byte-immutable per ADR-0038 § D6; even mechanical link-fix edits mutate the body-SHA. Documentation-link cleanup MUST exclude anchored files.
When orienting on the project, these dev-notes give the most signal per word:
feature-state-table-2026-05-22.md— comprehensive 54-feature inventoryv25-dl-journey-retrospective-2026-05-22.md— what the forecaster track taught (4 retirements)v3-vol-overlay-noop-discovery-2026-05-22.md— the load-bearing engineering patternstrategic-reset-2026-05-23.md— half-validated moat finding + next-6-week roadmap framingfeature-state-analyst-review-2026-05-22.md+feature-state-architect-review-2026-05-22.md— dual-perspective reviews
Private / single-operator research project. No external license at this time.