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_http_base_url, get_ws_private_url, get_ws_public_url},
21};
22
23#[derive(Debug, Clone)]
24pub struct KrakenDataClientConfig {
25    pub api_key: Option<String>,
26    pub api_secret: Option<String>,
27    pub product_type: KrakenProductType,
28    pub environment: KrakenEnvironment,
29    pub base_url: Option<String>,
30    pub ws_public_url: Option<String>,
31    pub ws_private_url: Option<String>,
32    pub http_proxy: Option<String>,
33    pub ws_proxy: Option<String>,
34    pub timeout_secs: Option<u64>,
35    pub heartbeat_interval_secs: Option<u64>,
36}
37
38impl Default for KrakenDataClientConfig {
39    fn default() -> Self {
40        Self {
41            api_key: None,
42            api_secret: None,
43            product_type: KrakenProductType::Spot,
44            environment: KrakenEnvironment::Mainnet,
45            base_url: None,
46            ws_public_url: None,
47            ws_private_url: None,
48            http_proxy: None,
49            ws_proxy: None,
50            timeout_secs: Some(30),
51            heartbeat_interval_secs: Some(30),
52        }
53    }
54}
55
56impl KrakenDataClientConfig {
57    pub fn has_api_credentials(&self) -> bool {
58        self.api_key.is_some() && self.api_secret.is_some()
59    }
60
61    pub fn http_base_url(&self) -> String {
62        self.base_url
63            .clone()
64            .unwrap_or_else(|| get_http_base_url(self.product_type, self.environment).to_string())
65    }
66
67    pub fn ws_public_url(&self) -> String {
68        self.ws_public_url
69            .clone()
70            .unwrap_or_else(|| get_ws_public_url(self.product_type, self.environment).to_string())
71    }
72
73    pub fn ws_private_url(&self) -> String {
74        self.ws_private_url
75            .clone()
76            .unwrap_or_else(|| get_ws_private_url(self.product_type, self.environment).to_string())
77    }
78}
79
80#[derive(Debug, Clone)]
81pub struct KrakenExecClientConfig {
82    pub api_key: String,
83    pub api_secret: String,
84    pub product_type: KrakenProductType,
85    pub environment: KrakenEnvironment,
86    pub base_url: Option<String>,
87    pub ws_url: Option<String>,
88    pub http_proxy: Option<String>,
89    pub ws_proxy: Option<String>,
90    pub timeout_secs: Option<u64>,
91    pub heartbeat_interval_secs: Option<u64>,
92}
93
94impl KrakenExecClientConfig {
95    pub fn http_base_url(&self) -> String {
96        self.base_url
97            .clone()
98            .unwrap_or_else(|| get_http_base_url(self.product_type, self.environment).to_string())
99    }
100
101    pub fn ws_url(&self) -> String {
102        self.ws_url
103            .clone()
104            .unwrap_or_else(|| get_ws_private_url(self.product_type, self.environment).to_string())
105    }
106}