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        ws_post_timeout_secs = None,
92    ))]
93    #[expect(clippy::too_many_arguments)]
94    fn py_new(
95        private_key: Option<String>,
96        vault_address: Option<String>,
97        account_address: Option<String>,
98        environment: Option<HyperliquidEnvironment>,
99        base_url_ws: Option<String>,
100        base_url_http: Option<String>,
101        base_url_exchange: Option<String>,
102        proxy_url: Option<String>,
103        http_timeout_secs: Option<u64>,
104        max_retries: Option<u32>,
105        retry_delay_initial_ms: Option<u64>,
106        retry_delay_max_ms: Option<u64>,
107        normalize_prices: Option<bool>,
108        market_order_slippage_bps: Option<u32>,
109        ws_post_timeout_secs: Option<u64>,
110    ) -> Self {
111        let defaults = Self::default();
112        Self {
113            private_key,
114            vault_address,
115            account_address,
116            base_url_ws,
117            base_url_http,
118            base_url_exchange,
119            proxy_url,
120            environment: environment.unwrap_or(defaults.environment),
121            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
122            max_retries: max_retries.unwrap_or(defaults.max_retries),
123            retry_delay_initial_ms: retry_delay_initial_ms
124                .unwrap_or(defaults.retry_delay_initial_ms),
125            retry_delay_max_ms: retry_delay_max_ms.unwrap_or(defaults.retry_delay_max_ms),
126            normalize_prices: normalize_prices.unwrap_or(defaults.normalize_prices),
127            market_order_slippage_bps: market_order_slippage_bps
128                .unwrap_or(defaults.market_order_slippage_bps),
129            ws_post_timeout_secs: ws_post_timeout_secs.unwrap_or(defaults.ws_post_timeout_secs),
130            transport_backend: defaults.transport_backend,
131            outcome_settlement_poll_secs: defaults.outcome_settlement_poll_secs,
132        }
133    }
134
135    fn __repr__(&self) -> String {
136        format!("{self:?}")
137    }
138}