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