Skip to main content

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