Skip to main content

nautilus_execution/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 execution engine and order emulator configuration.
17
18use nautilus_model::identifiers::ClientId;
19use pyo3::pymethods;
20
21use crate::{engine::config::ExecutionEngineConfig, order_emulator::config::OrderEmulatorConfig};
22
23#[pymethods]
24#[pyo3_stub_gen::derive::gen_stub_pymethods]
25impl ExecutionEngineConfig {
26    /// Configuration for `ExecutionEngine` instances.
27    #[new]
28    #[expect(clippy::too_many_arguments)]
29    #[pyo3(signature = (
30        load_cache = None,
31        manage_own_order_books = None,
32        snapshot_orders = None,
33        snapshot_positions = None,
34        snapshot_positions_interval_secs = None,
35        allow_overfills = None,
36        external_clients = None,
37        purge_closed_orders_interval_mins = None,
38        purge_closed_orders_buffer_mins = None,
39        purge_closed_positions_interval_mins = None,
40        purge_closed_positions_buffer_mins = None,
41        purge_account_events_interval_mins = None,
42        purge_account_events_lookback_mins = None,
43        purge_from_database = None,
44        debug = None,
45    ))]
46    fn py_new(
47        load_cache: Option<bool>,
48        manage_own_order_books: Option<bool>,
49        snapshot_orders: Option<bool>,
50        snapshot_positions: Option<bool>,
51        snapshot_positions_interval_secs: Option<f64>,
52        allow_overfills: Option<bool>,
53        external_clients: Option<Vec<ClientId>>,
54        purge_closed_orders_interval_mins: Option<u32>,
55        purge_closed_orders_buffer_mins: Option<u32>,
56        purge_closed_positions_interval_mins: Option<u32>,
57        purge_closed_positions_buffer_mins: Option<u32>,
58        purge_account_events_interval_mins: Option<u32>,
59        purge_account_events_lookback_mins: Option<u32>,
60        purge_from_database: Option<bool>,
61        debug: Option<bool>,
62    ) -> Self {
63        Self::builder()
64            .maybe_load_cache(load_cache)
65            .maybe_manage_own_order_books(manage_own_order_books)
66            .maybe_snapshot_orders(snapshot_orders)
67            .maybe_snapshot_positions(snapshot_positions)
68            .maybe_snapshot_positions_interval_secs(snapshot_positions_interval_secs)
69            .maybe_allow_overfills(allow_overfills)
70            .maybe_external_clients(external_clients)
71            .maybe_purge_closed_orders_interval_mins(purge_closed_orders_interval_mins)
72            .maybe_purge_closed_orders_buffer_mins(purge_closed_orders_buffer_mins)
73            .maybe_purge_closed_positions_interval_mins(purge_closed_positions_interval_mins)
74            .maybe_purge_closed_positions_buffer_mins(purge_closed_positions_buffer_mins)
75            .maybe_purge_account_events_interval_mins(purge_account_events_interval_mins)
76            .maybe_purge_account_events_lookback_mins(purge_account_events_lookback_mins)
77            .maybe_purge_from_database(purge_from_database)
78            .maybe_debug(debug)
79            .build()
80    }
81
82    #[getter]
83    #[pyo3(name = "load_cache")]
84    const fn py_load_cache(&self) -> bool {
85        self.load_cache
86    }
87
88    #[getter]
89    #[pyo3(name = "manage_own_order_books")]
90    const fn py_manage_own_order_books(&self) -> bool {
91        self.manage_own_order_books
92    }
93
94    #[getter]
95    #[pyo3(name = "snapshot_orders")]
96    const fn py_snapshot_orders(&self) -> bool {
97        self.snapshot_orders
98    }
99
100    #[getter]
101    #[pyo3(name = "snapshot_positions")]
102    const fn py_snapshot_positions(&self) -> bool {
103        self.snapshot_positions
104    }
105
106    #[getter]
107    #[pyo3(name = "snapshot_positions_interval_secs")]
108    const fn py_snapshot_positions_interval_secs(&self) -> Option<f64> {
109        self.snapshot_positions_interval_secs
110    }
111
112    #[getter]
113    #[pyo3(name = "allow_overfills")]
114    const fn py_allow_overfills(&self) -> bool {
115        self.allow_overfills
116    }
117
118    #[getter]
119    #[pyo3(name = "purge_from_database")]
120    const fn py_purge_from_database(&self) -> bool {
121        self.purge_from_database
122    }
123
124    #[getter]
125    #[pyo3(name = "debug")]
126    const fn py_debug(&self) -> bool {
127        self.debug
128    }
129
130    fn __repr__(&self) -> String {
131        format!("{self:?}")
132    }
133
134    fn __str__(&self) -> String {
135        format!("{self:?}")
136    }
137}
138
139#[pymethods]
140#[pyo3_stub_gen::derive::gen_stub_pymethods]
141impl OrderEmulatorConfig {
142    /// Configuration for `OrderEmulator` instances.
143    #[new]
144    #[pyo3(signature = (debug = None))]
145    fn py_new(debug: Option<bool>) -> Self {
146        Self::builder().maybe_debug(debug).build()
147    }
148
149    #[getter]
150    #[pyo3(name = "debug")]
151    const fn py_debug(&self) -> bool {
152        self.debug
153    }
154
155    fn __repr__(&self) -> String {
156        format!("{self:?}")
157    }
158
159    fn __str__(&self) -> String {
160        format!("{self:?}")
161    }
162}