nautilus_dydx/python/
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//! Python wrapper functions for dYdX URL helpers.
17
18use pyo3::prelude::*;
19
20use crate::common::consts::{
21    DYDX_GRPC_URL, DYDX_GRPC_URLS, DYDX_HTTP_URL, DYDX_TESTNET_GRPC_URL, DYDX_TESTNET_GRPC_URLS,
22    DYDX_TESTNET_HTTP_URL, DYDX_TESTNET_WS_URL, DYDX_WS_URL,
23};
24
25/// Get the gRPC URLs for dYdX based on network.
26#[pyfunction]
27#[pyo3(name = "get_dydx_grpc_urls")]
28#[must_use]
29pub fn py_get_dydx_grpc_urls(is_testnet: bool) -> Vec<String> {
30    if is_testnet {
31        DYDX_TESTNET_GRPC_URLS
32            .iter()
33            .map(|s| (*s).to_string())
34            .collect()
35    } else {
36        DYDX_GRPC_URLS.iter().map(|s| (*s).to_string()).collect()
37    }
38}
39
40/// Get the primary gRPC URL for dYdX based on network.
41#[pyfunction]
42#[pyo3(name = "get_dydx_grpc_url")]
43#[must_use]
44pub fn py_get_dydx_grpc_url(is_testnet: bool) -> String {
45    if is_testnet {
46        DYDX_TESTNET_GRPC_URL.to_string()
47    } else {
48        DYDX_GRPC_URL.to_string()
49    }
50}
51
52/// Get the HTTP base URL for dYdX based on network.
53#[pyfunction]
54#[pyo3(name = "get_dydx_http_url")]
55#[must_use]
56pub fn py_get_dydx_http_url(is_testnet: bool) -> String {
57    if is_testnet {
58        DYDX_TESTNET_HTTP_URL.to_string()
59    } else {
60        DYDX_HTTP_URL.to_string()
61    }
62}
63
64/// Get the WebSocket URL for dYdX based on network.
65#[pyfunction]
66#[pyo3(name = "get_dydx_ws_url")]
67#[must_use]
68pub fn py_get_dydx_ws_url(is_testnet: bool) -> String {
69    if is_testnet {
70        DYDX_TESTNET_WS_URL.to_string()
71    } else {
72        DYDX_WS_URL.to_string()
73    }
74}