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