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/// Command-line interface for NautilusTrader.
19#[derive(Debug, Parser)]
20#[clap(version, about, author)]
21pub struct NautilusCli {
22    #[clap(subcommand)]
23    pub command: Commands,
24}
25
26/// Available top-level commands for the NautilusTrader CLI.
27#[derive(Parser, Debug)]
28pub enum Commands {
29    Database(DatabaseOpt),
30    #[cfg(feature = "defi")]
31    Blockchain(BlockchainOpt),
32}
33
34/// Database management options and subcommands.
35#[derive(Parser, Debug)]
36#[command(about = "Postgres database operations", long_about = None)]
37pub struct DatabaseOpt {
38    #[clap(subcommand)]
39    pub command: DatabaseCommand,
40}
41
42/// Configuration parameters for database connection and operations.
43#[derive(Parser, Debug, Clone)]
44pub struct DatabaseConfig {
45    /// Hostname or IP address of the database server.
46    #[arg(long)]
47    pub host: Option<String>,
48    /// Port number of the database server.
49    #[arg(long)]
50    pub port: Option<u16>,
51    /// Username for connecting to the database.
52    #[arg(long)]
53    pub username: Option<String>,
54    /// Name of the database.
55    #[arg(long)]
56    pub database: Option<String>,
57    /// Password for connecting to the database.
58    #[arg(long)]
59    pub password: Option<String>,
60    /// Directory path to the schema files.
61    #[arg(long)]
62    pub schema: Option<String>,
63}
64
65/// Available database management commands.
66#[derive(Parser, Debug, Clone)]
67#[command(about = "Postgres database operations", long_about = None)]
68pub enum DatabaseCommand {
69    /// Initializes a new Postgres database with the latest schema.
70    Init(DatabaseConfig),
71    /// Drops roles, privileges and deletes all data from the database.
72    Drop(DatabaseConfig),
73}
74
75#[cfg(feature = "defi")]
76/// Blockchain management options and subcommands.
77#[derive(Parser, Debug)]
78#[command(about = "Blockchain operations", long_about = None)]
79pub struct BlockchainOpt {
80    #[clap(subcommand)]
81    pub command: BlockchainCommand,
82}
83
84#[cfg(feature = "defi")]
85/// Available blockchain management commands.
86#[derive(Parser, Debug, Clone)]
87#[command(about = "Blockchain operations", long_about = None)]
88pub enum BlockchainCommand {
89    /// Syncs blockchain blocks.
90    SyncBlocks {
91        /// The blockchain chain name (case-insensitive). Examples: ethereum, arbitrum, base, polygon, bsc
92        #[arg(long)]
93        chain: String,
94        /// Starting block number to sync from (optional)
95        #[arg(long)]
96        from_block: Option<u64>,
97        /// Ending block number to sync to (optional, defaults to current chain head)
98        #[arg(long)]
99        to_block: Option<u64>,
100        /// Database configuration options
101        #[clap(flatten)]
102        database: DatabaseConfig,
103    },
104    /// Sync DEX pools.
105    SyncDex {
106        /// The blockchain chain name (case-insensitive). Examples: ethereum, arbitrum, base, polygon, bsc
107        #[arg(long)]
108        chain: String,
109        /// The DEX name (case-insensitive). Examples: `UniswapV3`, uniswapv3, `SushiSwapV2`, `PancakeSwapV3`
110        #[arg(long)]
111        dex: String,
112        /// RPC HTTP URL for blockchain calls (optional, falls back to `RPC_HTTP_URL` env var)
113        #[arg(long)]
114        rpc_url: Option<String>,
115        /// Reset sync progress and start from the beginning, ignoring last synced block
116        #[arg(long)]
117        reset: bool,
118        /// Maximum number of Multicall calls per RPC request (optional, defaults to 100)
119        #[arg(long)]
120        multicall_calls_per_rpc_request: Option<u32>,
121        /// Database configuration options
122        #[clap(flatten)]
123        database: DatabaseConfig,
124    },
125    /// Analyze a specific DEX pool.
126    AnalyzePool {
127        /// The blockchain chain name (case-insensitive). Examples: ethereum, arbitrum, base, polygon, bsc
128        #[arg(long)]
129        chain: String,
130        /// The DEX name (case-insensitive). Examples: UniswapV3, uniswapv3, SushiSwapV2, PancakeSwapV3
131        #[arg(long)]
132        dex: String,
133        /// The pool contract address
134        #[arg(long)]
135        address: String,
136        /// Starting block number to sync from (optional)
137        #[arg(long)]
138        from_block: Option<u64>,
139        /// Ending block number to sync to (optional, defaults to current chain head)
140        #[arg(long)]
141        to_block: Option<u64>,
142        /// RPC HTTP URL for blockchain calls (optional, falls back to RPC_HTTP_URL env var)
143        #[arg(long)]
144        rpc_url: Option<String>,
145        /// Reset sync progress and start from the beginning, ignoring last synced block
146        #[arg(long)]
147        reset: bool,
148        /// Maximum number of Multicall calls per RPC request (optional, defaults to 100)
149        #[arg(long)]
150        multicall_calls_per_rpc_request: Option<u32>,
151        /// Database configuration options
152        #[clap(flatten)]
153        database: DatabaseConfig,
154    },
155}