nautilus_blockchain/config.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
16use std::any::Any;
17
18use nautilus_common::factories::ClientConfig;
19use nautilus_infrastructure::sql::pg::PostgresConnectOptions;
20use nautilus_model::{
21 defi::{Chain, DexType, SharedChain},
22 identifiers::{AccountId, TraderId},
23};
24use nautilus_network::websocket::TransportBackend;
25
26/// Defines filtering criteria for the DEX pool universe that the data client will operate on.
27#[derive(Debug, Clone, bon::Builder)]
28#[cfg_attr(
29 feature = "python",
30 pyo3::pyclass(
31 module = "nautilus_trader.core.nautilus_pyo3.blockchain",
32 from_py_object
33 )
34)]
35#[cfg_attr(
36 feature = "python",
37 pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.blockchain")
38)]
39pub struct DexPoolFilters {
40 /// Whether to exclude pools containing tokens with empty name or symbol fields.
41 #[builder(default = true)]
42 pub remove_pools_with_empty_erc20fields: bool,
43}
44
45impl Default for DexPoolFilters {
46 fn default() -> Self {
47 Self::builder().build()
48 }
49}
50
51/// Configuration for blockchain data clients.
52#[derive(Debug, Clone, bon::Builder)]
53#[cfg_attr(
54 feature = "python",
55 pyo3::pyclass(
56 module = "nautilus_trader.core.nautilus_pyo3.blockchain",
57 from_py_object
58 )
59)]
60#[cfg_attr(
61 feature = "python",
62 pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.blockchain")
63)]
64pub struct BlockchainDataClientConfig {
65 /// The blockchain chain configuration.
66 pub chain: SharedChain,
67 /// List of decentralized exchange IDs to register and sync during connection.
68 #[builder(default)]
69 pub dex_ids: Vec<DexType>,
70 /// Determines if the client should use Hypersync for live data streaming.
71 #[builder(default)]
72 pub use_hypersync_for_live_data: bool,
73 /// The HTTP URL for the blockchain RPC endpoint.
74 pub http_rpc_url: String,
75 /// The maximum number of RPC requests allowed per second.
76 pub rpc_requests_per_second: Option<u32>,
77 /// The maximum number of Multicall calls per one RPC request.
78 #[builder(default = 200)]
79 pub multicall_calls_per_rpc_request: u32,
80 /// The WebSocket secure URL for the blockchain RPC endpoint.
81 pub wss_rpc_url: Option<String>,
82 /// Optional proxy URL for HTTP and WebSocket transports.
83 pub proxy_url: Option<String>,
84 /// The block from which to sync historical data.
85 pub from_block: Option<u64>,
86 /// Filtering criteria that define which DEX pools to include in the data universe.
87 #[builder(default)]
88 pub pool_filters: DexPoolFilters,
89 /// Optional configuration for data client's Postgres cache database
90 pub postgres_cache_database_config: Option<PostgresConnectOptions>,
91 /// WebSocket transport backend (defaults to `Tungstenite`).
92 #[builder(default)]
93 pub transport_backend: TransportBackend,
94}
95
96#[derive(Debug, Clone, bon::Builder)]
97pub struct BlockchainExecutionClientConfig {
98 /// The trader ID for the client.
99 pub trader_id: TraderId,
100 /// The account ID for the client.
101 pub client_id: AccountId,
102 /// The blockchain chain configuration.
103 pub chain: Chain,
104 /// The wallet address of the execution client.
105 pub wallet_address: String,
106 /// Token universe: set of ERC-20 token addresses to monitor for balance tracking.
107 pub tokens: Option<Vec<String>>,
108 /// The HTTP URL for the blockchain RPC endpoint.
109 pub http_rpc_url: String,
110 /// The maximum number of RPC requests allowed per second.
111 pub rpc_requests_per_second: Option<u32>,
112 /// WebSocket transport backend (defaults to `Tungstenite`).
113 #[builder(default)]
114 pub transport_backend: TransportBackend,
115}
116
117impl ClientConfig for BlockchainExecutionClientConfig {
118 fn as_any(&self) -> &dyn Any {
119 self
120 }
121}