nautilus_cli/opt.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 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
16use clap::Parser;
17
18/// Main CLI structure for parsing command-line arguments and options.
19///
20/// This is the entry point for the NautilusTrader command-line interface,
21/// providing access to various system management and operational commands.
22#[derive(Debug, Parser)]
23#[clap(version, about, author)]
24pub struct NautilusCli {
25 #[clap(subcommand)]
26 pub command: Commands,
27}
28
29/// Available top-level commands for the NautilusTrader CLI.
30#[derive(Parser, Debug)]
31pub enum Commands {
32 Database(DatabaseOpt),
33 #[cfg(feature = "hypersync")]
34 Blockchain(BlockchainOpt),
35}
36
37/// Database management options and subcommands.
38#[derive(Parser, Debug)]
39#[command(about = "Postgres database operations", long_about = None)]
40pub struct DatabaseOpt {
41 #[clap(subcommand)]
42 pub command: DatabaseCommand,
43}
44
45/// Configuration parameters for database connection and operations.
46#[derive(Parser, Debug, Clone)]
47pub struct DatabaseConfig {
48 /// Hostname or IP address of the database server.
49 #[arg(long)]
50 pub host: Option<String>,
51 /// Port number of the database server.
52 #[arg(long)]
53 pub port: Option<u16>,
54 /// Username for connecting to the database.
55 #[arg(long)]
56 pub username: Option<String>,
57 /// Name of the database.
58 #[arg(long)]
59 pub database: Option<String>,
60 /// Password for connecting to the database.
61 #[arg(long)]
62 pub password: Option<String>,
63 /// Directory path to the schema files.
64 #[arg(long)]
65 pub schema: Option<String>,
66}
67
68/// Available database management commands.
69#[derive(Parser, Debug, Clone)]
70#[command(about = "Postgres database operations", long_about = None)]
71pub enum DatabaseCommand {
72 /// Initializes a new Postgres database with the latest schema.
73 Init(DatabaseConfig),
74 /// Drops roles, privileges and deletes all data from the database.
75 Drop(DatabaseConfig),
76}
77
78#[cfg(feature = "hypersync")]
79/// Blockchain management options and subcommands.
80#[derive(Parser, Debug)]
81#[command(about = "Blockchain operations", long_about = None)]
82pub struct BlockchainOpt {
83 #[clap(subcommand)]
84 pub command: BlockchainCommand,
85}
86
87#[cfg(feature = "hypersync")]
88/// Available blockchain management commands.
89#[derive(Parser, Debug, Clone)]
90#[command(about = "Blockchain operations", long_about = None)]
91pub enum BlockchainCommand {
92 /// Syncs blockchain blocks.
93 SyncBlocks {
94 /// The blockchain chain name (case-insensitive). Examples: ethereum, arbitrum, base, polygon, bsc
95 #[arg(long)]
96 chain: String,
97 /// Starting block number to sync from (optional)
98 #[arg(long)]
99 from_block: Option<u64>,
100 /// Ending block number to sync to (optional, defaults to current chain head)
101 #[arg(long)]
102 to_block: Option<u64>,
103 /// Database configuration options
104 #[clap(flatten)]
105 database: DatabaseConfig,
106 },
107 /// Sync DEX pools.
108 SyncDex {
109 /// The blockchain chain name (case-insensitive). Examples: ethereum, arbitrum, base, polygon, bsc
110 #[arg(long)]
111 chain: String,
112 /// The DEX name (case-insensitive). Examples: `UniswapV3`, uniswapv3, `SushiSwapV2`, `PancakeSwapV3`
113 #[arg(long)]
114 dex: String,
115 /// RPC HTTP URL for blockchain calls (optional, falls back to `RPC_HTTP_URL` env var)
116 #[arg(long)]
117 rpc_url: Option<String>,
118 /// Reset sync progress and start from the beginning, ignoring last synced block
119 #[arg(long)]
120 reset: bool,
121 /// Database configuration options
122 #[clap(flatten)]
123 database: DatabaseConfig,
124 },
125}