Skip to main content

Repository layout

The repo is a Turborepo monorepo. The Python bot lives at the root; the website and shared design system are under apps/ and packages/.

Monorepo commands


The three-file rule

Any ML feature change touches exactly three files:
  1. ml/feature_engineering.py β€” add the feature computation
  2. ml_config.json β†’ features array β€” add the name in the correct position
  3. Retrain all 4 models β€” Signal, Position, SLTP, Risk (in that order)
Changing any one without the others breaks inference. The models/model_compat.json file stores a hash of the feature list. On startup, EnsemblePredictor verifies the hash against the current ml_config.json. A mismatch raises ModelCompatibilityError immediately.

Strict training order

Models must always be trained in this order:
Training out of order produces either import errors or silent data contamination in the Risk model’s training labels.

Backtester / live parity

backtest/run.py must always mirror trading/bot.py. Every change to execution logic in the bot must be reflected in the backtester, and vice versa. Key parity invariants:
  • Same feature engineering (ml/feature_engineering.py)
  • Same model inference chain (calibrated pkl β†’ ONNX β†’ raw pkl)
  • Same position sizing formula
  • Same equity-aware SL cap
  • Same circuit breakers and gates
  • Same position model evaluation timing
If these diverge, backtest scores become unreliable as live performance predictors.

Lane discipline

The codebase has two clearly separated lanes: Clients should never retrain. The live trading host should stay simple β€” it does not need a GPU or the full ML dependency stack (just pip install -r requirements.txt is fine).

Go binary β€” embedded asset system

The Go binary uses Go’s //go:embed directive to bake all ML models, scalers, and configs into the compiled binary at build time. The scripts/pack_embedded.sh script copies the necessary files into internal/embedded/ before each build.
Because everything is embedded, customers do not need a models/ directory, Hugging Face Hub access, or any Python tooling. See Go binary for the full build and license reference.

Config files

Two config files govern all behavior: Both are committed to git. When weekly_optimize.py updates config.json, the change appears in git history. This makes every optimization run fully auditable.