Skip to main content

nautilus_deribit/common/
urls.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//! URL helpers for Deribit API endpoints.
17
18use super::{
19    consts::{DERIBIT_HTTP_URL, DERIBIT_TESTNET_HTTP_URL, DERIBIT_TESTNET_WS_URL, DERIBIT_WS_URL},
20    enums::DeribitEnvironment,
21};
22
23/// Returns the HTTP base URL for the given environment.
24#[must_use]
25pub fn get_http_base_url(environment: DeribitEnvironment) -> &'static str {
26    match environment {
27        DeribitEnvironment::Testnet => DERIBIT_TESTNET_HTTP_URL,
28        DeribitEnvironment::Mainnet => DERIBIT_HTTP_URL,
29    }
30}
31
32/// Returns the WebSocket URL for the given environment.
33#[must_use]
34pub fn get_ws_url(environment: DeribitEnvironment) -> &'static str {
35    match environment {
36        DeribitEnvironment::Testnet => DERIBIT_TESTNET_WS_URL,
37        DeribitEnvironment::Mainnet => DERIBIT_WS_URL,
38    }
39}
40
41#[cfg(test)]
42mod tests {
43    use rstest::rstest;
44
45    use super::*;
46
47    #[rstest]
48    fn test_http_base_url_production() {
49        assert_eq!(
50            get_http_base_url(DeribitEnvironment::Mainnet),
51            "https://www.deribit.com"
52        );
53    }
54
55    #[rstest]
56    fn test_http_base_url_testnet() {
57        assert_eq!(
58            get_http_base_url(DeribitEnvironment::Testnet),
59            "https://test.deribit.com"
60        );
61    }
62
63    #[rstest]
64    fn test_ws_url_production() {
65        assert_eq!(
66            get_ws_url(DeribitEnvironment::Mainnet),
67            "wss://www.deribit.com/ws/api/v2"
68        );
69    }
70
71    #[rstest]
72    fn test_ws_url_testnet() {
73        assert_eq!(
74            get_ws_url(DeribitEnvironment::Testnet),
75            "wss://test.deribit.com/ws/api/v2"
76        );
77    }
78}