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 blockchain/DeFi commands including block sync, DEX pool sync, and pool
41//! analysis.
42
43#![warn(rustc::all)]
44#![warn(clippy::pedantic)]
45#![allow(
46 clippy::manual_let_else,
47 clippy::option_if_let_else,
48 clippy::or_fun_call,
49 clippy::redundant_else,
50 clippy::similar_names,
51 clippy::single_match_else,
52 reason = "workspace policy; generated by scripts/update-clippy-allowances.py"
53)]
54#![warn(clippy::clone_on_ref_ptr)]
55#![deny(unsafe_code)]
56#![deny(unsafe_op_in_unsafe_fn)]
57#![deny(nonstandard_style)]
58#![deny(missing_debug_implementations)]
59#![deny(clippy::missing_errors_doc)]
60#![deny(clippy::missing_panics_doc)]
61#![deny(rustdoc::broken_intra_doc_links)]
62#![allow(
63 clippy::assert_is_empty,
64 reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
65)]
66
67#[cfg(feature = "defi")]
68mod blockchain;
69mod database;
70pub mod opt;
71
72use nautilus_persistence::backend::parquet::migration::{
73 ParquetMigrationConfig, migrate_parquet_catalog,
74};
75
76#[cfg(feature = "defi")]
77use crate::blockchain::run_blockchain_command;
78use crate::{
79 database::postgres::run_database_command,
80 opt::{CatalogCommand, Commands, NautilusCli},
81};
82
83/// Builds the top-level CLI command, augmented with capability-aware blockchain help.
84///
85/// The blockchain subcommands gain `after_long_help` sections derived from the adapter's DEX
86/// registration maps when the `defi` feature is enabled.
87#[must_use]
88pub fn cli_command() -> clap::Command {
89 let command = <NautilusCli as clap::CommandFactory>::command();
90 #[cfg(feature = "defi")]
91 let command = crate::blockchain::augment_blockchain_help(command);
92 command
93}
94
95/// Runs the Nautilus CLI based on the provided options.
96///
97/// # Errors
98///
99/// Returns an error if execution of the specified command fails.
100pub async fn run(opt: NautilusCli) -> anyhow::Result<()> {
101 match opt.command {
102 Commands::Catalog(catalog) => match catalog.command {
103 CatalogCommand::MigrateParquet(args) => {
104 let report = migrate_parquet_catalog(ParquetMigrationConfig {
105 source_uri: args.source,
106 target_uri: args.destination,
107 source_options: args.source_options,
108 target_options: args.target_options,
109 dry_run: args.dry_run,
110 })?;
111 println!("{report}");
112 }
113 },
114 Commands::Database(database_opt) => run_database_command(database_opt).await?,
115 #[cfg(feature = "defi")]
116 Commands::Blockchain(blockchain_opt) => {
117 Box::pin(run_blockchain_command(blockchain_opt)).await?;
118 }
119 }
120 Ok(())
121}