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