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