Skip to main content

nautilus_lighter/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 Lighter configuration.
17
18use nautilus_model::identifiers::{AccountId, Venue};
19use nautilus_network::websocket::TransportBackend;
20use pyo3::pymethods;
21
22use crate::{
23    common::enums::{LighterDeployment, LighterEnvironment},
24    config::{LighterDataClientConfig, LighterExecutionClientConfig},
25};
26
27#[pymethods]
28#[pyo3_stub_gen::derive::gen_stub_pymethods]
29impl LighterDataClientConfig {
30    /// Configuration for the Lighter live data client.
31    #[new]
32    #[pyo3(signature = (
33        base_url_http = None,
34        base_url_ws = None,
35        proxy_url = None,
36        environment = None,
37        account_index = None,
38        api_key_index = None,
39        private_key = None,
40        http_timeout_secs = None,
41        ws_timeout_secs = None,
42        update_instruments_interval_mins = None,
43        rest_quota_per_min = None,
44        transport_backend = None,
45        deployment = None,
46        venue = None,
47    ))]
48    #[expect(clippy::too_many_arguments)]
49    fn py_new(
50        base_url_http: Option<String>,
51        base_url_ws: Option<String>,
52        proxy_url: Option<String>,
53        environment: Option<LighterEnvironment>,
54        account_index: Option<u64>,
55        api_key_index: Option<u8>,
56        private_key: Option<String>,
57        http_timeout_secs: Option<u64>,
58        ws_timeout_secs: Option<u64>,
59        update_instruments_interval_mins: Option<u64>,
60        rest_quota_per_min: Option<u32>,
61        transport_backend: Option<TransportBackend>,
62        deployment: Option<LighterDeployment>,
63        venue: Option<Venue>,
64    ) -> Self {
65        let defaults = Self::default();
66        Self {
67            environment: environment.unwrap_or(defaults.environment),
68            deployment: deployment.unwrap_or(defaults.deployment),
69            venue,
70            account_index,
71            api_key_index,
72            private_key,
73            base_url_http,
74            base_url_ws,
75            proxy_url,
76            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
77            ws_timeout_secs: ws_timeout_secs.unwrap_or(defaults.ws_timeout_secs),
78            update_instruments_interval_mins: update_instruments_interval_mins
79                .unwrap_or(defaults.update_instruments_interval_mins),
80            rest_quota_per_min,
81            transport_backend: transport_backend.unwrap_or(defaults.transport_backend),
82        }
83    }
84
85    #[getter]
86    const fn has_proxy_url(&self) -> bool {
87        self.proxy_url.is_some()
88    }
89
90    fn __repr__(&self) -> String {
91        stringify!(LighterDataClientConfig).to_string()
92    }
93}
94
95#[pymethods]
96#[pyo3_stub_gen::derive::gen_stub_pymethods]
97impl LighterExecutionClientConfig {
98    /// Configuration for the Lighter live execution client.
99    #[new]
100    #[pyo3(signature = (
101        account_id,
102        account_index = None,
103        api_key_index = None,
104        private_key = None,
105        base_url_http = None,
106        base_url_ws = None,
107        proxy_url = None,
108        environment = None,
109        http_timeout_secs = None,
110        ws_timeout_secs = None,
111        market_order_slippage_bps = None,
112        rest_quota_per_min = None,
113        sendtx_quota_per_min = None,
114        transport_backend = None,
115        deployment = None,
116        venue = None,
117    ))]
118    #[expect(clippy::too_many_arguments)]
119    fn py_new(
120        account_id: AccountId,
121        account_index: Option<u64>,
122        api_key_index: Option<u8>,
123        private_key: Option<String>,
124        base_url_http: Option<String>,
125        base_url_ws: Option<String>,
126        proxy_url: Option<String>,
127        environment: Option<LighterEnvironment>,
128        http_timeout_secs: Option<u64>,
129        ws_timeout_secs: Option<u64>,
130        market_order_slippage_bps: Option<u32>,
131        rest_quota_per_min: Option<u32>,
132        sendtx_quota_per_min: Option<u32>,
133        transport_backend: Option<TransportBackend>,
134        deployment: Option<LighterDeployment>,
135        venue: Option<Venue>,
136    ) -> Self {
137        let defaults = Self::default();
138        Self {
139            environment: environment.unwrap_or(defaults.environment),
140            deployment: deployment.unwrap_or(defaults.deployment),
141            venue,
142            account_id,
143            account_index,
144            api_key_index,
145            private_key,
146            base_url_http,
147            base_url_ws,
148            proxy_url,
149            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
150            ws_timeout_secs: ws_timeout_secs.unwrap_or(defaults.ws_timeout_secs),
151            market_order_slippage_bps: market_order_slippage_bps
152                .unwrap_or(defaults.market_order_slippage_bps),
153            rest_quota_per_min,
154            sendtx_quota_per_min,
155            transport_backend: transport_backend.unwrap_or(defaults.transport_backend),
156        }
157    }
158
159    #[getter]
160    const fn has_proxy_url(&self) -> bool {
161        self.proxy_url.is_some()
162    }
163
164    fn __repr__(&self) -> String {
165        stringify!(LighterExecutionClientConfig).to_string()
166    }
167}