nautilus_dydx/python/
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//! 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#[pyfunction]
26#[pyo3(name = "get_dydx_grpc_urls")]
27#[must_use]
28pub fn py_get_dydx_grpc_urls(is_testnet: bool) -> Vec<String> {
29    if is_testnet {
30        DYDX_TESTNET_GRPC_URLS
31            .iter()
32            .map(|s| (*s).to_string())
33            .collect()
34    } else {
35        DYDX_GRPC_URLS.iter().map(|s| (*s).to_string()).collect()
36    }
37}
38
39#[pyfunction]
40#[pyo3(name = "get_dydx_grpc_url")]
41#[must_use]
42pub fn py_get_dydx_grpc_url(is_testnet: bool) -> String {
43    if is_testnet {
44        DYDX_TESTNET_GRPC_URL.to_string()
45    } else {
46        DYDX_GRPC_URL.to_string()
47    }
48}
49
50#[pyfunction]
51#[pyo3(name = "get_dydx_http_url")]
52#[must_use]
53pub fn py_get_dydx_http_url(is_testnet: bool) -> String {
54    if is_testnet {
55        DYDX_TESTNET_HTTP_URL.to_string()
56    } else {
57        DYDX_HTTP_URL.to_string()
58    }
59}
60
61#[pyfunction]
62#[pyo3(name = "get_dydx_ws_url")]
63#[must_use]
64pub fn py_get_dydx_ws_url(is_testnet: bool) -> String {
65    if is_testnet {
66        DYDX_TESTNET_WS_URL.to_string()
67    } else {
68        DYDX_WS_URL.to_string()
69    }
70}