A high-performance algorithmic trading platform and event-driven backtester
Project description
Branch | Version | Status |
---|---|---|
master |
||
nightly |
||
develop |
Platform | Rust | Python |
---|---|---|
Linux (x86_64) |
1.77.1+ | 3.10+ |
macOS (x86_64) |
1.77.1+ | 3.10+ |
macOS (arm64) |
1.77.1+ | 3.10+ |
Windows (x86_64) |
1.77.1+ | 3.10+ |
- Website: https://nautilustrader.io
- Docs: https://docs.nautilustrader.io
- Support: support@nautilustrader.io
Introduction
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.
NautilusTraders 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. Thus, it can handle high-frequency trading operations for any asset classes including FX, Equities, Futures, Options, CFDs, Crypto and Betting - across multiple venues simultaneously.
Features
- Fast - C-level speed through Rust and Cython. Asynchronous networking with uvloop
- Reliable - Type safety through Rust and Cython. Redis backed performant state persistence
- Portable - OS independent, runs on Linux, macOS, 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 instructionspost-only
,reduce-only
, and icebergs. Contingency order lists includingOCO
,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 Agent Training - Backtest engine fast enough to be used to train AI trading agents (RL/ES)
nautilus - from ancient Greek 'sailor' and naus 'ship'.
The nautilus shell consists of modular chambers with a growth factor which approximates a logarithmic spiral. The idea is that this can be translated to the aesthetics of design and architecture.
Why NautilusTrader?
- Highly performant event-driven Python - native binary core components
- Parity between backtesting and live trading - identical strategy code
- Reduced operational risk - risk management functionality, logical correctness 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 (or other suitable language) using vectorized methods, with the strategy then needing to be reimplemented in a more event-drive 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 Cython?
Cython is a compiled programming language which aims to be a superset of the Python programming language, designed to give C-like performance with code that is written in Python - with optional C-inspired syntax.
The project heavily utilizes Cython to provide static type safety and increased performance for Python through C extension modules. The vast majority of the production code is actually written in Cython, however the libraries can be accessed from both Python and Cython.
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, 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. In the future as more Rust code is introduced, PyO3 will be leveraged for easier Python bindings.
This project makes the Soundness Pledge:
“The intent of this project is to be free of soundness bugs. The developers will do their best to avoid them, and welcome help in analyzing and fixing them.”
Architecture (data flow)
Quality Attributes
- Reliability
- Performance
- Modularity
- Testability
- Maintainability
- Deployability
Integrations
NautilusTrader is designed in a modular way to work with adapters which provide connectivity to trading venues and data providers - converting their raw API into a unified interface. The following integrations are currently supported:
Name | ID | Type | Status | Docs |
---|---|---|---|---|
Betfair | BETFAIR |
Sports Betting Exchange | Guide | |
Binance | BINANCE |
Crypto Exchange (CEX) | Guide | |
Binance US | BINANCE |
Crypto Exchange (CEX) | Guide | |
Binance Futures | BINANCE |
Crypto Exchange (CEX) | Guide | |
Bybit | BYBIT |
Crypto Exchange (CEX) | Guide | |
Databento | DATABENTO |
Data Provider | Guide | |
Interactive Brokers | INTERACTIVE_BROKERS |
Brokerage (multi-venue) | Guide |
ID:
The default client ID for the integrations adapter clientsType:
The type of integration (often the venue type)
Status
building
- Under construction and likely not in a usable statebeta
- Completed to a minimally working state and in a 'beta' testing phasestable
- Stabilized feature set and API, the integration has been tested by both developers and users to a reasonable level (some bugs may still remain)
Refer to the Integrations documentation for further details.
Installation
From PyPI
We recommend running the platform with the latest stable version of Python, and in a virtual environment to isolate the dependencies.
To install the latest binary wheel from PyPI:
pip install -U nautilus_trader
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.
For MacBook Pro M1/M2, make sure your Python installed using pyenv is configured with --enable-shared
:
PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install <python_version>
See https://pyo3.rs/latest/getting_started#virtualenvs.
It's possible to install from source using pip
if you first install the build dependencies
as specified in the pyproject.toml
. However, we highly recommend installing using poetry as below.
-
Install rustup (the Rust toolchain installer):
- Linux and macOS:
curl https://sh.rustup.rs -sSf | sh
- Windows:
- Download and install
rustup-init.exe
- Install "Desktop development with C++" with Build Tools for Visual Studio 2019
- Download and install
- Linux and macOS:
-
Enable
cargo
in the current shell:- Linux and macOS:
source $HOME/.cargo/env
- Windows:
- Start a new PowerShell
- Linux and macOS:
-
Install poetry (or follow the installation guide on their site):
curl -sSL https://install.python-poetry.org | python3 -
-
Clone the source with
git
, and install from the projects root directory:git clone https://github.com/nautechsystems/nautilus_trader cd nautilus_trader poetry install --only main --all-extras
Refer to the Installation Guide for other options and further details.
Versioning and releases
NautilusTrader is currently following a bi-weekly beta release schedule. The API is becoming more stable, however breaking changes are still possible between releases. Documentation of these changes in the release notes are made on a best-effort basis.
Branches
master
branch will always reflect the source code for the latest released versionnightly
branch may contain experimental features and is generally merged fromdevelop
branch daily, and also when requireddevelop
branch is normally very active with frequent commits and may contain experimental features. We aim to maintain a stable passing build on this branch
The current roadmap has a goal of achieving a stable API for a 2.x
version. From this
point we will follow a formal process for releases, with deprecation periods for any API changes.
Makefile
A Makefile
is provided to automate most installation and build tasks for development. It provides the following targets:
make install
-- Installs inrelease
build mode withmain
,dev
andtest
dependencies then installs the package using poetry (default)make install-debug
-- Same asmake install
but withdebug
build modemake install-just-deps
-- Installs just themain
,dev
andtest
dependencies (does not install package)make install-just-deps-all
-- Same asmake install-just-deps
and additionally installsdocs
dependenciesmake build
-- Runs the Cython build script inrelease
build mode (default)make build-debug
-- Runs the Cython build script indebug
build modemake build-wheel
-- Runs the Poetry build with a wheel format inrelease
modemake build-wheel-debug
-- Runs the Poetry build with a wheel format indebug
modemake clean
-- CAUTION Cleans all non-source artifacts from the repositorymake docs
-- Builds the documentation HTML using Sphinxmake pre-commit
-- Runs the pre-commit checks over all filesmake ruff
-- Runs ruff over all files using thepyproject.toml
configmake outdated
-- Runs commands to show outdated dependencies for both Rust and Pythonmake pytest
-- Runs all tests withpytest
(except performance tests)make pytest-coverage
-- Same asmake pytest
and additionally runs with test coverage and produces a report
Examples
Indicators and strategies can be developed in both Python and Cython (although if performance and latency sensitivity are import we recommend Cython). The below are some examples of this:
- 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 a base python:3.11-slim
with the following image variant tags:
nautilus_trader:latest
has the latest release version installednautilus_trader:nightly
has the head of thenightly
branch installedjupyterlab:latest
has the latest release version installed along withjupyterlab
and an example backtest notebook with accompanying datajupyterlab:nightly
has the head of thenightly
branch installed along withjupyterlab
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
:warning: WARNING |
---|
NautilusTrader currently exceeds the rate limit for Jupyter notebook logging (stdout output),
this is why log_level
in the examples is set to ERROR
. If you lower this level to see more
logging then the notebook will hang during cell execution. A fix is currently
being investigated which involves either raising the configured rate limits for
Jupyter, or throttling the log flushing from Nautilus.
https://github.com/jupyterlab/jupyterlab/issues/12845
https://github.com/deshaw/jupyterlab-limit-output
Minimal Strategy
The following is a minimal EMA Cross strategy example which just uses bar data.
While trading strategies can become very advanced with this platform, it's still possible to put
together simple strategies. First inherit from the Strategy
base class, then only the
methods which are required by the strategy need to be implemented.
class EMACross(Strategy):
"""
A simple moving average cross example strategy.
When the fast EMA crosses the slow EMA then enter a position at the market
in that direction.
Cancels all orders and closes all positions on stop.
"""
def __init__(self, config: EMACrossConfig) -> None:
super().__init__(config)
# Configuration
self.instrument_id = config.instrument_id
self.bar_type = config.bar_type
self.trade_size = Decimal(config.trade_size)
# Create the indicators for the strategy
self.fast_ema = ExponentialMovingAverage(config.fast_ema_period)
self.slow_ema = ExponentialMovingAverage(config.slow_ema_period)
self.instrument: Instrument | None = None # Initialized in on_start
def on_start(self) -> None:
"""
Actions to be performed on strategy start.
"""
# Get instrument
self.instrument = self.cache.instrument(self.instrument_id)
# Register the indicators for updating
self.register_indicator_for_bars(self.bar_type, self.fast_ema)
self.register_indicator_for_bars(self.bar_type, self.slow_ema)
# Get historical data
self.request_bars(self.bar_type)
# Subscribe to live data
self.subscribe_bars(self.bar_type)
def on_bar(self, bar: Bar) -> None:
"""
Actions to be performed when the strategy receives a bar.
"""
# BUY LOGIC
if self.fast_ema.value >= self.slow_ema.value:
if self.portfolio.is_flat(self.instrument_id):
self.buy()
elif self.portfolio.is_net_short(self.instrument_id):
self.close_all_positions(self.instrument_id)
self.buy()
# SELL LOGIC
elif self.fast_ema.value < self.slow_ema.value:
if self.portfolio.is_flat(self.instrument_id):
self.sell()
elif self.portfolio.is_net_long(self.instrument_id):
self.close_all_positions(self.instrument_id)
self.sell()
def buy(self) -> None:
"""
Users simple buy method (example).
"""
order: MarketOrder = self.order_factory.market(
instrument_id=self.instrument_id,
order_side=OrderSide.BUY,
quantity=self.instrument.make_qty(self.trade_size),
)
self.submit_order(order)
def sell(self) -> None:
"""
Users simple sell method (example).
"""
order: MarketOrder = self.order_factory.market(
instrument_id=self.instrument_id,
order_side=OrderSide.SELL,
quantity=self.instrument.make_qty(self.trade_size),
)
self.submit_order(order)
def on_stop(self) -> None:
"""
Actions to be performed when the strategy is stopped.
"""
# Cleanup orders and positions
self.cancel_all_orders(self.instrument_id)
self.close_all_positions(self.instrument_id)
# Unsubscribe from data
self.unsubscribe_bars(self.bar_type)
def on_reset(self) -> None:
"""
Actions to be performed when the strategy is reset.
"""
# Reset indicators here
self.fast_ema.reset()
self.slow_ema.reset()
Development
We aim to provide the most pleasant developer experience possible for this hybrid codebase of Python, Cython and Rust. Refer to the Developer Guide for helpful information.
cargo-nextest is the standard Rust test runner for NautilusTrader. You can install it by running:
cargo install cargo-nextest
Contributing
Thank you for considering contributing to Nautilus Trader! We welcome any and all help to improve the project. If you have an idea for an enhancement or a bug fix, the first step is to open an issue on GitHub to discuss it with the team. This helps to ensure that your contribution will be well-aligned with the goals of the project and avoids duplication of effort.
Once you're ready to start working on your contribution, make sure to follow the guidelines outlined in the CONTRIBUTING.md file. This includes signing a Contributor License Agreement (CLA) to ensure that your contributions can be included in the project.
Note that all pull requests should be made to the develop
branch. This is where new features
and improvements are integrated before being released to the public.
Thank you again for your interest in Nautilus Trader! We look forward to reviewing your contributions and working with you to improve the project.
Community
Join our community of users and contributors on Discord to chat and stay up-to-date with the latest announcements and features of NautilusTrader. Whether you're a developer looking to contribute or just want to learn more about the platform, all are welcome on our server.
License
The source code for NautilusTrader is available on GitHub under the GNU Lesser General Public License v3.0. Contributions to the project are welcome and require the completion of a standard Contributor License Agreement (CLA).
NautilusTrader is developed and maintained by Nautech Systems, a technology company specializing in the development of high-performance trading systems. Although the project utilizes the Rust programming language and benefits from its ecosystem, Nautech Systems is not affiliated with the Rust Foundation, and this project is not an official work of the Rust Foundation. For more information, visit https://nautilustrader.io.
Copyright (C) 2015-2024 Nautech Systems Pty Ltd. All rights reserved.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for nautilus_trader-1.191.0-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32323b3607721a5b741a8b695f1547cace66d65cc217f5e991570f797577410e |
|
MD5 | a727c9dda07cd77b3752bdd9ca4e141d |
|
BLAKE2b-256 | 5e5ef0e63aeafad85c657ef1dca0a49f3bda9d87844f0e1e0b9994db9cdec7ff |
Hashes for nautilus_trader-1.191.0-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f32773c30ee025053ddff14aee8284c3b2f1bf8d969bae4368fc88610eacac9 |
|
MD5 | 1f189ed65fe892ae21995b047a119905 |
|
BLAKE2b-256 | 642b429c84c7e5042b9f35746a7027414311ced96993c86f3e98b69e30a3fd60 |
Hashes for nautilus_trader-1.191.0-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf9ba3ebc18b755c2e39edf512df7b667bcb1df2110108baee971c3ace8836a2 |
|
MD5 | 1d9d20c90de85b269ae1272e22a19cf1 |
|
BLAKE2b-256 | c7fb6475bdf7d95be531c4e60e3e6298f1a066e61934de5d1e695dd06e9c3ef9 |
Hashes for nautilus_trader-1.191.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53cb9e95c37bddc2271293ea0abe35afd7061df912361df780f81b3d63da7052 |
|
MD5 | 41eccb91a6a4bd2a6881f74203ac89cd |
|
BLAKE2b-256 | dab0299ce647633d4cc8dac797c4f26b05824e0b640908254a726674340b4372 |
Hashes for nautilus_trader-1.191.0-cp312-cp312-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10f30fd09b009121cfa07146c60081779e17e8a7d3c8a6ef3e5ac17c7ddc3904 |
|
MD5 | 00272fd6abdaa198f1a04ab322beb346 |
|
BLAKE2b-256 | ffcea3b3ef5da76950f6875bf388f849b93985927e9fecb082667855e1f170ca |
Hashes for nautilus_trader-1.191.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58d80ef841961530cf699df31d4d903bc6faad84e0242b0214d69e1bbc7cb8d7 |
|
MD5 | 7cfc806c982447071a1806d001113332 |
|
BLAKE2b-256 | 8e1b4045aec44bbdb9a008325a5fdcef2839b473e87e7eed2dc24a0bedf7b708 |
Hashes for nautilus_trader-1.191.0-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb42cb5d822561a8c87d16a765f3d941b6c272fe462fe5fd322aba8c5713cfd0 |
|
MD5 | de4a6fdfea747c98a1ae1098fdc08cff |
|
BLAKE2b-256 | 2e90d3970067daa1a60684481bcad6fc0e87ba50a93de30af5c176dc41fcab89 |
Hashes for nautilus_trader-1.191.0-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be6b4346da1cceb94ec91e757f30e45feb79c8bca1bce935fca71cbc4b546f6b |
|
MD5 | 9848fc25f5bd0f91e70e5f16bf89b7e0 |
|
BLAKE2b-256 | cb21fd5b2d870aca61827cbb17c7db111556b67c865aaab425d88e90bb91b53e |
Hashes for nautilus_trader-1.191.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 057a79f84bcd3b0f9dfbdfeeaffe946cbf4282c4e691476582385f6db02ab943 |
|
MD5 | 8638cdb886216af1b7e1108003f2a291 |
|
BLAKE2b-256 | f15e91cfb3d5fdbd612617b5b2cb70c65959f87ba46d90cb8472dd8dfec8d5ab |
Hashes for nautilus_trader-1.191.0-cp311-cp311-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ccf6d26e41951c2fb56a218b727b8cbc59fba7d7050ae807dc30421ae6d5bb9 |
|
MD5 | 4ffa5a993a3218e7353a1fd77698e548 |
|
BLAKE2b-256 | 1b520f3050ebce1edf13e1c1f34a9a4cc902b9e051a3a030019e7ee289391d2a |
Hashes for nautilus_trader-1.191.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f70bf051b6aee83189b9c0c86c06d8b1001e3d832166d1813f501931855572c5 |
|
MD5 | 84cc9b68fac69e9ab5edbf928963b87b |
|
BLAKE2b-256 | a620443744abc6c3a68b371f0c08883b96dc55cf13a536633abcf1ebc584d667 |
Hashes for nautilus_trader-1.191.0-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46f359afc4c04b5ff9d64e4a6f1e4aa16718bc47d18e9a58f5c4b796a42da678 |
|
MD5 | 06c34f2f9fe7b4205d6f0f8488c2d9e6 |
|
BLAKE2b-256 | 767f0422d4d92a9ea78d0056608dd1d4783d31ac5900c0d549b1e1c1e2caee6d |
Hashes for nautilus_trader-1.191.0-cp310-cp310-manylinux_2_31_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a28ea79d7983eeadd3d475eb827864b84113a0be232bbb6ecb0d8ac688e49dd |
|
MD5 | 7f789bbe897e542d09955813d87f32ad |
|
BLAKE2b-256 | 3016dc5f1f6ece398b836b16675c165e4d333152eec077d0ff31c6ad590ace0b |
Hashes for nautilus_trader-1.191.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e952a6047c6cb12fcc1132917d89fd41c562dc8b75ef7124a8dfea9428552434 |
|
MD5 | 32e8a2226b1403b0aa36d2eb177a335b |
|
BLAKE2b-256 | aed07953990f3da8b9a12f8fabe8f5a871b12d39da1bf746f9f2c84771bcf1ad |
Hashes for nautilus_trader-1.191.0-cp310-cp310-macosx_12_0_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f406829167fd9fc4a71404719bf17e7413df6152f763e2d364d531d9d56b033f |
|
MD5 | 2ba9b96c34ddf20627261e2d97d20baf |
|
BLAKE2b-256 | 766f133cbb347cfea64efbe5edb0fd49cb063ca461f8016c99a78216328ae21c |