Skip to main content

nautilus_coinbase/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
16use super::{
17    consts::{
18        REST_URL, REST_URL_SANDBOX, WS_URL, WS_URL_SANDBOX, WS_USER_URL, WS_USER_URL_SANDBOX,
19    },
20    enums::CoinbaseEnvironment,
21};
22
23pub fn rest_url(environment: CoinbaseEnvironment) -> &'static str {
24    match environment {
25        CoinbaseEnvironment::Live => REST_URL,
26        CoinbaseEnvironment::Sandbox => REST_URL_SANDBOX,
27    }
28}
29
30pub fn ws_url(environment: CoinbaseEnvironment) -> &'static str {
31    match environment {
32        CoinbaseEnvironment::Live => WS_URL,
33        CoinbaseEnvironment::Sandbox => WS_URL_SANDBOX,
34    }
35}
36
37pub fn ws_user_url(environment: CoinbaseEnvironment) -> &'static str {
38    match environment {
39        CoinbaseEnvironment::Live => WS_USER_URL,
40        CoinbaseEnvironment::Sandbox => WS_USER_URL_SANDBOX,
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use rstest::rstest;
47
48    use super::*;
49
50    #[rstest]
51    fn test_rest_url_live() {
52        assert_eq!(rest_url(CoinbaseEnvironment::Live), REST_URL);
53    }
54
55    #[rstest]
56    fn test_rest_url_sandbox() {
57        assert_eq!(rest_url(CoinbaseEnvironment::Sandbox), REST_URL_SANDBOX);
58    }
59
60    #[rstest]
61    fn test_ws_url_live() {
62        assert_eq!(ws_url(CoinbaseEnvironment::Live), WS_URL);
63    }
64
65    #[rstest]
66    fn test_ws_url_sandbox() {
67        assert_eq!(ws_url(CoinbaseEnvironment::Sandbox), WS_URL_SANDBOX);
68    }
69
70    #[rstest]
71    fn test_ws_user_url_live() {
72        assert_eq!(ws_user_url(CoinbaseEnvironment::Live), WS_USER_URL);
73    }
74
75    #[rstest]
76    fn test_ws_user_url_sandbox() {
77        assert_eq!(
78            ws_user_url(CoinbaseEnvironment::Sandbox),
79            WS_USER_URL_SANDBOX
80        );
81    }
82}