nautilus_hyperliquid/python/
mod.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 bindings from `pyo3`.
17
18pub mod enums;
19pub mod http;
20pub mod urls;
21pub mod websocket;
22
23use nautilus_core::python::to_pyvalue_err;
24use pyo3::prelude::*;
25
26/// Extract product type from a Hyperliquid symbol.
27///
28/// # Errors
29///
30/// Returns an error if the symbol does not contain a valid Hyperliquid product type suffix.
31#[pyfunction]
32#[pyo3(name = "hyperliquid_product_type_from_symbol")]
33fn py_hyperliquid_product_type_from_symbol(
34    symbol: &str,
35) -> PyResult<crate::common::HyperliquidProductType> {
36    crate::common::HyperliquidProductType::from_symbol(symbol).map_err(to_pyvalue_err)
37}
38
39/// Loaded as `nautilus_pyo3.hyperliquid`.
40#[pymodule]
41pub fn hyperliquid(m: &Bound<'_, PyModule>) -> PyResult<()> {
42    m.add_class::<crate::http::HyperliquidHttpClient>()?;
43    m.add_class::<crate::websocket::HyperliquidWebSocketClient>()?;
44    m.add_class::<crate::common::enums::HyperliquidProductType>()?;
45    m.add_class::<crate::common::enums::HyperliquidTpSl>()?;
46    m.add_class::<crate::common::enums::HyperliquidTriggerPriceType>()?;
47    m.add_class::<crate::common::enums::HyperliquidConditionalOrderType>()?;
48    m.add_class::<crate::common::enums::HyperliquidTrailingOffsetType>()?;
49    m.add_function(wrap_pyfunction!(urls::py_get_hyperliquid_http_base_url, m)?)?;
50    m.add_function(wrap_pyfunction!(urls::py_get_hyperliquid_ws_url, m)?)?;
51    m.add_function(wrap_pyfunction!(
52        py_hyperliquid_product_type_from_symbol,
53        m
54    )?)?;
55    Ok(())
56}