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