Skip to main content

nautilus_hyperliquid/python/
config.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 bindings for Hyperliquid configuration.
17
18use pyo3::prelude::*;
19
20use crate::{
21    common::enums::HyperliquidEnvironment,
22    config::{HyperliquidDataClientConfig, HyperliquidExecClientConfig},
23};
24
25#[pymethods]
26#[pyo3_stub_gen::derive::gen_stub_pymethods]
27impl HyperliquidDataClientConfig {
28    /// Configuration for the Hyperliquid data client.
29    #[new]
30    #[pyo3(signature = (
31        environment = None,
32        private_key = None,
33        base_url_ws = None,
34        base_url_http = None,
35        proxy_url = None,
36        http_timeout_secs = None,
37        ws_timeout_secs = None,
38        update_instruments_interval_mins = None,
39    ))]
40    #[expect(clippy::too_many_arguments)]
41    fn py_new(
42        environment: Option<HyperliquidEnvironment>,
43        private_key: Option<String>,
44        base_url_ws: Option<String>,
45        base_url_http: Option<String>,
46        proxy_url: Option<String>,
47        http_timeout_secs: Option<u64>,
48        ws_timeout_secs: Option<u64>,
49        update_instruments_interval_mins: Option<u64>,
50    ) -> Self {
51        let defaults = Self::default();
52        Self {
53            private_key,
54            base_url_ws,
55            base_url_http,
56            proxy_url,
57            environment: environment.unwrap_or(defaults.environment),
58            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
59            ws_timeout_secs: ws_timeout_secs.unwrap_or(defaults.ws_timeout_secs),
60            update_instruments_interval_mins: update_instruments_interval_mins
61                .unwrap_or(defaults.update_instruments_interval_mins),
62            transport_backend: defaults.transport_backend,
63        }
64    }
65
66    fn __repr__(&self) -> String {
67        format!("{self:?}")
68    }
69}
70
71#[pymethods]
72#[pyo3_stub_gen::derive::gen_stub_pymethods]
73impl HyperliquidExecClientConfig {
74    /// Configuration for the Hyperliquid execution client.
75    #[new]
76    #[pyo3(signature = (
77        private_key = None,
78        vault_address = None,
79        account_address = None,
80        environment = None,
81        base_url_ws = None,
82        base_url_http = None,
83        base_url_exchange = None,
84        proxy_url = None,
85        http_timeout_secs = None,
86        max_retries = None,
87        retry_delay_initial_ms = None,
88        retry_delay_max_ms = None,
89        normalize_prices = None,
90        market_order_slippage_bps = None,
91    ))]
92    #[expect(clippy::too_many_arguments)]
93    fn py_new(
94        private_key: Option<String>,
95        vault_address: Option<String>,
96        account_address: Option<String>,
97        environment: Option<HyperliquidEnvironment>,
98        base_url_ws: Option<String>,
99        base_url_http: Option<String>,
100        base_url_exchange: Option<String>,
101        proxy_url: Option<String>,
102        http_timeout_secs: Option<u64>,
103        max_retries: Option<u32>,
104        retry_delay_initial_ms: Option<u64>,
105        retry_delay_max_ms: Option<u64>,
106        normalize_prices: Option<bool>,
107        market_order_slippage_bps: Option<u32>,
108    ) -> Self {
109        let defaults = Self::default();
110        Self {
111            private_key,
112            vault_address,
113            account_address,
114            base_url_ws,
115            base_url_http,
116            base_url_exchange,
117            proxy_url,
118            environment: environment.unwrap_or(defaults.environment),
119            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
120            max_retries: max_retries.unwrap_or(defaults.max_retries),
121            retry_delay_initial_ms: retry_delay_initial_ms
122                .unwrap_or(defaults.retry_delay_initial_ms),
123            retry_delay_max_ms: retry_delay_max_ms.unwrap_or(defaults.retry_delay_max_ms),
124            normalize_prices: normalize_prices.unwrap_or(defaults.normalize_prices),
125            market_order_slippage_bps: market_order_slippage_bps
126                .unwrap_or(defaults.market_order_slippage_bps),
127            transport_backend: defaults.transport_backend,
128        }
129    }
130
131    fn __repr__(&self) -> String {
132        format!("{self:?}")
133    }
134}