nautilus_blockchain/
config.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 nautilus_infrastructure::sql::pg::PostgresConnectOptions;
17use nautilus_model::defi::{DexType, SharedChain};
18
19/// Defines filtering criteria for the DEX pool universe that the data client will operate on.
20#[derive(Debug, Clone)]
21#[cfg_attr(
22    feature = "python",
23    pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.blockchain")
24)]
25#[cfg_attr(
26    feature = "python",
27    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.blockchain")
28)]
29pub struct DexPoolFilters {
30    /// Whether to exclude pools containing tokens with empty name or symbol fields.
31    pub remove_pools_with_empty_erc20fields: bool,
32}
33
34impl DexPoolFilters {
35    /// Creates a new [`DexPoolFilters`] instance.
36    #[must_use]
37    pub fn new(remove_pools_with_empty_erc20fields: Option<bool>) -> Self {
38        Self {
39            remove_pools_with_empty_erc20fields: remove_pools_with_empty_erc20fields
40                .unwrap_or(true),
41        }
42    }
43}
44
45impl Default for DexPoolFilters {
46    fn default() -> Self {
47        Self {
48            remove_pools_with_empty_erc20fields: true,
49        }
50    }
51}
52
53/// Configuration for blockchain data clients.
54#[derive(Debug, Clone)]
55#[cfg_attr(
56    feature = "python",
57    pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.blockchain")
58)]
59#[cfg_attr(
60    feature = "python",
61    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.adapters.blockchain")
62)]
63pub struct BlockchainDataClientConfig {
64    /// The blockchain chain configuration.
65    pub chain: SharedChain,
66    /// List of decentralized exchange IDs to register and sync during connection.
67    pub dex_ids: Vec<DexType>,
68    /// Determines if the client should use Hypersync for live data streaming.
69    pub use_hypersync_for_live_data: bool,
70    /// The HTTP URL for the blockchain RPC endpoint.
71    pub http_rpc_url: String,
72    /// The maximum number of RPC requests allowed per second.
73    pub rpc_requests_per_second: Option<u32>,
74    /// The maximum number of Multicall calls per one RPC request.
75    pub multicall_calls_per_rpc_request: u32,
76    /// The WebSocket secure URL for the blockchain RPC endpoint.
77    pub wss_rpc_url: Option<String>,
78    /// The block from which to sync historical data.
79    pub from_block: Option<u64>,
80    /// Filtering criteria that define which DEX pools to include in the data universe.
81    pub pool_filters: DexPoolFilters,
82    /// Optional configuration for data client's Postgres cache database
83    pub postgres_cache_database_config: Option<PostgresConnectOptions>,
84}
85
86impl BlockchainDataClientConfig {
87    /// Creates a new [`BlockchainDataClientConfig`] instance.
88    #[allow(clippy::too_many_arguments)]
89    #[must_use]
90    pub fn new(
91        chain: SharedChain,
92        dex_ids: Vec<DexType>,
93        http_rpc_url: String,
94        rpc_requests_per_second: Option<u32>,
95        multicall_calls_per_rpc_request: Option<u32>,
96        wss_rpc_url: Option<String>,
97        use_hypersync_for_live_data: bool,
98        from_block: Option<u64>,
99        pools_filters: Option<DexPoolFilters>,
100        postgres_cache_database_config: Option<PostgresConnectOptions>,
101    ) -> Self {
102        Self {
103            chain,
104            dex_ids,
105            use_hypersync_for_live_data,
106            http_rpc_url,
107            rpc_requests_per_second,
108            multicall_calls_per_rpc_request: multicall_calls_per_rpc_request.unwrap_or(100),
109            wss_rpc_url,
110            from_block,
111            pool_filters: pools_filters.unwrap_or_default(),
112            postgres_cache_database_config,
113        }
114    }
115}