Skip to main content

nautilus_derive/python/
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
16//! Python bindings for Derive configuration.
17
18use nautilus_core::string::secret::SecretString;
19use nautilus_model::identifiers::AccountId;
20use nautilus_network::websocket::TransportBackend;
21use pyo3::pymethods;
22use rust_decimal::Decimal;
23
24use crate::{
25    common::enums::DeriveEnvironment,
26    config::{DeriveDataClientConfig, DeriveExecutionClientConfig},
27};
28
29#[pymethods]
30#[pyo3_stub_gen::derive::gen_stub_pymethods]
31impl DeriveDataClientConfig {
32    /// Configuration for the Derive data client.
33    #[new]
34    #[pyo3(signature = (
35        base_url_rest = None,
36        base_url_ws = None,
37        proxy_url = None,
38        environment = None,
39        http_timeout_secs = None,
40        ws_timeout_secs = None,
41        update_instruments_interval_mins = None,
42        currencies = None,
43        include_expired = None,
44        auto_load_missing_instruments = None,
45        transport_backend = None,
46        book_snapshot_timeout_secs = None,
47        book_stale_threshold_secs = None,
48    ))]
49    #[expect(clippy::too_many_arguments)]
50    fn py_new(
51        base_url_rest: Option<String>,
52        base_url_ws: Option<String>,
53        proxy_url: Option<String>,
54        environment: Option<DeriveEnvironment>,
55        http_timeout_secs: Option<u64>,
56        ws_timeout_secs: Option<u64>,
57        update_instruments_interval_mins: Option<u64>,
58        currencies: Option<Vec<String>>,
59        include_expired: Option<bool>,
60        auto_load_missing_instruments: Option<bool>,
61        transport_backend: Option<TransportBackend>,
62        book_snapshot_timeout_secs: Option<u64>,
63        book_stale_threshold_secs: Option<u64>,
64    ) -> Self {
65        let defaults = Self::default();
66
67        Self {
68            base_url_rest,
69            base_url_ws,
70            proxy_url: proxy_url.map(SecretString::from),
71            environment: environment.unwrap_or(defaults.environment),
72            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
73            ws_timeout_secs,
74            book_snapshot_timeout_secs: book_snapshot_timeout_secs
75                .unwrap_or(defaults.book_snapshot_timeout_secs),
76            book_stale_threshold_secs: book_stale_threshold_secs
77                .unwrap_or(defaults.book_stale_threshold_secs),
78            update_instruments_interval_mins: update_instruments_interval_mins
79                .unwrap_or(defaults.update_instruments_interval_mins),
80            currencies: currencies.unwrap_or(defaults.currencies),
81            include_expired: include_expired.unwrap_or(defaults.include_expired),
82            auto_load_missing_instruments: auto_load_missing_instruments
83                .unwrap_or(defaults.auto_load_missing_instruments),
84            transport_backend: transport_backend.unwrap_or(defaults.transport_backend),
85        }
86    }
87
88    #[getter]
89    const fn has_proxy_url(&self) -> bool {
90        self.proxy_url.is_some()
91    }
92
93    fn __repr__(&self) -> String {
94        stringify!(DeriveDataClientConfig).to_string()
95    }
96}
97
98#[pymethods]
99#[pyo3_stub_gen::derive::gen_stub_pymethods]
100impl DeriveExecutionClientConfig {
101    /// Configuration for the Derive execution client.
102    #[new]
103    #[pyo3(signature = (
104        account_id = None,
105        wallet_address = None,
106        session_key = None,
107        subaccount_id = None,
108        base_url_rest = None,
109        base_url_ws = None,
110        proxy_url = None,
111        environment = None,
112        http_timeout_secs = None,
113        max_retries = None,
114        retry_delay_initial_ms = None,
115        retry_delay_max_ms = None,
116        ws_timeout_secs = None,
117        max_fee_per_contract = None,
118        domain_separator = None,
119        action_typehash = None,
120        trade_module_address = None,
121        signature_expiry_secs = None,
122        market_order_slippage_bps = None,
123        max_matching_requests_per_second = None,
124        max_per_instrument_matching_requests_per_second = None,
125        transport_backend = None,
126    ))]
127    #[expect(clippy::too_many_arguments)]
128    fn py_new(
129        account_id: Option<AccountId>,
130        wallet_address: Option<String>,
131        session_key: Option<String>,
132        subaccount_id: Option<u64>,
133        base_url_rest: Option<String>,
134        base_url_ws: Option<String>,
135        proxy_url: Option<String>,
136        environment: Option<DeriveEnvironment>,
137        http_timeout_secs: Option<u64>,
138        max_retries: Option<u32>,
139        retry_delay_initial_ms: Option<u64>,
140        retry_delay_max_ms: Option<u64>,
141        ws_timeout_secs: Option<u64>,
142        max_fee_per_contract: Option<Decimal>,
143        domain_separator: Option<String>,
144        action_typehash: Option<String>,
145        trade_module_address: Option<String>,
146        signature_expiry_secs: Option<u64>,
147        market_order_slippage_bps: Option<u32>,
148        max_matching_requests_per_second: Option<u32>,
149        max_per_instrument_matching_requests_per_second: Option<u32>,
150        transport_backend: Option<TransportBackend>,
151    ) -> Self {
152        let defaults = Self::default();
153
154        Self {
155            account_id: account_id.unwrap_or(defaults.account_id),
156            wallet_address,
157            session_key: session_key.map(SecretString::from),
158            subaccount_id,
159            base_url_rest,
160            base_url_ws,
161            proxy_url: proxy_url.map(SecretString::from),
162            environment: environment.unwrap_or(defaults.environment),
163            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
164            max_retries: max_retries.unwrap_or(defaults.max_retries),
165            retry_delay_initial_ms: retry_delay_initial_ms
166                .unwrap_or(defaults.retry_delay_initial_ms),
167            retry_delay_max_ms: retry_delay_max_ms.unwrap_or(defaults.retry_delay_max_ms),
168            ws_timeout_secs,
169            max_fee_per_contract,
170            transport_backend: transport_backend.unwrap_or(defaults.transport_backend),
171            domain_separator,
172            action_typehash,
173            trade_module_address,
174            signature_expiry_secs: signature_expiry_secs.unwrap_or(defaults.signature_expiry_secs),
175            market_order_slippage_bps: market_order_slippage_bps
176                .unwrap_or(defaults.market_order_slippage_bps),
177            max_matching_requests_per_second,
178            max_per_instrument_matching_requests_per_second,
179        }
180    }
181
182    #[getter]
183    const fn has_proxy_url(&self) -> bool {
184        self.proxy_url.is_some()
185    }
186
187    fn __repr__(&self) -> String {
188        stringify!(DeriveExecutionClientConfig).to_string()
189    }
190}