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 pyo3::pymethods;
19use rust_decimal::Decimal;
20
21use crate::{
22    common::enums::DeriveEnvironment,
23    config::{DeriveDataClientConfig, DeriveExecClientConfig},
24};
25
26#[pymethods]
27#[pyo3_stub_gen::derive::gen_stub_pymethods]
28impl DeriveDataClientConfig {
29    /// Configuration for the Derive live data client.
30    #[new]
31    #[pyo3(signature = (
32        base_url_rest = None,
33        base_url_ws = None,
34        proxy_url = None,
35        environment = None,
36        http_timeout_secs = None,
37        ws_timeout_secs = None,
38        update_instruments_interval_mins = None,
39        currencies = None,
40        include_expired = None,
41        auto_load_missing_instruments = None,
42    ))]
43    #[expect(clippy::too_many_arguments)]
44    fn py_new(
45        base_url_rest: Option<String>,
46        base_url_ws: Option<String>,
47        proxy_url: Option<String>,
48        environment: Option<DeriveEnvironment>,
49        http_timeout_secs: Option<u64>,
50        ws_timeout_secs: Option<u64>,
51        update_instruments_interval_mins: Option<u64>,
52        currencies: Option<Vec<String>>,
53        include_expired: Option<bool>,
54        auto_load_missing_instruments: Option<bool>,
55    ) -> Self {
56        let defaults = Self::default();
57        Self {
58            base_url_rest,
59            base_url_ws,
60            proxy_url,
61            environment: environment.unwrap_or(defaults.environment),
62            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
63            ws_timeout_secs: ws_timeout_secs.unwrap_or(defaults.ws_timeout_secs),
64            update_instruments_interval_mins: update_instruments_interval_mins
65                .unwrap_or(defaults.update_instruments_interval_mins),
66            currencies: currencies.unwrap_or(defaults.currencies),
67            include_expired: include_expired.unwrap_or(defaults.include_expired),
68            auto_load_missing_instruments: auto_load_missing_instruments
69                .unwrap_or(defaults.auto_load_missing_instruments),
70            transport_backend: defaults.transport_backend,
71        }
72    }
73
74    #[getter]
75    fn proxy_url(&self) -> Option<String> {
76        self.proxy_url.clone()
77    }
78
79    fn __repr__(&self) -> String {
80        format!("{self:?}")
81    }
82}
83
84#[pymethods]
85#[pyo3_stub_gen::derive::gen_stub_pymethods]
86impl DeriveExecClientConfig {
87    /// Configuration for the Derive live execution client.
88    #[new]
89    #[pyo3(signature = (
90        wallet_address = None,
91        session_key = None,
92        subaccount_id = None,
93        base_url_rest = None,
94        base_url_ws = None,
95        proxy_url = None,
96        environment = None,
97        http_timeout_secs = None,
98        max_retries = None,
99        retry_delay_initial_ms = None,
100        retry_delay_max_ms = None,
101        max_fee_per_contract = None,
102        domain_separator = None,
103        action_typehash = None,
104        trade_module_address = None,
105        signature_expiry_secs = None,
106        market_order_slippage_bps = None,
107        max_matching_requests_per_second = None,
108    ))]
109    #[expect(clippy::too_many_arguments)]
110    fn py_new(
111        wallet_address: Option<String>,
112        session_key: Option<String>,
113        subaccount_id: Option<u64>,
114        base_url_rest: Option<String>,
115        base_url_ws: Option<String>,
116        proxy_url: Option<String>,
117        environment: Option<DeriveEnvironment>,
118        http_timeout_secs: Option<u64>,
119        max_retries: Option<u32>,
120        retry_delay_initial_ms: Option<u64>,
121        retry_delay_max_ms: Option<u64>,
122        max_fee_per_contract: Option<Decimal>,
123        domain_separator: Option<String>,
124        action_typehash: Option<String>,
125        trade_module_address: Option<String>,
126        signature_expiry_secs: Option<u64>,
127        market_order_slippage_bps: Option<u32>,
128        max_matching_requests_per_second: Option<u32>,
129    ) -> Self {
130        let defaults = Self::default();
131        Self {
132            wallet_address,
133            session_key,
134            subaccount_id,
135            base_url_rest,
136            base_url_ws,
137            proxy_url,
138            environment: environment.unwrap_or(defaults.environment),
139            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
140            max_retries: max_retries.unwrap_or(defaults.max_retries),
141            retry_delay_initial_ms: retry_delay_initial_ms
142                .unwrap_or(defaults.retry_delay_initial_ms),
143            retry_delay_max_ms: retry_delay_max_ms.unwrap_or(defaults.retry_delay_max_ms),
144            max_fee_per_contract,
145            transport_backend: defaults.transport_backend,
146            domain_separator,
147            action_typehash,
148            trade_module_address,
149            signature_expiry_secs: signature_expiry_secs.unwrap_or(defaults.signature_expiry_secs),
150            market_order_slippage_bps: market_order_slippage_bps
151                .unwrap_or(defaults.market_order_slippage_bps),
152            max_matching_requests_per_second,
153        }
154    }
155
156    #[getter]
157    fn proxy_url(&self) -> Option<String> {
158        self.proxy_url.clone()
159    }
160
161    fn __repr__(&self) -> String {
162        format!("{self:?}")
163    }
164}