Skip to main content

nautilus_okx/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 OKX URL helpers.
17
18use pyo3::prelude::*;
19
20use crate::common::{enums::OKXEnvironment, urls};
21
22/// Returns the OKX HTTP base URL.
23#[pyfunction]
24#[pyo3_stub_gen::derive::gen_stub_pyfunction(module = "nautilus_trader.okx")]
25pub fn get_okx_http_base_url() -> String {
26    urls::get_http_base_url().to_string()
27}
28
29/// Returns the OKX WebSocket URL for public data (market data).
30#[pyfunction]
31#[pyo3_stub_gen::derive::gen_stub_pyfunction(module = "nautilus_trader.okx")]
32pub fn get_okx_ws_url_public(environment: OKXEnvironment) -> String {
33    urls::get_ws_base_url_public(environment).to_string()
34}
35
36/// Returns the OKX WebSocket URL for private data (account/order management).
37#[pyfunction]
38#[pyo3_stub_gen::derive::gen_stub_pyfunction(module = "nautilus_trader.okx")]
39pub fn get_okx_ws_url_private(environment: OKXEnvironment) -> String {
40    urls::get_ws_base_url_private(environment).to_string()
41}
42
43/// Returns the OKX WebSocket URL for business data (bars/candlesticks).
44#[pyfunction]
45#[pyo3_stub_gen::derive::gen_stub_pyfunction(module = "nautilus_trader.okx")]
46pub fn get_okx_ws_url_business(environment: OKXEnvironment) -> String {
47    urls::get_ws_base_url_business(environment).to_string()
48}
49
50/// Derives a WebSocket URL for a given channel from a base URL.
51#[pyfunction]
52#[pyo3_stub_gen::derive::gen_stub_pyfunction(module = "nautilus_trader.okx")]
53pub fn derive_okx_ws_url(base_url: &str, channel: &str) -> String {
54    urls::derive_ws_url(base_url, channel)
55}
56
57/// Checks if OKX endpoint requires authentication.
58#[pyfunction]
59#[pyo3_stub_gen::derive::gen_stub_pyfunction(module = "nautilus_trader.okx")]
60pub fn okx_requires_authentication(endpoint_type: urls::OKXEndpointType) -> bool {
61    urls::requires_authentication(endpoint_type)
62}