nautilus_blockchain/python/
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
16//! Python bindings for blockchain configuration.
17
18use std::sync::Arc;
19
20use nautilus_infrastructure::sql::pg::PostgresConnectOptions;
21use nautilus_model::defi::{Chain, DexType};
22use pyo3::prelude::*;
23
24use crate::config::{BlockchainDataClientConfig, DexPoolFilters};
25
26#[pymethods]
27impl DexPoolFilters {
28    /// Creates a new `DexPoolFilters` instance.
29    #[new]
30    #[must_use]
31    pub fn py_new(remove_pools_with_empty_erc20_fields: Option<bool>) -> Self {
32        Self::new(remove_pools_with_empty_erc20_fields)
33    }
34}
35
36#[pymethods]
37impl BlockchainDataClientConfig {
38    /// Creates a new `BlockchainDataClientConfig` instance.
39    #[new]
40    #[allow(clippy::too_many_arguments)]
41    #[pyo3(signature = (chain, dex_ids, http_rpc_url, rpc_requests_per_second=None, multicall_calls_per_rpc_request=None, wss_rpc_url=None, use_hypersync_for_live_data=true, from_block=None, pool_filters=None, postgres_cache_database_config=None))]
42    fn py_new(
43        chain: &Chain,
44        dex_ids: Vec<DexType>,
45        http_rpc_url: String,
46        rpc_requests_per_second: Option<u32>,
47        multicall_calls_per_rpc_request: Option<u32>,
48        wss_rpc_url: Option<String>,
49        use_hypersync_for_live_data: bool,
50        from_block: Option<u64>,
51        pool_filters: Option<DexPoolFilters>,
52        postgres_cache_database_config: Option<PostgresConnectOptions>,
53    ) -> Self {
54        Self::new(
55            Arc::new(chain.clone()),
56            dex_ids,
57            http_rpc_url,
58            rpc_requests_per_second,
59            multicall_calls_per_rpc_request,
60            wss_rpc_url,
61            use_hypersync_for_live_data,
62            from_block,
63            pool_filters,
64            postgres_cache_database_config,
65        )
66    }
67
68    /// Returns the chain configuration.
69    #[getter]
70    fn chain(&self) -> Chain {
71        (*self.chain).clone()
72    }
73
74    /// Returns the HTTP RPC URL.
75    #[getter]
76    fn http_rpc_url(&self) -> String {
77        self.http_rpc_url.clone()
78    }
79
80    /// Returns the WebSocket RPC URL.
81    #[getter]
82    fn wss_rpc_url(&self) -> Option<String> {
83        self.wss_rpc_url.clone()
84    }
85
86    /// Returns the RPC requests per second limit.
87    #[getter]
88    const fn rpc_requests_per_second(&self) -> Option<u32> {
89        self.rpc_requests_per_second
90    }
91
92    /// Returns whether to use HyperSync for live data.
93    #[getter]
94    const fn use_hypersync_for_live_data(&self) -> bool {
95        self.use_hypersync_for_live_data
96    }
97
98    /// Returns the starting block for sync.
99    #[getter]
100    #[allow(clippy::wrong_self_convention)]
101    const fn from_block(&self) -> Option<u64> {
102        self.from_block
103    }
104
105    /// Returns a string representation of the configuration.
106    fn __repr__(&self) -> String {
107        format!(
108            "BlockchainDataClientConfig(chain={:?}, http_rpc_url={}, wss_rpc_url={:?}, use_hypersync_for_live_data={}, from_block={:?})",
109            self.chain.name,
110            self.http_rpc_url,
111            self.wss_rpc_url,
112            self.use_hypersync_for_live_data,
113            self.from_block
114        )
115    }
116}