Skip to main content

nautilus_cli/
lib.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Command-line interface and tools for [NautilusTrader](https://nautilustrader.io).
17//!
18//! The `nautilus-cli` crate provides a command-line interface for managing and
19//! operating NautilusTrader installations. It includes tools for database management,
20//! system configuration, and operational utilities:
21//!
22//! - Database initialization and management commands.
23//! - PostgreSQL schema setup and maintenance.
24//! - Configuration validation and setup utilities.
25//! - System administration and operational tools.
26//!
27//! # NautilusTrader
28//!
29//! [NautilusTrader](https://nautilustrader.io) is an open-source, production-grade, Rust-native
30//! engine for multi-asset, multi-venue trading systems.
31//!
32//! The system spans research, deterministic simulation, and live execution within a single
33//! event-driven architecture, providing research-to-live semantic parity.
34//!
35//! # Feature Flags
36//!
37//! This crate provides feature flags to control source code inclusion during compilation,
38//! depending on the intended use case:
39//!
40//! - `defi`: Enables DeFi functionality including blockchain data access and pool analysis.
41
42#![warn(rustc::all)]
43#![warn(clippy::pedantic)]
44#![deny(unsafe_code)]
45#![deny(unsafe_op_in_unsafe_fn)]
46#![deny(nonstandard_style)]
47#![deny(missing_debug_implementations)]
48#![deny(clippy::missing_errors_doc)]
49#![deny(clippy::missing_panics_doc)]
50#![deny(rustdoc::broken_intra_doc_links)]
51
52#[cfg(feature = "defi")]
53mod blockchain;
54mod database;
55pub mod opt;
56
57#[cfg(feature = "defi")]
58use crate::blockchain::run_blockchain_command;
59use crate::{
60    database::postgres::run_database_command,
61    opt::{Commands, NautilusCli},
62};
63
64/// Builds the top-level CLI command, augmented with capability-aware blockchain help.
65///
66/// The blockchain subcommands gain `after_long_help` sections derived from the adapter's DEX
67/// registration maps when the `defi` feature is enabled.
68#[must_use]
69pub fn cli_command() -> clap::Command {
70    let command = <NautilusCli as clap::CommandFactory>::command();
71    #[cfg(feature = "defi")]
72    let command = crate::blockchain::augment_blockchain_help(command);
73    command
74}
75
76/// Runs the Nautilus CLI based on the provided options.
77///
78/// # Errors
79///
80/// Returns an error if execution of the specified command fails.
81pub async fn run(opt: NautilusCli) -> anyhow::Result<()> {
82    match opt.command {
83        Commands::Database(database_opt) => run_database_command(database_opt).await?,
84        #[cfg(feature = "defi")]
85        Commands::Blockchain(blockchain_opt) => {
86            Box::pin(run_blockchain_command(blockchain_opt)).await?;
87        }
88    }
89    Ok(())
90}