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