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