Skip to main content

nautilus_kraken/
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//! Configuration types for Kraken data and execution clients.
17
18use nautilus_model::identifiers::{AccountId, TraderId};
19
20use crate::common::{
21    enums::{KrakenEnvironment, KrakenProductType},
22    urls::{get_kraken_http_base_url, get_kraken_ws_private_url, get_kraken_ws_public_url},
23};
24
25/// Configuration for the Kraken data client.
26#[derive(Debug, Clone)]
27pub struct KrakenDataClientConfig {
28    pub api_key: Option<String>,
29    pub api_secret: Option<String>,
30    pub product_type: KrakenProductType,
31    pub environment: KrakenEnvironment,
32    pub base_url: Option<String>,
33    pub ws_public_url: Option<String>,
34    pub ws_private_url: Option<String>,
35    pub http_proxy: Option<String>,
36    pub ws_proxy: Option<String>,
37    pub timeout_secs: Option<u64>,
38    pub heartbeat_interval_secs: Option<u64>,
39    pub max_requests_per_second: Option<u32>,
40}
41
42impl Default for KrakenDataClientConfig {
43    fn default() -> Self {
44        Self {
45            api_key: None,
46            api_secret: None,
47            product_type: KrakenProductType::Spot,
48            environment: KrakenEnvironment::Mainnet,
49            base_url: None,
50            ws_public_url: None,
51            ws_private_url: None,
52            http_proxy: None,
53            ws_proxy: None,
54            timeout_secs: Some(30),
55            heartbeat_interval_secs: Some(30),
56            max_requests_per_second: None,
57        }
58    }
59}
60
61impl KrakenDataClientConfig {
62    /// Returns true if both API key and secret are set.
63    pub fn has_api_credentials(&self) -> bool {
64        self.api_key.is_some() && self.api_secret.is_some()
65    }
66
67    /// Returns the HTTP base URL for the configured product type and environment.
68    pub fn http_base_url(&self) -> String {
69        self.base_url.clone().unwrap_or_else(|| {
70            get_kraken_http_base_url(self.product_type, self.environment).to_string()
71        })
72    }
73
74    /// Returns the public WebSocket URL for the configured product type and environment.
75    pub fn ws_public_url(&self) -> String {
76        self.ws_public_url.clone().unwrap_or_else(|| {
77            get_kraken_ws_public_url(self.product_type, self.environment).to_string()
78        })
79    }
80
81    /// Returns the private WebSocket URL for the configured product type and environment.
82    pub fn ws_private_url(&self) -> String {
83        self.ws_private_url.clone().unwrap_or_else(|| {
84            get_kraken_ws_private_url(self.product_type, self.environment).to_string()
85        })
86    }
87}
88
89/// Configuration for the Kraken execution client.
90#[derive(Debug, Clone)]
91pub struct KrakenExecClientConfig {
92    pub trader_id: TraderId,
93    pub account_id: AccountId,
94    pub api_key: String,
95    pub api_secret: String,
96    pub product_type: KrakenProductType,
97    pub environment: KrakenEnvironment,
98    pub base_url: Option<String>,
99    pub ws_url: Option<String>,
100    pub http_proxy: Option<String>,
101    pub ws_proxy: Option<String>,
102    pub timeout_secs: Option<u64>,
103    pub heartbeat_interval_secs: Option<u64>,
104    pub max_requests_per_second: Option<u32>,
105}
106
107impl Default for KrakenExecClientConfig {
108    fn default() -> Self {
109        Self {
110            trader_id: TraderId::default(),
111            account_id: AccountId::from("KRAKEN-001"),
112            api_key: String::new(),
113            api_secret: String::new(),
114            product_type: KrakenProductType::Spot,
115            environment: KrakenEnvironment::Mainnet,
116            base_url: None,
117            ws_url: None,
118            http_proxy: None,
119            ws_proxy: None,
120            timeout_secs: Some(30),
121            heartbeat_interval_secs: Some(30),
122            max_requests_per_second: None,
123        }
124    }
125}
126
127impl KrakenExecClientConfig {
128    /// Returns the HTTP base URL for the configured product type and environment.
129    pub fn http_base_url(&self) -> String {
130        self.base_url.clone().unwrap_or_else(|| {
131            get_kraken_http_base_url(self.product_type, self.environment).to_string()
132        })
133    }
134
135    /// Returns the WebSocket URL for the configured product type and environment.
136    pub fn ws_url(&self) -> String {
137        self.ws_url.clone().unwrap_or_else(|| {
138            get_kraken_ws_private_url(self.product_type, self.environment).to_string()
139        })
140    }
141}