nautilus_bitmex/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 BitMEX services.
17
18use super::consts::{
19    BITMEX_HTTP_TESTNET_URL, BITMEX_HTTP_URL, BITMEX_WS_TESTNET_URL, BITMEX_WS_URL,
20};
21
22/// Gets the BitMEX HTTP base URL.
23pub fn get_http_base_url(testnet: bool) -> String {
24    if testnet {
25        BITMEX_HTTP_TESTNET_URL.to_string()
26    } else {
27        BITMEX_HTTP_URL.to_string()
28    }
29}
30
31/// Gets the BitMEX WebSocket URL.
32pub fn get_ws_url(testnet: bool) -> String {
33    if testnet {
34        BITMEX_WS_TESTNET_URL.to_string()
35    } else {
36        BITMEX_WS_URL.to_string()
37    }
38}
39
40////////////////////////////////////////////////////////////////////////////////
41// Tests
42////////////////////////////////////////////////////////////////////////////////
43
44#[cfg(test)]
45mod tests {
46    use rstest::rstest;
47
48    use super::*;
49
50    #[rstest]
51    fn test_http_urls() {
52        assert_eq!(get_http_base_url(false), "https://www.bitmex.com/api/v1");
53        assert_eq!(get_http_base_url(true), "https://testnet.bitmex.com/api/v1");
54    }
55
56    #[rstest]
57    fn test_ws_urls() {
58        assert_eq!(get_ws_url(false), "wss://ws.bitmex.com/realtime");
59        assert_eq!(get_ws_url(true), "wss://ws.testnet.bitmex.com/realtime");
60    }
61}