Environment Setup
For development we recommend using the PyCharm Professional edition IDE, as it interprets Cython syntax. Alternatively, you could use Visual Studio Code with a Cython extension.
uv is the preferred tool for handling all Python virtual environments and dependencies.
pre-commit is used to automatically run various checks, auto-formatters and linting tools at commit.
NautilusTrader uses increasingly more Rust, so Rust should be installed on your system as well (installation guide).
NautilusTrader must compile and run on Linux, macOS, and Windows. Please keep portability in
mind (use std::path::Path
, avoid Bash-isms in shell scripts, etc.).
Setup
The following steps are for UNIX-like systems, and only need to be completed once.
- Follow the installation guide to set up the project with a modification to the final command to install development and test dependencies:
uv sync --active --all-groups --all-extras
or
make install
If you're developing and iterating frequently, then compiling in debug mode is often sufficient and significantly faster than a fully optimized build. To install in debug mode, use:
make install-debug
- Set up the pre-commit hook which will then run automatically at commit:
pre-commit install
Before opening a pull-request run the formatting and lint suite locally so that CI passes on the first attempt:
make format
make pre-commit
Make sure the Rust compiler reports zero errors – broken builds slow everyone down.
- Optional: For frequent Rust development, configure the
PYO3_PYTHON
variable in.cargo/config.toml
with the path to the Python interpreter. This helps reduce recompilation times for IDE/rust-analyzer basedcargo check
:
PYTHON_PATH=$(which python)
echo -e "\n[env]\nPYO3_PYTHON = \"$PYTHON_PATH\"" >> .cargo/config.toml
Since .cargo/config.toml
is tracked, configure git to skip any local modifications:
git update-index --skip-worktree .cargo/config.toml
To restore tracking: git update-index --no-skip-worktree .cargo/config.toml
Builds
Following any changes to .rs
, .pyx
or .pxd
files, you can re-compile by running:
uv run --no-sync python build.py
or
make build
If you're developing and iterating frequently, then compiling in debug mode is often sufficient and significantly faster than a fully optimized build. To compile in debug mode, use:
make build-debug
Faster builds 🏁
The cranelift backends reduces build time significantly for dev, testing and IDE checks. However, cranelift is available on the nightly toolchain and needs extra configuration. Install the nightly toolchain
rustup install nightly
rustup override set nightly
rustup component add rust-analyzer # install nightly lsp
rustup override set stable # reset to stable
Activate the nightly feature and use "cranelift" backend for dev and testing profiles in workspace Cargo.toml
. You can apply the below patch using git apply <patch>
. You can remove it using git apply -R <patch>
before pushing changes.
diff --git a/Cargo.toml b/Cargo.toml
index 62b78cd8d0..beb0800211 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,3 +1,6 @@
+# This line needs to come before anything else in Cargo.toml
+cargo-features = ["codegen-backend"]
+
[workspace]
resolver = "2"
members = [
@@ -140,6 +143,7 @@ lto = false
panic = "unwind"
incremental = true
codegen-units = 256
+codegen-backend = "cranelift"
[profile.test]
opt-level = 0
@@ -150,11 +154,13 @@ strip = false
lto = false
incremental = true
codegen-units = 256
+codegen-backend = "cranelift"
[profile.nextest]
inherits = "test"
debug = false # Improves compile times
strip = "debuginfo" # Improves compile times
+codegen-backend = "cranelift"
[profile.release]
opt-level = 3
Pass RUSTUP_TOOLCHAIN=nightly
when running make build-debug
like commands and include it in in all rust analyzer settings for faster builds and IDE checks.