Skip to content
sbOogwayPublic

About

General-purpose backtesting framework on nautilus_trader v2: pluggable data sources and asset classes, streamed L2, train/validation/test splits, isolated parallel runs. Rewrite of sbt.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

sbt2

Backtesting framework on nautilus_trader, with a server and a protocol for a GUI. The GUI lives on the gui branch.

CI codecov release python uv ruff Conventional Commits

Components

  • sbt2-backend/: the Python distributions, the CLI and the server. Its README has the quick start.
  • sbt2-protocol/: the protobuf messages between the server and its GUI. Its README has the protocol rules.
  • sbt2-notebooks/: Jupyter notebooks that run strategies on the server. Its README shows how to start them.

Install

Each release has the Python distributions and SHA256SUMS, which covers every file of the release. The notes name the server image with its digest.

Server

The image is for x86_64. Pull it and run it with a token that clients must present:

podman pull ghcr.io/sboogway/sbt2-server:latest
podman run -d -p 127.0.0.1:8765:8765 -e SBT2_SERVER_TOKEN=<token> \
  -v sbt2-data:/data ghcr.io/sboogway/sbt2-server:latest

Use :X.Y.Z instead of :latest to pin a version. With sbt2-backend/compose.yaml, set SBT2_VERSION=X.Y.Z to run that version.

To run it as a rootless user service that follows :latest, use the Quadlet unit sbt2-backend/sbt2-server.container:

mkdir -p ~/.config/containers/systemd ~/.config/sbt2
cp sbt2-backend/sbt2-server.container ~/.config/containers/systemd/
echo 'SBT2_SERVER_TOKEN=<token>' >~/.config/sbt2/server.env
chmod 600 ~/.config/sbt2/server.env
systemctl --user daemon-reload
systemctl --user start sbt2-server
loginctl enable-linger "$USER"  # keeps it running after logout

The server listens on 127.0.0.1:8765. podman auto-update pulls a new :latest and restarts the service. If the new image does not become healthy, it rolls back to the old one.

Make podman accept only signed server images. Install the public key, the policy and the signature lookup from sbt2-backend/deploy/:

mkdir -p ~/.config/containers/registries.d
cp sbt2-backend/deploy/sbt2-server.pub ~/.config/containers/
sed "s|@HOME@|$HOME|" sbt2-backend/deploy/policy.json >~/.config/containers/policy.json
cp sbt2-backend/deploy/registries.d/sbt2.yaml ~/.config/containers/registries.d/

~/.config/containers/policy.json replaces /etc/containers/policy.json for your user. If you have one already, add only the ghcr.io/sboogway/sbt2-server entry to it. Then podman auto-update refuses a server image without a valid signature, before the health check. To check an image by hand:

podman pull ghcr.io/sboogway/sbt2-server:latest

The pull fails with Source image rejected when the signature is missing or wrong.

The server speaks plain ws://, so publish its port only on loopback. For remote access, open an SSH tunnel and point the client at it:

ssh -N -L 8765:127.0.0.1:8765 user@host
export SBT2_SERVER_URL=ws://127.0.0.1:8765

Development

make sync
make check

make help lists the other commands. Each component also keeps its own direct commands, run from its directory.

Release

The maintainer cuts each release on their machine in two steps: make build, then make publish. make release runs both. There is no release in CI, and for now no CI: the tests run locally.

make build refuses to start unless:

  • HEAD is origin/main after a fetch, and the working tree is clean;
  • make check passes.

It then plans a tag for each merge on main since the last tag, with the version that git-cliff picks from its Conventional Commits. A merge with no feat, fix, perf, refactor or revert change gets no new version, so it gets no tag. The newest tagged merge is the release; VERSION=X.Y.Z makes HEAD the release with that version. The target refuses when there is nothing to release. It builds the wheels and the server image of the release, and smoke-tests the image. It writes the files, SHA256SUMS, the notes and the planned tags to the git-ignored dist/release/; the image stays in the local podman store. Nothing leaves the machine.

make publish refuses unless dist/release/ holds a build of the current origin/main. It drafts the release, uploads the files and pushes the image as :X.Y.Z and :latest. Last, it pushes the tags of the older merges and publishes. Publishing creates the release's tag on GitHub. The older merges get a tag only; the notes of the release list every change since the last release, by version. A failure before the publish leaves a draft; a re-run of make publish finishes it. After the publish, it removes dist/release/.

After the publish, make publish runs podman auto-update when the sbt2-server user service exists, so the server on the maintainer's machine runs the new image. A failed update only gives a warning.

The tokens come from the environment or from a git-ignored .env at the repo root (mode 600). A variable set in the environment wins over .env:

GH_TOKEN=...    # or a gh login; can edit the releases
GHCR_TOKEN=...  # classic token with write:packages

The push signs the image with a sigstore key, and then pulls it under the host policy to check the signature. The private key and its passphrase stay outside the repo; set their paths in the environment:

SBT2_SIGNING_KEY=~/.config/sbt2/signing/sbt2-server.private
SBT2_SIGNING_PASSPHRASE_FILE=~/.config/sbt2/signing/passphrase

Without them, or without the public key sbt2-backend/deploy/sbt2-server.pub, make publish and make release-image stop before they change anything. The push also needs the signature lookup in ~/.config/containers/registries.d/, as on the server host. To make the key pair once:

mkdir -p ~/.config/sbt2/signing && chmod 700 ~/.config/sbt2/signing
cd ~/.config/sbt2/signing
openssl rand -base64 32 >passphrase && chmod 600 passphrase
skopeo generate-sigstore-key --output-prefix sbt2-server --passphrase-file passphrase

Then commit sbt2-server.pub as sbt2-backend/deploy/sbt2-server.pub.

To add the image to an existing release, use make release-image. It acts on the newest vX.Y.Z tag; TAG=vX.Y.Z picks another release. It refuses when the release has the image already, unless FORCE=1. It builds the tag's commit in a temporary worktree.

License

sbt2 is licensed under the GNU Lesser General Public License v3.0 or later, which builds on the GNU General Public License v3.0.

About

General-purpose backtesting framework on nautilus_trader v2: pluggable data sources and asset classes, streamed L2, train/validation/test splits, isolated parallel runs. Rewrite of sbt.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages