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 live 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    ))]
47    #[expect(clippy::too_many_arguments)]
48    fn py_new(
49        base_url_rest: Option<String>,
50        base_url_ws: Option<String>,
51        proxy_url: Option<String>,
52        environment: Option<DeriveEnvironment>,
53        http_timeout_secs: Option<u64>,
54        ws_timeout_secs: Option<u64>,
55        update_instruments_interval_mins: Option<u64>,
56        currencies: Option<Vec<String>>,
57        include_expired: Option<bool>,
58        auto_load_missing_instruments: Option<bool>,
59        transport_backend: Option<TransportBackend>,
60    ) -> Self {
61        let defaults = Self::default();
62        Self {
63            base_url_rest,
64            base_url_ws,
65            proxy_url: proxy_url.map(SecretString::from),
66            environment: environment.unwrap_or(defaults.environment),
67            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
68            ws_timeout_secs,
69            update_instruments_interval_mins: update_instruments_interval_mins
70                .unwrap_or(defaults.update_instruments_interval_mins),
71            currencies: currencies.unwrap_or(defaults.currencies),
72            include_expired: include_expired.unwrap_or(defaults.include_expired),
73            auto_load_missing_instruments: auto_load_missing_instruments
74                .unwrap_or(defaults.auto_load_missing_instruments),
75            transport_backend: transport_backend.unwrap_or(defaults.transport_backend),
76        }
77    }
78
79    #[getter]
80    const fn has_proxy_url(&self) -> bool {
81        self.proxy_url.is_some()
82    }
83
84    fn __repr__(&self) -> String {
85        stringify!(DeriveDataClientConfig).to_string()
86    }
87}
88
89#[pymethods]
90#[pyo3_stub_gen::derive::gen_stub_pymethods]
91impl DeriveExecutionClientConfig {
92    /// Configuration for the Derive live execution client.
93    #[new]
94    #[pyo3(signature = (
95        account_id = None,
96        wallet_address = None,
97        session_key = None,
98        subaccount_id = None,
99        base_url_rest = None,
100        base_url_ws = None,
101        proxy_url = None,
102        environment = None,
103        http_timeout_secs = None,
104        max_retries = None,
105        retry_delay_initial_ms = None,
106        retry_delay_max_ms = None,
107        ws_timeout_secs = None,
108        max_fee_per_contract = None,
109        domain_separator = None,
110        action_typehash = None,
111        trade_module_address = None,
112        signature_expiry_secs = None,
113        market_order_slippage_bps = None,
114        max_matching_requests_per_second = None,
115        max_per_instrument_matching_requests_per_second = None,
116        transport_backend = None,
117    ))]
118    #[expect(clippy::too_many_arguments)]
119    fn py_new(
120        account_id: Option<AccountId>,
121        wallet_address: Option<String>,
122        session_key: Option<String>,
123        subaccount_id: Option<u64>,
124        base_url_rest: Option<String>,
125        base_url_ws: Option<String>,
126        proxy_url: Option<String>,
127        environment: Option<DeriveEnvironment>,
128        http_timeout_secs: Option<u64>,
129        max_retries: Option<u32>,
130        retry_delay_initial_ms: Option<u64>,
131        retry_delay_max_ms: Option<u64>,
132        ws_timeout_secs: Option<u64>,
133        max_fee_per_contract: Option<Decimal>,
134        domain_separator: Option<String>,
135        action_typehash: Option<String>,
136        trade_module_address: Option<String>,
137        signature_expiry_secs: Option<u64>,
138        market_order_slippage_bps: Option<u32>,
139        max_matching_requests_per_second: Option<u32>,
140        max_per_instrument_matching_requests_per_second: Option<u32>,
141        transport_backend: Option<TransportBackend>,
142    ) -> Self {
143        let defaults = Self::default();
144        Self {
145            account_id: account_id.unwrap_or(defaults.account_id),
146            wallet_address,
147            session_key: session_key.map(SecretString::from),
148            subaccount_id,
149            base_url_rest,
150            base_url_ws,
151            proxy_url: proxy_url.map(SecretString::from),
152            environment: environment.unwrap_or(defaults.environment),
153            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
154            max_retries: max_retries.unwrap_or(defaults.max_retries),
155            retry_delay_initial_ms: retry_delay_initial_ms
156                .unwrap_or(defaults.retry_delay_initial_ms),
157            retry_delay_max_ms: retry_delay_max_ms.unwrap_or(defaults.retry_delay_max_ms),
158            ws_timeout_secs,
159            max_fee_per_contract,
160            transport_backend: transport_backend.unwrap_or(defaults.transport_backend),
161            domain_separator,
162            action_typehash,
163            trade_module_address,
164            signature_expiry_secs: signature_expiry_secs.unwrap_or(defaults.signature_expiry_secs),
165            market_order_slippage_bps: market_order_slippage_bps
166                .unwrap_or(defaults.market_order_slippage_bps),
167            max_matching_requests_per_second,
168            max_per_instrument_matching_requests_per_second,
169        }
170    }
171
172    #[getter]
173    const fn has_proxy_url(&self) -> bool {
174        self.proxy_url.is_some()
175    }
176
177    fn __repr__(&self) -> String {
178        stringify!(DeriveExecutionClientConfig).to_string()
179    }
180}