Skip to main content

nautilus_kraken/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 Kraken configuration.
17
18use nautilus_model::identifiers::{AccountId, TraderId};
19use pyo3::prelude::*;
20
21use crate::{
22    common::enums::{KrakenEnvironment, KrakenProductType},
23    config::{KrakenDataClientConfig, KrakenExecClientConfig},
24};
25
26#[pymethods]
27#[pyo3_stub_gen::derive::gen_stub_pymethods]
28impl KrakenDataClientConfig {
29    /// Configuration for the Kraken data client.
30    #[new]
31    #[pyo3(signature = (
32        product_type = None,
33        environment = None,
34        api_key = None,
35        api_secret = None,
36        base_url = None,
37        ws_public_url = None,
38        ws_private_url = None,
39        proxy_url = None,
40        timeout_secs = None,
41        heartbeat_interval_secs = None,
42        max_requests_per_second = None,
43    ))]
44    #[expect(clippy::too_many_arguments)]
45    fn py_new(
46        product_type: Option<KrakenProductType>,
47        environment: Option<KrakenEnvironment>,
48        api_key: Option<String>,
49        api_secret: Option<String>,
50        base_url: Option<String>,
51        ws_public_url: Option<String>,
52        ws_private_url: Option<String>,
53        proxy_url: Option<String>,
54        timeout_secs: Option<u64>,
55        heartbeat_interval_secs: Option<u64>,
56        max_requests_per_second: Option<u32>,
57    ) -> Self {
58        let defaults = Self::default();
59        Self {
60            api_key,
61            api_secret,
62            product_type: product_type.unwrap_or(defaults.product_type),
63            environment: environment.unwrap_or(defaults.environment),
64            base_url,
65            ws_public_url,
66            ws_private_url,
67            proxy_url,
68            timeout_secs: timeout_secs.unwrap_or(defaults.timeout_secs),
69            heartbeat_interval_secs: heartbeat_interval_secs
70                .unwrap_or(defaults.heartbeat_interval_secs),
71            max_requests_per_second,
72            transport_backend: defaults.transport_backend,
73        }
74    }
75
76    fn __repr__(&self) -> String {
77        format!("{self:?}")
78    }
79}
80
81#[pymethods]
82#[pyo3_stub_gen::derive::gen_stub_pymethods]
83impl KrakenExecClientConfig {
84    /// Configuration for the Kraken execution client.
85    #[new]
86    #[pyo3(signature = (
87        trader_id,
88        account_id,
89        api_key,
90        api_secret,
91        product_type = None,
92        environment = None,
93        base_url = None,
94        ws_url = None,
95        proxy_url = None,
96        timeout_secs = None,
97        heartbeat_interval_secs = None,
98        max_requests_per_second = None,
99    ))]
100    #[expect(clippy::too_many_arguments)]
101    fn py_new(
102        trader_id: TraderId,
103        account_id: AccountId,
104        api_key: String,
105        api_secret: String,
106        product_type: Option<KrakenProductType>,
107        environment: Option<KrakenEnvironment>,
108        base_url: Option<String>,
109        ws_url: Option<String>,
110        proxy_url: Option<String>,
111        timeout_secs: Option<u64>,
112        heartbeat_interval_secs: Option<u64>,
113        max_requests_per_second: Option<u32>,
114    ) -> Self {
115        let defaults = Self::default();
116        Self {
117            trader_id,
118            account_id,
119            api_key,
120            api_secret,
121            product_type: product_type.unwrap_or(defaults.product_type),
122            environment: environment.unwrap_or(defaults.environment),
123            base_url,
124            ws_url,
125            proxy_url,
126            timeout_secs: timeout_secs.unwrap_or(defaults.timeout_secs),
127            heartbeat_interval_secs: heartbeat_interval_secs
128                .unwrap_or(defaults.heartbeat_interval_secs),
129            max_requests_per_second,
130            transport_backend: defaults.transport_backend,
131        }
132    }
133
134    fn __repr__(&self) -> String {
135        format!("{self:?}")
136    }
137}