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