Case study · S24DeFi Labs

algo_bot: an autonomous trading platform that's safe by default, and built so it can't fool itself.

Most trading bots fail quietly: a backtest that was luck, a bug that peeked at the future, fees nobody modeled, automation with no brakes. We built a platform whose first job is to refuse all of that, and whose second job is to trade.

Why we built itFast to build, just as fast to fool yourself

Retail algorithmic trading has four classic failure modes, and AI coding agents make most of them easier to commit. An agent can write a strategy, a backtest and a dashboard in an afternoon. It can also hand you a beautiful equity curve that is pure overfitting.

Overfit backtestsTry enough ideas and one will look brilliant by chance.
Lookahead leaksOne misaligned index and the model is reading tomorrow's paper.
Fees and slippageEdges that exist only at zero cost.
Automation with no brakesA loop that keeps trading after it should have stopped.

What it solvesBuilt so nothing reaches capital without earning it

algo_bot is two systems sharing one codebase. The trading path runs strategies across six broker integrations with several independent risk limits, and it defaults to doing nothing: paper or testnet execution unless someone deliberately switches on live trading. The research path is built to decide whether any idea deserves to go live, using a statistical bar that rises with every idea we try.

The design principle across both: when in doubt, the system stops, records why, and waits for a human.

ArchitectureThe trading path

Trading path: market data, signals, risk layer, execution, ledger and audit, with a kill switch over risk and execution, and a command center and observability stack across all stages
Risk decisions, execution and safety events write to the audit trail. The kill switch sits outside the strategy code, so a misbehaving strategy cannot override it.
Runtime. Python 3.11 services in a six-container Docker Compose stack: trading engine, FastAPI and WebSocket command center, an analytics dashboard, Prometheus, Alertmanager and Grafana.
Brokers. Five venue integrations across crypto, US equities and FX (four with a live path), plus a paper broker, behind one factory interface, with per-broker circuit breakers and cross-exchange position reconciliation.
Risk. Per-trade, total open-risk, daily-loss and losing-streak limits; order rate, size and duplicate checks; and a graduated drawdown response that shrinks, then flattens and halts.
Audit. Kill-switch events from the operator tool and the risk engine, risk blocks, overrides and manual resets land in an append-only store that refuses updates and deletes. Risk decisions are hash-chained, so tampering shows.

Engineering highlightsSeven decisions, and the failure each one prevents

1. Live trading is opt-in, several times over

Problem
One wrong config flag should never put real money at risk.
Built
Paper and testnet by default, and no broker places a live order without an explicit setting. On the equities path, going live also takes a same-day confirmation file, an optional typed confirmation and a paper-trading qualification with six pass criteria; any override is recorded.
Result
The safe state is the one you get by doing nothing.

2. A kill switch with four separate paths

Problem
If the only off switch runs inside the broken part, you can't turn it off.
Built
File, environment, automatic (loss limits and safety trips) and a command-center call. Any one of them halts trading, and switches made through the software are logged.
Result
There's more than one way to stop it, and none of them depends on a strategy behaving.

3. A bar that rises with every idea tried

Problem
Test enough strategies and the best one looks good by luck.
Built
A permanent trial ledger and a Deflated Sharpe test. Rejected ideas keep counting, so each new candidate must beat the expected best result of all the noise we've already tried.
Result
The test refused the strongest result on record, and we agree with it.

4. A lookahead guard that caught a real leak

Problem
Future data leaking into a signal is the classic backtest lie, and it's easy to miss in review.
Built
A contract test that re-scores truncated history and demands identical results, run before any evaluation counts.
Result
It rejected a first implementation that derived an input from the data it was scoring. The fix made that input independent of the scored data.

5. Forensics where the majority was wrong

Problem
The trade ledger mixed 1,392 rows from a retired replay path with 301 live paper trades. "Most common equals normal" flagged the genuine trades as the anomaly.
Built
Signature-based cohort scoring and a reversible quarantine keyed on how each row was written, with dry-run, snapshot and a single transaction.
Result
Zero misclassified rows, nothing deleted, and an honest baseline recovered.

6. AI agents, with the rules written in code

Problem
AI agents write a lot of this codebase. Agents that can merge anything eventually will.
Built
Separate roles for implementer, adversarial reviewer and independent merge reviewer; a strict human authorization grammar where anything else means no; and protected paths that can't merge without an independent review posted by a dedicated, main-branch-only identity.
Result
Several agents work in one repo, and every protected change needs a second, independent review.

7. An LLM in the loop that has to earn its vote

Problem
"Ask an LLM if this trade is good" is easy to build and impossible to trust by default.
Built
An optional LLM scoring layer, off by default and log-only: it records an opinion on each signal but blocks nothing until the data shows it predicts outcomes. If it fails, the loop carries on unaffected.
Result
As shipped, the score is only recorded. It blocks nothing, and if it fails, trading carries on.

Research rigorHow an idea earns the right to trade

Research pipeline: pre-register, adversarial review, return-free preflight, lookahead guard, walk-forward out-of-sample, Deflated Sharpe test
Each step needs an explicit, written human authorization. Agents can propose, attack and implement, but they can't spend a trial or ship a strategy on their own.
  • Pre-registration. Hypothesis, expected sign, one test horizon and a published prior are committed before any data is touched.
  • Return-free preflight. Data provenance, overlap with ideas already killed, coverage and a statistical-power check, each with a kill line written in advance.
  • Cheap kills first. At least five ideas were stopped before spending a single counted trial.
  • One trial means one trial. No quiet sensitivity runs and no re-tries under a new name. A changed idea is a new registration.

Honest resultsSaying no is the product

0 / 32

evaluations certified for capital so far. That includes a candidate that was positive in every out-of-sample fold and about three times stronger than anything before it, and still failed the deflated bar once every earlier trial was counted. In our own written analysis, the bar now sits above every effect we've found but one, and that one still failed. We kept it there rather than lower it after the fact.

The system would rather report nothing than report luck. We make no claims of returns or profitability.

The whole platformSystem map

System map: trading engine, control and observability, research workbench, delivery and quality
Trading, control, research, and delivery. The same four areas the rest of this page walks through one at a time.

By the numbersBuilt like production software

~180Klines of Python
5,100+automated tests
88%coverage floor in CI
12GitHub Actions workflows
560+merged pull requests
6broker integrations

Plus lint and format checks, a dependency vulnerability audit that fails on any finding, pre-commit hooks that block private keys and env files, a changelog requirement on every PR, and a daily data-verification job.

What's nextRaise the evidence, not lower the bar

The next step is a prospective-only test: future candidates are judged on data that didn't exist when they were registered, so no past result can be rescued by a rule change. On the engineering side, the priority is fewer features, finished properly: finishing the path from research verdict to paper deployment before adding anything new.

By designWhat this page leaves out

The code is private. This case study describes the architecture and the engineering decisions, not the means to reproduce them. Intentionally omitted:

  • strategy logic and parameters
  • research ideas, constructions and thresholds
  • risk, fee and drawdown settings
  • symbols, data sources and vendors
  • prompts and model configuration
  • infrastructure identifiers and secrets
  • performance, P&L and account data