All builds

Trading bots

Two trading engines where code holds the risk and AI only picks from a menu

A crypto engine on OKX and a second bot that trades crypto on Binance and US stocks on Tiger Brokers. Code generates the trades, sizes them and manages every exit. A fast model picks one option from the menu or says hold. A slow model sets the mood once every few hours. Neither is allowed near the stop-loss.

Everyone wants to build the AI that trades. I wanted to build the one that cannot blow itself up. So the design question was never “how smart is the model”. It was “what is the model not allowed to touch”.

The split

Code does the dangerous parts. It reads closed price bars only, never a half-formed one. It generates candidates from three plain strategies (trend, breakout and buying a dip), sizes each one to risk a fixed slice of the book at the stop, and manages every open position: stops, targets, trailing exits, time limits. Daily and weekly loss limits halt new trades automatically.

A fast model chooses. When there are candidates, a small fast model picks one from the menu or says hold, and reports how risky the moment feels. Below a confidence threshold, it is ignored. If there are no candidates, no model is called at all, which is most of the time and most of the savings.

A slow model sets the posture. Every few hours a frontier model reads the bigger picture and sets the mood: risk on, neutral or risk off, how many positions, how much weight each strategy gets. It has a daily spending cap. It never places an order.

Two engines

The first trades crypto on OKX and was built overnight in early October. It is the one that taught me the rules.

The second is the rebuild. One core, two bots: crypto on Binance and an S&P 500 fund plus three large US stocks on Tiger Brokers, deciding on every closed 15-minute bar across three timeframes, with its picks made by Clef running on Cloudflare. It ships with 222 automated tests.

Panic buttons are files. Drop one in a folder and the bot stops opening trades. Drop another and it closes everything. It works from anywhere I can reach the Mac mini.

The gate

Nothing goes live because a backtest looked good. An engine has to run for two weeks on the exchange’s demo engine with positive results after fees and a drawdown under a fixed limit before a live key is even created. Live keys can trade but never withdraw, and are locked to one machine.

The first engine’s paper month did not clear the gate. The log showed exactly why: a slow layer that was offline for more than a week, replies it could not read, and a bug that re-entered the same idea twice. No live key was created. That is the gate working, and it is the most useful result the project has produced.

What broke

  • Backtests that flatter. The best of five configurations on the same data is the one you should trust least. I picked it anyway, labelled it as such, and expected worse. It was worse.
  • A frontier model with no credit. The slow layer ran neutral for days because an API account was empty. Now a missing brain means “stay neutral”, by design.

What I would tell you

If you build one of these, spend your time on what stops it, not what starts it. The model is the least important part of a trading bot.

Newsletter · weekly

The Build Log

One system teardown a week. What I built, what it cost, what broke, and the exact prompts that did the heavy lifting. No tool listicles.

  • A full build teardown with architecture
  • The prompt or config that unlocked it
  • The failures, with root causes

Weekly. Unsubscribe in one click. Read past issues.