Environment Setup - Loren1166/NautilusTrader- GitHub Wiki
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. 我们建议使用 PyCharm Professional edition IDE 进行开发,因为它可以解释 Cython 语法。或者,您可以使用 Visual Studio Code 和 Cython 扩展。
pyenv is the recommended tool for handling Python installations and virtual environments. pyenv 是处理 Python 安装和虚拟环境的推荐工具。
poetry is the preferred tool for handling all Python package and dev dependencies. poetry 是处理所有 Python 包和开发依赖项的首选工具。
pre-commit is used to automatically run various checks, auto-formatters and linting tools at commit. pre-commit 用于在提交时自动运行各种检查、自动格式化程序和 linting 工具。
NautilusTrader uses increasingly more Rust, so Rust should be installed on your system as well (installation guide). NautilusTrader 越来越多地使用 Rust,因此也应该在您的系统上安装 Rust(安装指南)。
Setup | 设置
The following steps are for UNIX-like systems, and only need to be completed once. 以下步骤适用于类 UNIX 系统,并且只需要完成一次。
Follow the installation guide to set up the project with a modification to the final poetry command: 按照安装指南设置项目,并对最终的 poetry 命令进行修改:
poetry install
Set up the pre-commit hook which will then run automatically at commit: 设置 pre-commit 钩子,它将在提交时自动运行:
pre-commit install
In case of large recompiles for small changes, configure the PYO3_PYTHON variable in nautilus_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 based cargo check. 如果对小的更改进行大型重新编译,请使用 poetry 管理环境中 Python 解释器的路径配置 nautilus_trader/.cargo/config.toml 中的 PYO3_PYTHON 变量。这主要对使用核心并经历基于 IDE/rust 分析器的 cargo check 频繁重新编译的 Rust 开发人员有用。
poetry shell
PYTHON_PATH=$(which python)
echo -e "\n[env]\nPYO3_PYTHON = \"$PYTHON_PATH\"" >> .cargo/config.toml
Since .cargo/config.toml is a tracked file, configure git to skip local modifications to it with git update-index --skip-worktree .cargo/config.toml. Git will still pull remote modifications. To push modifications track local modifications using git update-index --no-skip-worktree .cargo/config.toml. 由于 .cargo/config.toml 是一个跟踪文件,请将 git 配置为使用 git update-index --skip-worktree .cargo/config.toml 跳过对其的本地修改。Git 仍然会拉取远程修改。要推送修改,请使用 git update-index --no-skip-worktree .cargo/config.toml 跟踪本地修改。
The git hack is needed till local cargo config feature is merged. 在合并本地 cargo 配置功能之前,需要使用 git hack。
Builds | 构建
Following any changes to .pyx or .pxd files, you can re-compile by running: 在对 .pyx 或 .pxd 文件进行任何更改之后,您可以通过运行以下命令重新编译:
poetry run python build.py
or 或者
make build
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 目录中的 docker-compose.yml 文件来引导 Nautilus 工作环境。这将启动以下服务:
docker-compose up -d
If you only want specific services running (like postgres for example), you can start them with command: 如果只想运行特定服务(例如 postgres),可以使用以下命令启动它们:
docker-compose up -d postgres
Used services are: 使用的服务是:
- postgres: Postgres database with root user POSTRES_USER which defaults to postgres, POSTGRES_PASSWORD which defaults to pass and POSTGRES_DB which defaults to postgres postgres:Postgres 数据库,具有 root 用户 POSTRES_USER,默认为 postgres,POSTGRES_PASSWORD 默认为 pass,POSTGRES_DB 默认为 postgres
- redis: Redis server redis:Redis 服务器
- pgadmin: PgAdmin4 for database management and administration pgadmin:PgAdmin4,用于数据库管理
Note: 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 cli 登录以创建 nautilus Postgres 数据库。为此,您可以运行并从 docker 服务设置中键入 POSTGRES_PASSWORD
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): 以 postgres 管理员身份登录后,使用目标数据库名称(我们使用 nautilus)运行 CREATE DATABASE 命令:
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 | Nautilus CLI 开发者指南
Introduction | 简介
The Nautilus CLI is a command-line interface tool designed to interact with the Nautilus Trader ecosystem. It provides commands for managing the Postgres database and other trading operations. Nautilus CLI 是一种命令行界面工具,旨在与 Nautilus Trader 生态系统交互。它提供了用于管理 Postgres 数据库和其他交易操作的命令。
Note: The Nautilus CLI command is only supported on UNIX-like systems. 注意:Nautilus CLI 命令仅在类 UNIX 系统上受支持。
Install | 安装
You can install nautilus cli command with from Make file target, which will use cargo install under the hood. And this command will install nautilus bin executable in your path if Rust cargo is properly configured. 您可以使用 Makefile 目标安装 nautilus cli 命令,该目标将在后台使用 cargo install。如果 Rust cargo 配置正确,此命令将在您的路径中安装 nautilus bin 可执行文件。
make install-cli
Commands | 命令
You can run nautilus --help to inspect structure of CLI and groups of commands: 您可以运行 nautilus --help 来检查 CLI 的结构和命令组:
Database | 数据库
These are commands related to the bootstrapping the Postgres database. For that you work, you need to supply right connection configuration. You can do that through command line arguments or .env file in the root directory or where the commands is being run. 这些命令与引导 Postgres 数据库相关。为此,您需要提供正确的连接配置。您可以通过命令行参数或根目录中或运行命令的位置的 .env 文件来完成此操作。
- --host arg or POSTGRES_HOST for database host --host arg 或 POSTGRES_HOST 用于数据库主机
- --port arg or POSTGRES_PORT for database port --port arg 或 POSTGRES_PORT 用于数据库端口
- --user arg or POSTGRES_USER for root administrator user to run command with (namely postgres root user here) --user arg 或 POSTGRES_USER 用于运行命令的 root 管理员用户(此处即为 postgres root 用户)
- --password arg or POSTGRES_PASSWORD for root administrator password --password arg 或 POSTGRES_PASSWORD 用于 root 管理员密码
- --database arg or POSTGRES_DATABASE for both database name and new user that will have privileges of this database ( if you provided nautilus as value, then new user will be created with name nautilus that will inherit the password from POSTGRES_PASSWORD and nautilus database with be bootstrapped with this user as owner) --database arg 或 POSTGRES_DATABASE 用于数据库名称和将拥有此数据库权限的新用户(如果您提供 nautilus 作为值,则将创建一个名为 nautilus 的新用户,该用户将继承 POSTGRES_PASSWORD 的密码,并且 nautilus 数据库将以该用户作为所有者进行引导)
Example of .env file .env 文件示例
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USERNAME=postgres
POSTGRES_DATABASE=nautilus
POSTGRES_PASSWORD=pass
List of commands are: 命令列表如下:
- nautilus database init: Will bootstrap schema, roles and all sql files located in schema root directory (like tables.sql) nautilus database init:将引导架构、角色和位于架构根目录中的所有 sql 文件(如 tables.sql)
- nautilus database drop: Will drop all tables, role and data in target Postgres database nautilus database drop:将删除目标 Postgres 数据库中的所有表、角色和数据