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