Skip to main content

nautilus_deribit/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 Deribit configuration.
17
18use nautilus_model::identifiers::AccountId;
19use nautilus_network::websocket::TransportBackend;
20use pyo3::prelude::*;
21
22use crate::{
23    common::enums::DeribitEnvironment,
24    config::{DeribitDataClientConfig, DeribitExecutionClientConfig},
25    http::models::DeribitProductType,
26};
27
28#[pymethods]
29#[pyo3_stub_gen::derive::gen_stub_pymethods]
30impl DeribitDataClientConfig {
31    /// Configuration for the Deribit data client.
32    #[new]
33    #[pyo3(signature = (
34        product_types = None,
35        environment = None,
36        api_key = None,
37        api_secret = None,
38        base_url_http = None,
39        base_url_ws = None,
40        proxy_url = None,
41        http_timeout_secs = None,
42        max_retries = None,
43        retry_delay_initial_ms = None,
44        retry_delay_max_ms = None,
45        heartbeat_interval_secs = None,
46        auth_timeout_secs = None,
47        update_instruments_interval_mins = None,
48        auto_load_missing_instruments = None,
49        transport_backend = None,
50    ))]
51    #[expect(clippy::too_many_arguments)]
52    fn py_new(
53        product_types: Option<Vec<DeribitProductType>>,
54        environment: Option<DeribitEnvironment>,
55        api_key: Option<String>,
56        api_secret: Option<String>,
57        base_url_http: Option<String>,
58        base_url_ws: Option<String>,
59        proxy_url: Option<String>,
60        http_timeout_secs: Option<u64>,
61        max_retries: Option<u32>,
62        retry_delay_initial_ms: Option<u64>,
63        retry_delay_max_ms: Option<u64>,
64        heartbeat_interval_secs: Option<u64>,
65        auth_timeout_secs: Option<u64>,
66        update_instruments_interval_mins: Option<u64>,
67        auto_load_missing_instruments: Option<bool>,
68        transport_backend: Option<TransportBackend>,
69    ) -> Self {
70        let defaults = Self::default();
71        Self {
72            api_key,
73            api_secret,
74            product_types: product_types.unwrap_or(defaults.product_types),
75            base_url_http,
76            base_url_ws,
77            proxy_url,
78            environment: environment.unwrap_or(defaults.environment),
79            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
80            max_retries: max_retries.unwrap_or(defaults.max_retries),
81            retry_delay_initial_ms: retry_delay_initial_ms
82                .unwrap_or(defaults.retry_delay_initial_ms),
83            retry_delay_max_ms: retry_delay_max_ms.unwrap_or(defaults.retry_delay_max_ms),
84            heartbeat_interval_secs: heartbeat_interval_secs
85                .unwrap_or(defaults.heartbeat_interval_secs),
86            auth_timeout_secs,
87            update_instruments_interval_mins: update_instruments_interval_mins
88                .unwrap_or(defaults.update_instruments_interval_mins),
89            auto_load_missing_instruments: auto_load_missing_instruments
90                .unwrap_or(defaults.auto_load_missing_instruments),
91            transport_backend: transport_backend.unwrap_or(defaults.transport_backend),
92        }
93    }
94
95    #[getter]
96    const fn has_proxy_url(&self) -> bool {
97        self.proxy_url.is_some()
98    }
99
100    fn __repr__(&self) -> String {
101        stringify!(DeribitDataClientConfig).to_string()
102    }
103}
104
105#[pymethods]
106#[pyo3_stub_gen::derive::gen_stub_pymethods]
107impl DeribitExecutionClientConfig {
108    /// Configuration for the Deribit execution client.
109    #[new]
110    #[pyo3(signature = (
111        account_id,
112        product_types = None,
113        environment = None,
114        api_key = None,
115        api_secret = None,
116        base_url_http = None,
117        base_url_ws = None,
118        proxy_url = None,
119        http_timeout_secs = None,
120        max_retries = None,
121        retry_delay_initial_ms = None,
122        retry_delay_max_ms = None,
123        auth_timeout_secs = None,
124        transport_backend = None,
125    ))]
126    #[expect(clippy::too_many_arguments)]
127    fn py_new(
128        account_id: AccountId,
129        product_types: Option<Vec<DeribitProductType>>,
130        environment: Option<DeribitEnvironment>,
131        api_key: Option<String>,
132        api_secret: Option<String>,
133        base_url_http: Option<String>,
134        base_url_ws: Option<String>,
135        proxy_url: Option<String>,
136        http_timeout_secs: Option<u64>,
137        max_retries: Option<u32>,
138        retry_delay_initial_ms: Option<u64>,
139        retry_delay_max_ms: Option<u64>,
140        auth_timeout_secs: Option<u64>,
141        transport_backend: Option<TransportBackend>,
142    ) -> Self {
143        let defaults = Self::default();
144        Self {
145            account_id,
146            api_key,
147            api_secret,
148            product_types: product_types.unwrap_or(defaults.product_types),
149            base_url_http,
150            base_url_ws,
151            proxy_url,
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            auth_timeout_secs,
159            transport_backend: transport_backend.unwrap_or(defaults.transport_backend),
160        }
161    }
162
163    #[getter]
164    const fn has_proxy_url(&self) -> bool {
165        self.proxy_url.is_some()
166    }
167
168    fn __repr__(&self) -> String {
169        stringify!(DeribitExecutionClientConfig).to_string()
170    }
171}