nautilus_kraken/
config.rs

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