NautilusTrader: a high-performance algorithmic trading platform and event-driven backtester
NautilusTrader is an open-source, high-performance, production-grade algorithmic trading platform, providing quantitative traders with the ability to backtest portfolios of automated trading strategies on historical data with an event-driven engine, and also deploy those same strategies live, with no code changes.
The platform is AI-first, designed to develop and deploy algorithmic trading strategies within a highly performant and robust Python-native environment. This helps to address the parity challenge of keeping the Python research/backtest environment consistent with the production live trading environment.
NautilusTrader's design, architecture, and implementation philosophy holds software correctness and safety at the highest level, with the aim of supporting Python-native, mission-critical, trading system backtesting and live deployment workloads.
The platform is also universal and asset-class-agnostic — with any REST, WebSocket or FIX API able to be integrated via modular adapters. It supports high-frequency trading across a wide range of asset classes and instrument types including FX, Equities, Futures, Options, Crypto and Betting, enabling seamless operations across multiple venues simultaneously.
Features
- Fast: Core is written in Rust with asynchronous networking using tokio.
- Reliable: Type safety and thread safety through Rust. Redis-backed performant state persistence (optional).
- Portable: OS independent, runs on Linux, macOS, and Windows. Deploy using Docker.
- Flexible: Modular adapters mean any REST, WebSocket, or FIX API can be integrated.
- Advanced: Time in force IOC, FOK, GTD, AT_THE_OPEN, AT_THE_CLOSE, advanced order types and conditional triggers. Execution instructions post-only, reduce-only, and icebergs. Contingency order lists including OCO, OTO.
- Customizable: Add user-defined custom components, or assemble entire systems from scratch leveraging the cache and message bus.
- Backtesting: Run with multiple venues, instruments and strategies simultaneously using historical quote tick, trade tick, bar, order book and custom data with nanosecond resolution.
- Live: Use identical strategy implementations between backtesting and live deployments.
- Multi-venue: Multiple venue capabilities facilitate market-making and statistical arbitrage strategies.
- AI Training: Backtest engine fast enough to be used to train AI trading agents (RL/ES).
Why NautilusTrader?
- Highly performant event-driven Python: Native binary core components.
- Parity between backtesting and live trading: Identical strategy code.
- Reduced operational risk: Enhanced risk management functionality, logical accuracy, and type safety.
- Highly extendable: Message bus, custom components and actors, custom data, custom adapters.
Traditionally, trading strategy research and backtesting might be conducted in Python using vectorized methods, with the strategy then needing to be reimplemented in a more event-driven way using C++, C#, Java or other statically typed language(s). The reasoning here is that vectorized backtesting code cannot express the granular time and event dependent complexity of real-time trading, where compiled languages have proven to be more suitable due to their inherently higher performance, and type safety.
One of the key advantages of NautilusTrader here, is that this reimplementation step is now circumvented - as the critical core components of the platform have all been written entirely in Rust or Cython. This means we're using the right tools for the job, where systems programming languages compile performant binaries, with CPython C extension modules then able to offer a Python-native environment, suitable for professional quantitative traders and trading firms.
Why Python?
Python was originally created decades ago as a simple scripting language with a clean straight forward syntax. It has since evolved into a fully fledged general purpose object-oriented programming language. Based on the TIOBE index, Python is currently the most popular programming language in the world. Not only that, Python has become the de facto lingua franca of data science, machine learning, and artificial intelligence.
The language out of the box is not without its drawbacks however, especially in the context of implementing large performance-critical systems. Cython has addressed a lot of these issues, offering all the advantages of a statically typed language, embedded into Pythons rich ecosystem of software libraries and developer/user communities.
What is Rust?
Rust is a multi-paradigm programming language designed for performance and safety, especially safe concurrency. Rust is blazingly fast and memory-efficient (comparable to C and C++) with no garbage collector. It can power mission-critical systems, run on embedded devices, and easily integrates with other languages.
Rust’s rich type system and ownership model guarantees memory-safety and thread-safety deterministically — eliminating many classes of bugs at compile-time.
The project increasingly utilizes Rust for core performance-critical components. Python language binding is handled through Cython and PyO3, with static libraries linked at compile-time before the wheel binaries are packaged, so a user does not need to have Rust installed to run NautilusTrader.
Architecture (data flow)
Installation
From PyPI
We recommend using the latest supported version of Python and setting up nautilus_trader in a virtual environment to isolate dependencies
To install the latest binary wheel (or sdist package) from PyPI using Pythons pip package manager:
pip install -U nautilus_trader
From the Nautech Systems package index
The Nautech Systems package index (packages.nautechsystems.io) is PEP-503 compliant and hosts both stable and development binary wheels for nautilus_trader. This enables users to install either the latest stable release or pre-release versions for testing.
Stable wheels
Stable wheels correspond to official releases of nautilus_trader on PyPI, and use standard versioning.
To install the latest stable release:
pip install -U nautilus_trader --index-url=https://packages.nautechsystems.io/simple
Development wheels
Development wheels are published from both the develop and nightly branches for Linux and macOS, allowing users to test features and fixes ahead of stable releases.
This process also helps preserve compute resources and ensures easy access to the exact binaries tested in CI pipelines, while adhering to PEP-440 versioning standards:
- develop wheels use the version format dev{date}+{build_number} (e.g., 1.208.0.dev20241212+7001).
- nightly wheels use the version format a{date} (alpha) (e.g., 1.208.0a20241212).
Installation commands
By default, pip installs the latest stable release. Adding the --pre flag ensures that pre-release versions, including development wheels, are considered.
To install the latest available pre-release (including development wheels):
pip install -U nautilus_trader --pre --index-url=https://packages.nautechsystems.io/simple
To install a specific development wheel (e.g., 1.208.0a20241212 for December 12, 2024):
pip install nautilus_trader==1.208.0a20241212 --index-url=https://packages.nautechsystems.io/simple
Available versions
You can view all available versions of nautilus_trader on the package index.
To programmatically fetch and list available versions:
curl -s https://packages.nautechsystems.io/simple/nautilus-trader/index.html | grep -oP '(?<=<a href=")[^"]+(?=")' | awk -F'#' '{print $1}' | sort
Branch updates
- develop branch wheels (.dev): Are built and published continuously with every merged commit.
- nightly branch wheels (a): Are built and published daily when develop branch is automatically merged at 14:00 UTC (if there are changes).
Retention policies
- develop branch wheels (.dev): Only the most recent wheel build is retained.
- nightly branch wheels (a): Only the 3 most recent wheel builds are retained.
From Source
Installation from source requires the Python.h header file, which is included in development releases such as python-dev. You'll also need the latest stable rustc and cargo to compile the Rust libraries.
See the Installation Guide for other options and further details.
Redis
Using Redis with NautilusTrader is optional and only required if configured as the backend for a cache database or message bus. See the Redis section of the Installation Guide for further details.
Examples
Indicators and strategies can be developed in both Python and Cython. For performance and latency-sensitive applications, we recommend using Cython. Below are some examples:
- indicator example written in Python.
- indicator examples written in Cython.
- strategy examples written in both Python and Cython.
- backtest examples using a BacktestEngine directly.
Docker
Docker containers are built using the base image python:3.12-slim with the following variant tags:
- nautilus_trader:latest has the latest release version installed.
- nautilus_trader:nightly has the head of the nightly branch installed.
- jupyterlab:latest has the latest release version installed along with jupyterlab and an example backtest notebook with accompanying data.
- jupyterlab:nightly has the head of the nightly branch installed along with jupyterlab and an example backtest notebook with accompanying data.
The container images can be pulled as follows:
docker pull ghcr.io/nautechsystems/<image_variant_tag> --platform linux/amd64
You can launch the backtest example container by running:
docker pull ghcr.io/nautechsystems/jupyterlab:nightly --platform linux/amd64 docker run -p 8888:8888 ghcr.io/nautechsystems/jupyterlab:nightly
Then open your browser at the following address:
http://127.0.0.1:8888/lab