nautilus_kraken/common/
urls.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//! URL builders for Kraken HTTP and WebSocket endpoints.
17
18use super::{
19    consts::{
20        KRAKEN_FUTURES_DEMO_HTTP_URL, KRAKEN_FUTURES_DEMO_WS_URL, KRAKEN_FUTURES_HTTP_URL,
21        KRAKEN_FUTURES_WS_URL, KRAKEN_SPOT_HTTP_URL, KRAKEN_SPOT_WS_PRIVATE_URL,
22        KRAKEN_SPOT_WS_PUBLIC_URL,
23    },
24    enums::{KrakenEnvironment, KrakenProductType},
25};
26
27/// Returns the HTTP base URL for the given product type and environment.
28pub fn get_kraken_http_base_url(
29    product_type: KrakenProductType,
30    environment: KrakenEnvironment,
31) -> &'static str {
32    match (product_type, environment) {
33        (KrakenProductType::Spot, _) => KRAKEN_SPOT_HTTP_URL,
34        (KrakenProductType::Futures, KrakenEnvironment::Mainnet) => KRAKEN_FUTURES_HTTP_URL,
35        (KrakenProductType::Futures, KrakenEnvironment::Demo) => KRAKEN_FUTURES_DEMO_HTTP_URL,
36    }
37}
38
39/// Returns the public WebSocket URL for the given product type and environment.
40pub fn get_kraken_ws_public_url(
41    product_type: KrakenProductType,
42    environment: KrakenEnvironment,
43) -> &'static str {
44    match (product_type, environment) {
45        (KrakenProductType::Spot, _) => KRAKEN_SPOT_WS_PUBLIC_URL,
46        (KrakenProductType::Futures, KrakenEnvironment::Mainnet) => KRAKEN_FUTURES_WS_URL,
47        (KrakenProductType::Futures, KrakenEnvironment::Demo) => KRAKEN_FUTURES_DEMO_WS_URL,
48    }
49}
50
51/// Returns the private WebSocket URL for the given product type and environment.
52pub fn get_kraken_ws_private_url(
53    product_type: KrakenProductType,
54    environment: KrakenEnvironment,
55) -> &'static str {
56    match (product_type, environment) {
57        (KrakenProductType::Spot, _) => KRAKEN_SPOT_WS_PRIVATE_URL,
58        (KrakenProductType::Futures, KrakenEnvironment::Mainnet) => KRAKEN_FUTURES_WS_URL,
59        (KrakenProductType::Futures, KrakenEnvironment::Demo) => KRAKEN_FUTURES_DEMO_WS_URL,
60    }
61}