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