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        auto_load_missing_instruments = None,
47    ))]
48    #[expect(clippy::too_many_arguments)]
49    fn py_new(
50        product_types: Option<Vec<DeribitProductType>>,
51        environment: Option<DeribitEnvironment>,
52        api_key: Option<String>,
53        api_secret: Option<String>,
54        base_url_http: Option<String>,
55        base_url_ws: Option<String>,
56        proxy_url: Option<String>,
57        http_timeout_secs: Option<u64>,
58        max_retries: Option<u32>,
59        retry_delay_initial_ms: Option<u64>,
60        retry_delay_max_ms: Option<u64>,
61        heartbeat_interval_secs: Option<u64>,
62        update_instruments_interval_mins: Option<u64>,
63        auto_load_missing_instruments: Option<bool>,
64    ) -> Self {
65        let defaults = Self::default();
66        Self {
67            api_key,
68            api_secret,
69            product_types: product_types.unwrap_or(defaults.product_types),
70            base_url_http,
71            base_url_ws,
72            proxy_url,
73            environment: environment.unwrap_or(defaults.environment),
74            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
75            max_retries: max_retries.unwrap_or(defaults.max_retries),
76            retry_delay_initial_ms: retry_delay_initial_ms
77                .unwrap_or(defaults.retry_delay_initial_ms),
78            retry_delay_max_ms: retry_delay_max_ms.unwrap_or(defaults.retry_delay_max_ms),
79            heartbeat_interval_secs: heartbeat_interval_secs
80                .unwrap_or(defaults.heartbeat_interval_secs),
81            update_instruments_interval_mins: update_instruments_interval_mins
82                .unwrap_or(defaults.update_instruments_interval_mins),
83            auto_load_missing_instruments: auto_load_missing_instruments
84                .unwrap_or(defaults.auto_load_missing_instruments),
85            transport_backend: defaults.transport_backend,
86        }
87    }
88
89    fn __repr__(&self) -> String {
90        format!("{self:?}")
91    }
92}
93
94#[pymethods]
95#[pyo3_stub_gen::derive::gen_stub_pymethods]
96impl DeribitExecClientConfig {
97    /// Configuration for the Deribit execution client.
98    #[new]
99    #[pyo3(signature = (
100        trader_id,
101        account_id,
102        product_types = None,
103        environment = None,
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    ))]
114    #[expect(clippy::too_many_arguments)]
115    fn py_new(
116        trader_id: TraderId,
117        account_id: AccountId,
118        product_types: Option<Vec<DeribitProductType>>,
119        environment: Option<DeribitEnvironment>,
120        api_key: Option<String>,
121        api_secret: Option<String>,
122        base_url_http: Option<String>,
123        base_url_ws: Option<String>,
124        proxy_url: Option<String>,
125        http_timeout_secs: Option<u64>,
126        max_retries: Option<u32>,
127        retry_delay_initial_ms: Option<u64>,
128        retry_delay_max_ms: Option<u64>,
129    ) -> Self {
130        let defaults = Self::default();
131        Self {
132            trader_id,
133            account_id,
134            api_key,
135            api_secret,
136            product_types: product_types.unwrap_or(defaults.product_types),
137            base_url_http,
138            base_url_ws,
139            proxy_url,
140            environment: environment.unwrap_or(defaults.environment),
141            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
142            max_retries: max_retries.unwrap_or(defaults.max_retries),
143            retry_delay_initial_ms: retry_delay_initial_ms
144                .unwrap_or(defaults.retry_delay_initial_ms),
145            retry_delay_max_ms: retry_delay_max_ms.unwrap_or(defaults.retry_delay_max_ms),
146            transport_backend: defaults.transport_backend,
147        }
148    }
149
150    fn __repr__(&self) -> String {
151        format!("{self:?}")
152    }
153}