Skip to main content

nautilus_bitmex/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 BitMEX configuration.
17
18use nautilus_model::identifiers::AccountId;
19use nautilus_network::websocket::TransportBackend;
20use pyo3::prelude::*;
21
22use crate::{
23    common::enums::BitmexEnvironment,
24    config::{BitmexDataClientConfig, BitmexExecutionClientConfig},
25};
26
27#[pymethods]
28#[pyo3_stub_gen::derive::gen_stub_pymethods]
29impl BitmexDataClientConfig {
30    /// Configuration for the BitMEX live data client.
31    #[new]
32    #[pyo3(signature = (
33        api_key = None,
34        api_secret = None,
35        base_url_http = None,
36        base_url_ws = None,
37        proxy_url = None,
38        http_timeout_secs = None,
39        max_retries = None,
40        retry_delay_initial_ms = None,
41        retry_delay_max_ms = None,
42        heartbeat_interval_secs = None,
43        auth_timeout_secs = None,
44        recv_window_ms = None,
45        active_only = None,
46        update_instruments_interval_mins = None,
47        environment = None,
48        max_requests_per_second = None,
49        max_requests_per_minute = None,
50        transport_backend = None,
51    ))]
52    #[expect(clippy::too_many_arguments)]
53    fn py_new(
54        api_key: Option<String>,
55        api_secret: Option<String>,
56        base_url_http: Option<String>,
57        base_url_ws: Option<String>,
58        proxy_url: Option<String>,
59        http_timeout_secs: Option<u64>,
60        max_retries: Option<u32>,
61        retry_delay_initial_ms: Option<u64>,
62        retry_delay_max_ms: Option<u64>,
63        heartbeat_interval_secs: Option<u64>,
64        auth_timeout_secs: Option<u64>,
65        recv_window_ms: Option<u64>,
66        active_only: Option<bool>,
67        update_instruments_interval_mins: Option<u64>,
68        environment: Option<BitmexEnvironment>,
69        max_requests_per_second: Option<u32>,
70        max_requests_per_minute: Option<u32>,
71        transport_backend: Option<TransportBackend>,
72    ) -> Self {
73        let defaults = Self::default();
74        Self {
75            api_key,
76            api_secret,
77            base_url_http,
78            base_url_ws,
79            proxy_url,
80            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
81            max_retries: max_retries.unwrap_or(defaults.max_retries),
82            retry_delay_initial_ms: retry_delay_initial_ms
83                .unwrap_or(defaults.retry_delay_initial_ms),
84            retry_delay_max_ms: retry_delay_max_ms.unwrap_or(defaults.retry_delay_max_ms),
85            heartbeat_interval_secs,
86            auth_timeout_secs,
87            recv_window_ms: recv_window_ms.unwrap_or(defaults.recv_window_ms),
88            active_only: active_only.unwrap_or(defaults.active_only),
89            update_instruments_interval_mins,
90            environment: environment.unwrap_or(defaults.environment),
91            max_requests_per_second: max_requests_per_second
92                .unwrap_or(defaults.max_requests_per_second),
93            max_requests_per_minute: max_requests_per_minute
94                .unwrap_or(defaults.max_requests_per_minute),
95            transport_backend: transport_backend.unwrap_or(defaults.transport_backend),
96        }
97    }
98
99    #[getter]
100    const fn has_proxy_url(&self) -> bool {
101        self.proxy_url.is_some()
102    }
103
104    fn __repr__(&self) -> String {
105        stringify!(BitmexDataClientConfig).to_string()
106    }
107}
108
109#[pymethods]
110#[pyo3_stub_gen::derive::gen_stub_pymethods]
111impl BitmexExecutionClientConfig {
112    /// Configuration for the BitMEX live execution client.
113    #[new]
114    #[pyo3(signature = (
115        api_key = None,
116        api_secret = None,
117        base_url_http = None,
118        base_url_ws = None,
119        proxy_url = None,
120        http_timeout_secs = None,
121        max_retries = None,
122        retry_delay_initial_ms = None,
123        retry_delay_max_ms = None,
124        heartbeat_interval_secs = None,
125        auth_timeout_secs = None,
126        recv_window_ms = None,
127        active_only = None,
128        environment = None,
129        account_id = None,
130        max_requests_per_second = None,
131        max_requests_per_minute = None,
132        submitter_pool_size = None,
133        canceller_pool_size = None,
134        submitter_proxy_urls = None,
135        canceller_proxy_urls = None,
136        deadmans_switch_timeout_secs = None,
137        transport_backend = None,
138    ))]
139    #[expect(clippy::too_many_arguments)]
140    fn py_new(
141        api_key: Option<String>,
142        api_secret: Option<String>,
143        base_url_http: Option<String>,
144        base_url_ws: Option<String>,
145        proxy_url: Option<String>,
146        http_timeout_secs: Option<u64>,
147        max_retries: Option<u32>,
148        retry_delay_initial_ms: Option<u64>,
149        retry_delay_max_ms: Option<u64>,
150        heartbeat_interval_secs: Option<u64>,
151        auth_timeout_secs: Option<u64>,
152        recv_window_ms: Option<u64>,
153        active_only: Option<bool>,
154        environment: Option<BitmexEnvironment>,
155        account_id: Option<AccountId>,
156        max_requests_per_second: Option<u32>,
157        max_requests_per_minute: Option<u32>,
158        submitter_pool_size: Option<usize>,
159        canceller_pool_size: Option<usize>,
160        submitter_proxy_urls: Option<Vec<String>>,
161        canceller_proxy_urls: Option<Vec<String>>,
162        deadmans_switch_timeout_secs: Option<u64>,
163        transport_backend: Option<TransportBackend>,
164    ) -> Self {
165        let defaults = Self::default();
166        Self {
167            api_key,
168            api_secret,
169            base_url_http,
170            base_url_ws,
171            proxy_url,
172            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
173            max_retries: max_retries.unwrap_or(defaults.max_retries),
174            retry_delay_initial_ms: retry_delay_initial_ms
175                .unwrap_or(defaults.retry_delay_initial_ms),
176            retry_delay_max_ms: retry_delay_max_ms.unwrap_or(defaults.retry_delay_max_ms),
177            heartbeat_interval_secs: heartbeat_interval_secs
178                .unwrap_or(defaults.heartbeat_interval_secs),
179            auth_timeout_secs,
180            recv_window_ms: recv_window_ms.unwrap_or(defaults.recv_window_ms),
181            active_only: active_only.unwrap_or(defaults.active_only),
182            environment: environment.unwrap_or(defaults.environment),
183            account_id,
184            max_requests_per_second: max_requests_per_second
185                .unwrap_or(defaults.max_requests_per_second),
186            max_requests_per_minute: max_requests_per_minute
187                .unwrap_or(defaults.max_requests_per_minute),
188            submitter_pool_size,
189            canceller_pool_size,
190            submitter_proxy_urls,
191            canceller_proxy_urls,
192            deadmans_switch_timeout_secs,
193            transport_backend: transport_backend.unwrap_or(defaults.transport_backend),
194        }
195    }
196
197    #[getter]
198    const fn has_proxy_url(&self) -> bool {
199        self.proxy_url.is_some()
200    }
201
202    #[getter]
203    const fn has_submitter_proxy_urls(&self) -> bool {
204        self.submitter_proxy_urls.is_some()
205    }
206
207    #[getter]
208    const fn has_canceller_proxy_urls(&self) -> bool {
209        self.canceller_proxy_urls.is_some()
210    }
211
212    fn __repr__(&self) -> String {
213        stringify!(BitmexExecutionClientConfig).to_string()
214    }
215}