Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nautilus CLI #1602

Merged
merged 5 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: '3.5'

services:
postgres:
container_name: nautilus-database
image: postgres
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-pass}
POSTGRES_DATABASE: ${POSTGRES_DATABASE:-postgres}
PGDATA: /data/postgres
volumes:
- nautilus-database:/data/postgres
ports:
- "5432:5432"
networks:
- nautilus-network
restart: unless-stopped

pgadmin:
container_name: nautilus-pgadmin
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:[email protected]}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
volumes:
- pgadmin:/root/.pgadmin
ports:
- "${PGADMIN_PORT:-5051}:80"
networks:
- nautilus-network
restart: unless-stopped

redis:
container_name: nautilus-redis
image: redis
ports:
- 6379:6379
restart: unless-stopped
networks:
- nautilus-network

networks:
nautilus-network:

volumes:
nautilus-database:
pgadmin:
9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,8 @@ test-examples:
install-talib:
bash scripts/install-talib.sh

.PHONY: init-db
init-db:
(cd nautilus_core && cargo run --bin init-db)
.PHONY: install-cli
install-cli:
(cd nautilus_core && cargo install --path cli --bin nautilus)

.PHONY: drop-db
drop-db:
(cd nautilus_core && cargo run --bin drop-db)

90 changes: 90 additions & 0 deletions docs/developer_guide/environment_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,93 @@ Following any changes to `.pyx` or `.pxd` files, you can re-compile by running:
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:

```bash
docker-compose up -d
```

If you only want specific services running (like `postgres` for example), you can start them with command:

```bash
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`
- `redis` - Redis server
- `pgadmin` - PgAdmin4 for database management and administration

> **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

```bash
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 designed to interact
with the Nautilus Trader ecosystem. It provides commands for managing the Postgres database and other trading operations.

> **Note:** The Nautilus CLI command is only supported on UNIX-like systems.


## 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.

```bash
make install-cli
```

## Commands
You can run `nautilus --help` to inspect structure of CLI and groups of commands:

### 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.

- `--host` arg or `POSTGRES_HOST` for database host
- `--port` arg or `POSTGRES_PORT` for database port
- `--user` arg or `POSTGRES_USER` for root administrator user to run command with (namely `postgres` root user here)
- `--password` arg or `POSTGRES_PASSWORD` for root administrator password
- `--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)

Example of `.env` file

```
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USERNAME=postgres
POSTGRES_DATABASE=nautilus
POSTGRES_PASSWORD=pass
```

List of commands are:

1. `nautilus database init` - it will bootstrap schema, roles and all sql files located in `schema` root directory (like `tables.sql`)
2. `nautilus database drop` - it will drop all tables, role and data in target Postgres database
130 changes: 128 additions & 2 deletions nautilus_core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions nautilus_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"network/tokio-tungstenite",
"persistence",
"pyo3",
"cli"
]

[workspace.package]
Expand Down Expand Up @@ -49,6 +50,7 @@ tracing = "0.1.40"
tokio = { version = "1.37.0", features = ["full"] }
ustr = { version = "1.0.0", features = ["serde"] }
uuid = { version = "1.8.0", features = ["v4"] }
sqlx = { version = "0.7.4", features = ["postgres", "runtime-tokio"] }

# dev-dependencies
criterion = "0.5.1"
Expand Down
Loading