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.
pyenv is the recommended tool for handling Python installations and virtual environments.
poetry is the preferred tool for handling all Python package and dev 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).
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 poetry command:
poetry install
-
Set up the pre-commit hook which will then run automatically at commit:
pre-commit install
-
In case of large recompiles for small changes, configure the
PYO3_PYTHON
variable innautilus_trader/.cargo/config.toml
with the path to the Python interpreter in the poetry managed environment. This is primarily useful for Rust developers working on core and experience frequent recompiles from IDE/rust analyzer basedcargo check
.poetry shell
PYTHON_PATH=$(which python)
echo -e "\n[env]\nPYO3_PYTHON = \"$PYTHON_PATH\"" >> .cargo/config.tomlSince
.cargo/config.toml
is a tracked file, configure git to skip local modifications to it withgit update-index --skip-worktree .cargo/config.toml
. Git will still pull remote modifications. To push modifications track local modifications usinggit update-index --no-skip-worktree .cargo/config.toml
.The git hack is needed till local cargo config feature is merged.
Builds
Following any changes to .rs
, .pyx
or .pxd
files, you can re-compile by running:
poetry run 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
Services
You can use docker-compose.yml
file located in .docker
directory
to bootstrap the Nautilus working environment. This will start the following services:
docker-compose up -d
If you only want specific services running (like postgres
for example), you can start them with command:
docker-compose up -d postgres
Used services are:
postgres
: Postgres database with root userPOSTRES_USER
which defaults topostgres
,POSTGRES_PASSWORD
which defaults topass
andPOSTGRES_DB
which defaults topostgres
redis
: Redis serverpgadmin
: PgAdmin4 for database management and administration
Please use this as development environment only. For production, use a proper and more secure setup.
After the services has been started, you must log in with psql
cli to create nautilus
Postgres database.
To do that you can run, and type POSTGRES_PASSWORD
from docker service setup
psql -h localhost -p 5432 -U postgres
After you have logged in as postgres
administrator, run CREATE DATABASE
command with target db name (we use nautilus
):
psql (16.2, server 15.2 (Debian 15.2-1.pgdg110+1))
Type "help" for help.
postgres=# CREATE DATABASE nautilus;
CREATE DATABASE
Nautilus CLI Developer Guide
Introduction
The Nautilus CLI is a command-line interface tool for interacting with the NautilusTrader ecosystem. It offers commands for managing the PostgreSQL database and handling various trading operations.
The Nautilus CLI command is only supported on UNIX-like systems.
Install
You can install the Nautilus CLI using the below Makefile target, which leverages cargo install
under the hood.
This will place the nautilus binary in your system's PATH, assuming Rust's cargo
is properly configured.
make install-cli
Commands
You can run nautilus --help
to view the CLI structure and available command groups:
Database
These commands handle bootstrapping the PostgreSQL database.
To use them, you need to provide the correct connection configuration,
either through command-line arguments or a .env
file located in the root directory or the current working directory.
--host
orPOSTGRES_HOST
for the database host--port
orPOSTGRES_PORT
for the database port--user
orPOSTGRES_USER
for the root administrator (typically the postgres user)--password
orPOSTGRES_PASSWORD
for the root administrator's password--database
orPOSTGRES_DATABASE
for both the database name and the new user with privileges to that database (e.g., if you providenautilus
as the value, a new user named nautilus will be created with the password fromPOSTGRES_PASSWORD
, and thenautilus
database will be bootstrapped with this user as the owner).
Example of .env
file
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=pass
POSTGRES_DATABASE=nautilus
List of commands are:
nautilus database init
: Will bootstrap schema, roles and all sql files located inschema
root directory (liketables.sql
)nautilus database drop
: Will drop all tables, roles and data in target Postgres database