Skip to main content

nautilus_testkit/python/
testers.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 live tester configuration.
17
18use std::num::NonZeroUsize;
19
20use jiff::Timestamp;
21use nautilus_common::{actor::DataActorConfig, python::config_error_to_pyvalue_err};
22use nautilus_core::from_pydict;
23use nautilus_model::{
24    data::BarType,
25    enums::{BookType, ContingencyType, OrderType, TimeInForce, TrailingOffsetType, TriggerType},
26    identifiers::{ActorId, ClientId, InstrumentId, StrategyId},
27    types::Quantity,
28};
29use nautilus_trading::strategy::StrategyConfig;
30use pyo3::{prelude::*, types::PyDict};
31use rust_decimal::Decimal;
32
33use crate::{DataTesterConfig, ExecTesterConfig};
34
35#[pymethods]
36#[pyo3_stub_gen::derive::gen_stub_pymethods]
37impl DataTesterConfig {
38    /// Configuration for the data tester actor.
39    #[new]
40    #[allow(
41        clippy::needless_pass_by_value,
42        reason = "PyO3 #[new] requires owned params"
43    )]
44    #[expect(clippy::too_many_arguments)]
45    #[pyo3(signature = (
46        actor_id = None,
47        client_id = None,
48        instrument_ids = None,
49        bar_types = None,
50        subscribe_book_deltas = None,
51        subscribe_book_depth = None,
52        subscribe_book_at_interval = None,
53        subscribe_quotes = None,
54        subscribe_trades = None,
55        subscribe_mark_prices = None,
56        subscribe_index_prices = None,
57        subscribe_funding_rates = None,
58        subscribe_bars = None,
59        subscribe_instrument = None,
60        subscribe_instrument_status = None,
61        subscribe_instrument_close = None,
62        subscribe_option_greeks = None,
63        can_unsubscribe = None,
64        request_instruments = None,
65        request_quotes = None,
66        request_trades = None,
67        request_bars = None,
68        request_book_snapshot = None,
69        request_book_deltas = None,
70        request_funding_rates = None,
71        book_depth = None,
72        book_interval_ms = None,
73        book_levels_to_print = None,
74        manage_book = None,
75        log_data = None,
76        stats_interval_secs = None,
77        log_events = None,
78        log_commands = None,
79        request_start = None,
80        request_end = None,
81        request_limit = None,
82        book_type = None,
83    ))]
84    fn py_new(
85        actor_id: Option<ActorId>,
86        client_id: Option<ClientId>,
87        instrument_ids: Option<Vec<InstrumentId>>,
88        bar_types: Option<Vec<BarType>>,
89        subscribe_book_deltas: Option<bool>,
90        subscribe_book_depth: Option<bool>,
91        subscribe_book_at_interval: Option<bool>,
92        subscribe_quotes: Option<bool>,
93        subscribe_trades: Option<bool>,
94        subscribe_mark_prices: Option<bool>,
95        subscribe_index_prices: Option<bool>,
96        subscribe_funding_rates: Option<bool>,
97        subscribe_bars: Option<bool>,
98        subscribe_instrument: Option<bool>,
99        subscribe_instrument_status: Option<bool>,
100        subscribe_instrument_close: Option<bool>,
101        subscribe_option_greeks: Option<bool>,
102        can_unsubscribe: Option<bool>,
103        request_instruments: Option<bool>,
104        request_quotes: Option<bool>,
105        request_trades: Option<bool>,
106        request_bars: Option<bool>,
107        request_book_snapshot: Option<bool>,
108        request_book_deltas: Option<bool>,
109        request_funding_rates: Option<bool>,
110        book_depth: Option<usize>,
111        book_interval_ms: Option<usize>,
112        book_levels_to_print: Option<usize>,
113        manage_book: Option<bool>,
114        log_data: Option<bool>,
115        stats_interval_secs: Option<u64>,
116        log_events: Option<bool>,
117        log_commands: Option<bool>,
118        request_start: Option<Timestamp>,
119        request_end: Option<Timestamp>,
120        #[gen_stub(override_type(type_repr = "int | None"))] request_limit: Option<NonZeroUsize>,
121        book_type: Option<BookType>,
122    ) -> PyResult<Self> {
123        let defaults = Self::default();
124        let config = Self {
125            base: DataActorConfig {
126                actor_id,
127                log_events: log_events.unwrap_or(defaults.base.log_events),
128                log_commands: log_commands.unwrap_or(defaults.base.log_commands),
129            },
130            instrument_ids: instrument_ids.unwrap_or(defaults.instrument_ids),
131            client_id,
132            bar_types,
133            subscribe_book_deltas: subscribe_book_deltas.unwrap_or(defaults.subscribe_book_deltas),
134            subscribe_book_depth: subscribe_book_depth.unwrap_or(defaults.subscribe_book_depth),
135            subscribe_book_at_interval: subscribe_book_at_interval
136                .unwrap_or(defaults.subscribe_book_at_interval),
137            subscribe_quotes: subscribe_quotes.unwrap_or(defaults.subscribe_quotes),
138            subscribe_trades: subscribe_trades.unwrap_or(defaults.subscribe_trades),
139            subscribe_mark_prices: subscribe_mark_prices.unwrap_or(defaults.subscribe_mark_prices),
140            subscribe_index_prices: subscribe_index_prices
141                .unwrap_or(defaults.subscribe_index_prices),
142            subscribe_funding_rates: subscribe_funding_rates
143                .unwrap_or(defaults.subscribe_funding_rates),
144            subscribe_bars: subscribe_bars.unwrap_or(defaults.subscribe_bars),
145            subscribe_instrument: subscribe_instrument.unwrap_or(defaults.subscribe_instrument),
146            subscribe_instrument_status: subscribe_instrument_status
147                .unwrap_or(defaults.subscribe_instrument_status),
148            subscribe_instrument_close: subscribe_instrument_close
149                .unwrap_or(defaults.subscribe_instrument_close),
150            subscribe_option_greeks: subscribe_option_greeks
151                .unwrap_or(defaults.subscribe_option_greeks),
152            subscribe_params: defaults.subscribe_params,
153            request_params: defaults.request_params,
154            can_unsubscribe: can_unsubscribe.unwrap_or(defaults.can_unsubscribe),
155            request_instruments: request_instruments.unwrap_or(defaults.request_instruments),
156            request_quotes: request_quotes.unwrap_or(defaults.request_quotes),
157            request_trades: request_trades.unwrap_or(defaults.request_trades),
158            request_bars: request_bars.unwrap_or(defaults.request_bars),
159            request_book_snapshot: request_book_snapshot.unwrap_or(defaults.request_book_snapshot),
160            request_book_deltas: request_book_deltas.unwrap_or(defaults.request_book_deltas),
161            request_funding_rates: request_funding_rates.unwrap_or(defaults.request_funding_rates),
162            book_type: book_type.unwrap_or(defaults.book_type),
163            book_depth,
164            book_interval_ms: book_interval_ms.unwrap_or(defaults.book_interval_ms),
165            book_levels_to_print: book_levels_to_print.unwrap_or(defaults.book_levels_to_print),
166            manage_book: manage_book.unwrap_or(defaults.manage_book),
167            log_data: log_data.unwrap_or(defaults.log_data),
168            stats_interval_secs: stats_interval_secs.unwrap_or(defaults.stats_interval_secs),
169            request_start,
170            request_end,
171            request_limit,
172        };
173        config.validate().map_err(config_error_to_pyvalue_err)?;
174        Ok(config)
175    }
176
177    #[getter]
178    #[pyo3(name = "actor_id")]
179    const fn py_actor_id(&self) -> Option<ActorId> {
180        self.base.actor_id
181    }
182
183    #[getter]
184    #[pyo3(name = "client_id")]
185    const fn py_client_id(&self) -> Option<ClientId> {
186        self.client_id
187    }
188
189    #[getter]
190    #[pyo3(name = "instrument_ids")]
191    fn py_instrument_ids(&self) -> Vec<InstrumentId> {
192        self.instrument_ids.clone()
193    }
194
195    #[getter]
196    #[pyo3(name = "bar_types")]
197    fn py_bar_types(&self) -> Option<Vec<BarType>> {
198        self.bar_types.clone()
199    }
200
201    #[getter]
202    #[pyo3(name = "subscribe_book_deltas")]
203    const fn py_subscribe_book_deltas(&self) -> bool {
204        self.subscribe_book_deltas
205    }
206
207    #[getter]
208    #[pyo3(name = "subscribe_book_depth")]
209    const fn py_subscribe_book_depth(&self) -> bool {
210        self.subscribe_book_depth
211    }
212
213    #[getter]
214    #[pyo3(name = "subscribe_book_at_interval")]
215    const fn py_subscribe_book_at_interval(&self) -> bool {
216        self.subscribe_book_at_interval
217    }
218
219    #[getter]
220    #[pyo3(name = "subscribe_quotes")]
221    const fn py_subscribe_quotes(&self) -> bool {
222        self.subscribe_quotes
223    }
224
225    #[getter]
226    #[pyo3(name = "subscribe_trades")]
227    const fn py_subscribe_trades(&self) -> bool {
228        self.subscribe_trades
229    }
230
231    #[getter]
232    #[pyo3(name = "subscribe_mark_prices")]
233    const fn py_subscribe_mark_prices(&self) -> bool {
234        self.subscribe_mark_prices
235    }
236
237    #[getter]
238    #[pyo3(name = "subscribe_index_prices")]
239    const fn py_subscribe_index_prices(&self) -> bool {
240        self.subscribe_index_prices
241    }
242
243    #[getter]
244    #[pyo3(name = "subscribe_funding_rates")]
245    const fn py_subscribe_funding_rates(&self) -> bool {
246        self.subscribe_funding_rates
247    }
248
249    #[getter]
250    #[pyo3(name = "subscribe_bars")]
251    const fn py_subscribe_bars(&self) -> bool {
252        self.subscribe_bars
253    }
254
255    #[getter]
256    #[pyo3(name = "subscribe_instrument")]
257    const fn py_subscribe_instrument(&self) -> bool {
258        self.subscribe_instrument
259    }
260
261    #[getter]
262    #[pyo3(name = "subscribe_instrument_status")]
263    const fn py_subscribe_instrument_status(&self) -> bool {
264        self.subscribe_instrument_status
265    }
266
267    #[getter]
268    #[pyo3(name = "subscribe_instrument_close")]
269    const fn py_subscribe_instrument_close(&self) -> bool {
270        self.subscribe_instrument_close
271    }
272
273    #[getter]
274    #[pyo3(name = "subscribe_option_greeks")]
275    const fn py_subscribe_option_greeks(&self) -> bool {
276        self.subscribe_option_greeks
277    }
278
279    #[getter]
280    #[pyo3(name = "can_unsubscribe")]
281    const fn py_can_unsubscribe(&self) -> bool {
282        self.can_unsubscribe
283    }
284
285    #[getter]
286    #[pyo3(name = "request_instruments")]
287    const fn py_request_instruments(&self) -> bool {
288        self.request_instruments
289    }
290
291    #[getter]
292    #[pyo3(name = "request_quotes")]
293    const fn py_request_quotes(&self) -> bool {
294        self.request_quotes
295    }
296
297    #[getter]
298    #[pyo3(name = "request_trades")]
299    const fn py_request_trades(&self) -> bool {
300        self.request_trades
301    }
302
303    #[getter]
304    #[pyo3(name = "request_bars")]
305    const fn py_request_bars(&self) -> bool {
306        self.request_bars
307    }
308
309    #[getter]
310    #[pyo3(name = "request_book_snapshot")]
311    const fn py_request_book_snapshot(&self) -> bool {
312        self.request_book_snapshot
313    }
314
315    #[getter]
316    #[pyo3(name = "request_book_deltas")]
317    const fn py_request_book_deltas(&self) -> bool {
318        self.request_book_deltas
319    }
320
321    #[getter]
322    #[pyo3(name = "request_funding_rates")]
323    const fn py_request_funding_rates(&self) -> bool {
324        self.request_funding_rates
325    }
326
327    #[getter]
328    #[pyo3(name = "book_depth")]
329    const fn py_book_depth(&self) -> Option<usize> {
330        self.book_depth
331    }
332
333    #[getter]
334    #[pyo3(name = "book_interval_ms")]
335    const fn py_book_interval_ms(&self) -> usize {
336        self.book_interval_ms
337    }
338
339    #[getter]
340    #[pyo3(name = "book_levels_to_print")]
341    const fn py_book_levels_to_print(&self) -> usize {
342        self.book_levels_to_print
343    }
344
345    #[getter]
346    #[pyo3(name = "manage_book")]
347    const fn py_manage_book(&self) -> bool {
348        self.manage_book
349    }
350
351    #[getter]
352    #[pyo3(name = "log_data")]
353    const fn py_log_data(&self) -> bool {
354        self.log_data
355    }
356
357    #[getter]
358    #[pyo3(name = "stats_interval_secs")]
359    const fn py_stats_interval_secs(&self) -> u64 {
360        self.stats_interval_secs
361    }
362
363    #[getter]
364    #[pyo3(name = "request_start")]
365    const fn py_request_start(&self) -> Option<Timestamp> {
366        self.request_start
367    }
368
369    #[getter]
370    #[pyo3(name = "request_end")]
371    const fn py_request_end(&self) -> Option<Timestamp> {
372        self.request_end
373    }
374
375    #[getter]
376    #[pyo3(name = "request_limit")]
377    #[gen_stub(override_return_type(type_repr = "int | None"))]
378    const fn py_request_limit(&self) -> Option<NonZeroUsize> {
379        self.request_limit
380    }
381
382    #[getter]
383    #[pyo3(name = "book_type")]
384    const fn py_book_type(&self) -> BookType {
385        self.book_type
386    }
387
388    #[getter]
389    #[pyo3(name = "log_events")]
390    const fn py_log_events(&self) -> bool {
391        self.base.log_events
392    }
393
394    #[getter]
395    #[pyo3(name = "log_commands")]
396    const fn py_log_commands(&self) -> bool {
397        self.base.log_commands
398    }
399
400    fn __repr__(&self) -> String {
401        format!("{self:?}")
402    }
403}
404
405#[pymethods]
406#[pyo3_stub_gen::derive::gen_stub_pymethods]
407impl ExecTesterConfig {
408    /// Configuration for the execution tester strategy.
409    #[new]
410    #[allow(
411        clippy::needless_pass_by_value,
412        reason = "PyO3 #[new] requires owned params"
413    )]
414    #[expect(clippy::too_many_arguments)]
415    #[pyo3(signature = (
416        strategy_id = None,
417        order_id_tag = None,
418        use_hyphens_in_client_order_ids = None,
419        use_uuid_client_order_ids = None,
420        external_order_instrument_ids = None,
421        instrument_id = None,
422        client_id = None,
423        order_qty = None,
424        order_display_qty = None,
425        order_expire_time_delta_mins = None,
426        order_params = None,
427        subscribe_book = None,
428        subscribe_quotes = None,
429        subscribe_trades = None,
430        book_type = None,
431        book_depth = None,
432        book_interval_ms = None,
433        book_levels_to_print = None,
434        open_position_on_start_qty = None,
435        open_position_on_first_quote = None,
436        open_position_time_in_force = None,
437        enable_limit_buys = None,
438        enable_limit_sells = None,
439        enable_stop_buys = None,
440        enable_stop_sells = None,
441        tob_offset_ticks = None,
442        limit_time_in_force = None,
443        stop_order_type = None,
444        stop_offset_ticks = None,
445        stop_limit_offset_ticks = None,
446        stop_trigger_type = None,
447        stop_time_in_force = None,
448        trailing_offset = None,
449        trailing_offset_type = None,
450        enable_brackets = None,
451        batch_submit_limit_pair = None,
452        bracket_entry_order_type = None,
453        bracket_offset_ticks = None,
454        modify_orders_to_maintain_tob_offset = None,
455        modify_stop_orders_to_maintain_offset = None,
456        cancel_replace_orders_to_maintain_tob_offset = None,
457        cancel_replace_stop_orders_to_maintain_offset = None,
458        trigger_limit_order_maintenance_once = None,
459        use_post_only = None,
460        limit_aggressive = None,
461        use_quote_quantity = None,
462        emulation_trigger = None,
463        use_individual_cancels_on_stop = None,
464        cancel_orders_on_stop = None,
465        close_positions_on_stop = None,
466        close_positions_qty_precision = None,
467        close_positions_time_in_force = None,
468        reduce_only_on_stop = None,
469        use_batch_cancel_on_stop = None,
470        dry_run = None,
471        log_data = None,
472        test_reject_post_only = None,
473        test_reject_reduce_only = None,
474        test_modify_rejected = None,
475        can_unsubscribe = None,
476        clamp_to_instrument_price_range = None,
477        log_events = None,
478        log_commands = None,
479        bracket_contingency_type = None,
480        bracket_tp_order_type = None,
481    ))]
482    fn py_new(
483        py: Python<'_>,
484        strategy_id: Option<StrategyId>,
485        order_id_tag: Option<String>,
486        use_hyphens_in_client_order_ids: Option<bool>,
487        use_uuid_client_order_ids: Option<bool>,
488        external_order_instrument_ids: Option<Vec<InstrumentId>>,
489        instrument_id: Option<InstrumentId>,
490        client_id: Option<ClientId>,
491        order_qty: Option<Quantity>,
492        order_display_qty: Option<Quantity>,
493        order_expire_time_delta_mins: Option<u64>,
494        order_params: Option<Py<PyDict>>,
495        subscribe_book: Option<bool>,
496        subscribe_quotes: Option<bool>,
497        subscribe_trades: Option<bool>,
498        book_type: Option<BookType>,
499        book_depth: Option<usize>,
500        book_interval_ms: Option<usize>,
501        book_levels_to_print: Option<usize>,
502        open_position_on_start_qty: Option<Decimal>,
503        open_position_on_first_quote: Option<bool>,
504        open_position_time_in_force: Option<TimeInForce>,
505        enable_limit_buys: Option<bool>,
506        enable_limit_sells: Option<bool>,
507        enable_stop_buys: Option<bool>,
508        enable_stop_sells: Option<bool>,
509        tob_offset_ticks: Option<u64>,
510        limit_time_in_force: Option<TimeInForce>,
511        stop_order_type: Option<OrderType>,
512        stop_offset_ticks: Option<u64>,
513        stop_limit_offset_ticks: Option<u64>,
514        stop_trigger_type: Option<TriggerType>,
515        stop_time_in_force: Option<TimeInForce>,
516        trailing_offset: Option<Decimal>,
517        trailing_offset_type: Option<TrailingOffsetType>,
518        enable_brackets: Option<bool>,
519        batch_submit_limit_pair: Option<bool>,
520        bracket_entry_order_type: Option<OrderType>,
521        bracket_offset_ticks: Option<u64>,
522        modify_orders_to_maintain_tob_offset: Option<bool>,
523        modify_stop_orders_to_maintain_offset: Option<bool>,
524        cancel_replace_orders_to_maintain_tob_offset: Option<bool>,
525        cancel_replace_stop_orders_to_maintain_offset: Option<bool>,
526        trigger_limit_order_maintenance_once: Option<bool>,
527        use_post_only: Option<bool>,
528        limit_aggressive: Option<bool>,
529        use_quote_quantity: Option<bool>,
530        emulation_trigger: Option<TriggerType>,
531        use_individual_cancels_on_stop: Option<bool>,
532        cancel_orders_on_stop: Option<bool>,
533        close_positions_on_stop: Option<bool>,
534        close_positions_qty_precision: Option<u8>,
535        close_positions_time_in_force: Option<TimeInForce>,
536        reduce_only_on_stop: Option<bool>,
537        use_batch_cancel_on_stop: Option<bool>,
538        dry_run: Option<bool>,
539        log_data: Option<bool>,
540        test_reject_post_only: Option<bool>,
541        test_reject_reduce_only: Option<bool>,
542        test_modify_rejected: Option<bool>,
543        can_unsubscribe: Option<bool>,
544        clamp_to_instrument_price_range: Option<bool>,
545        log_events: Option<bool>,
546        log_commands: Option<bool>,
547        bracket_contingency_type: Option<ContingencyType>,
548        bracket_tp_order_type: Option<OrderType>,
549    ) -> PyResult<Self> {
550        let defaults = Self::default();
551        let order_params = match order_params {
552            Some(dict) => from_pydict(py, &dict)?,
553            None => None,
554        };
555        let config = Self {
556            base: StrategyConfig {
557                strategy_id,
558                order_id_tag,
559                use_hyphens_in_client_order_ids: use_hyphens_in_client_order_ids
560                    .unwrap_or(defaults.base.use_hyphens_in_client_order_ids),
561                use_uuid_client_order_ids: use_uuid_client_order_ids
562                    .unwrap_or(defaults.base.use_uuid_client_order_ids),
563                external_order_instrument_ids,
564                log_events: log_events.unwrap_or(defaults.base.log_events),
565                log_commands: log_commands.unwrap_or(defaults.base.log_commands),
566                ..Default::default()
567            },
568            instrument_id: instrument_id.unwrap_or(defaults.instrument_id),
569            order_qty: order_qty.unwrap_or(defaults.order_qty),
570            order_display_qty,
571            order_expire_time_delta_mins,
572            order_params,
573            client_id,
574            subscribe_book: subscribe_book.unwrap_or(defaults.subscribe_book),
575            subscribe_quotes: subscribe_quotes.unwrap_or(defaults.subscribe_quotes),
576            subscribe_trades: subscribe_trades.unwrap_or(defaults.subscribe_trades),
577            book_type: book_type.unwrap_or(defaults.book_type),
578            book_depth,
579            book_interval_ms: book_interval_ms.unwrap_or(defaults.book_interval_ms),
580            book_levels_to_print: book_levels_to_print.unwrap_or(defaults.book_levels_to_print),
581            open_position_on_start_qty,
582            open_position_on_first_quote: open_position_on_first_quote
583                .unwrap_or(defaults.open_position_on_first_quote),
584            open_position_time_in_force: open_position_time_in_force
585                .unwrap_or(defaults.open_position_time_in_force),
586            enable_limit_buys: enable_limit_buys.unwrap_or(defaults.enable_limit_buys),
587            enable_limit_sells: enable_limit_sells.unwrap_or(defaults.enable_limit_sells),
588            enable_stop_buys: enable_stop_buys.unwrap_or(defaults.enable_stop_buys),
589            enable_stop_sells: enable_stop_sells.unwrap_or(defaults.enable_stop_sells),
590            tob_offset_ticks: tob_offset_ticks.unwrap_or(defaults.tob_offset_ticks),
591            limit_time_in_force,
592            stop_order_type: stop_order_type.unwrap_or(defaults.stop_order_type),
593            stop_offset_ticks: stop_offset_ticks.unwrap_or(defaults.stop_offset_ticks),
594            stop_limit_offset_ticks,
595            stop_trigger_type: stop_trigger_type.unwrap_or(defaults.stop_trigger_type),
596            stop_time_in_force,
597            trailing_offset,
598            trailing_offset_type: trailing_offset_type.unwrap_or(defaults.trailing_offset_type),
599            enable_brackets: enable_brackets.unwrap_or(defaults.enable_brackets),
600            batch_submit_limit_pair: batch_submit_limit_pair
601                .unwrap_or(defaults.batch_submit_limit_pair),
602            bracket_entry_order_type: bracket_entry_order_type
603                .unwrap_or(defaults.bracket_entry_order_type),
604            bracket_offset_ticks: bracket_offset_ticks.unwrap_or(defaults.bracket_offset_ticks),
605            modify_orders_to_maintain_tob_offset: modify_orders_to_maintain_tob_offset
606                .unwrap_or(defaults.modify_orders_to_maintain_tob_offset),
607            modify_stop_orders_to_maintain_offset: modify_stop_orders_to_maintain_offset
608                .unwrap_or(defaults.modify_stop_orders_to_maintain_offset),
609            cancel_replace_orders_to_maintain_tob_offset:
610                cancel_replace_orders_to_maintain_tob_offset
611                    .unwrap_or(defaults.cancel_replace_orders_to_maintain_tob_offset),
612            cancel_replace_stop_orders_to_maintain_offset:
613                cancel_replace_stop_orders_to_maintain_offset
614                    .unwrap_or(defaults.cancel_replace_stop_orders_to_maintain_offset),
615            trigger_limit_order_maintenance_once: trigger_limit_order_maintenance_once
616                .unwrap_or(defaults.trigger_limit_order_maintenance_once),
617            use_post_only: use_post_only.unwrap_or(defaults.use_post_only),
618            limit_aggressive: limit_aggressive.unwrap_or(defaults.limit_aggressive),
619            use_quote_quantity: use_quote_quantity.unwrap_or(defaults.use_quote_quantity),
620            emulation_trigger,
621            use_individual_cancels_on_stop: use_individual_cancels_on_stop
622                .unwrap_or(defaults.use_individual_cancels_on_stop),
623            cancel_orders_on_stop: cancel_orders_on_stop.unwrap_or(defaults.cancel_orders_on_stop),
624            close_positions_on_stop: close_positions_on_stop
625                .unwrap_or(defaults.close_positions_on_stop),
626            close_positions_qty_precision,
627            close_positions_time_in_force,
628            reduce_only_on_stop: reduce_only_on_stop.unwrap_or(defaults.reduce_only_on_stop),
629            use_batch_cancel_on_stop: use_batch_cancel_on_stop
630                .unwrap_or(defaults.use_batch_cancel_on_stop),
631            dry_run: dry_run.unwrap_or(defaults.dry_run),
632            log_data: log_data.unwrap_or(defaults.log_data),
633            test_reject_post_only: test_reject_post_only.unwrap_or(defaults.test_reject_post_only),
634            test_reject_reduce_only: test_reject_reduce_only
635                .unwrap_or(defaults.test_reject_reduce_only),
636            test_modify_rejected: test_modify_rejected.unwrap_or(defaults.test_modify_rejected),
637            can_unsubscribe: can_unsubscribe.unwrap_or(defaults.can_unsubscribe),
638            clamp_to_instrument_price_range: clamp_to_instrument_price_range
639                .unwrap_or(defaults.clamp_to_instrument_price_range),
640            bracket_contingency_type: bracket_contingency_type
641                .unwrap_or(defaults.bracket_contingency_type),
642            bracket_tp_order_type: bracket_tp_order_type.unwrap_or(defaults.bracket_tp_order_type),
643        };
644        config.validate().map_err(config_error_to_pyvalue_err)?;
645        Ok(config)
646    }
647
648    #[getter]
649    #[pyo3(name = "strategy_id")]
650    const fn py_strategy_id(&self) -> Option<StrategyId> {
651        self.base.strategy_id
652    }
653
654    #[getter]
655    #[pyo3(name = "order_id_tag")]
656    fn py_order_id_tag(&self) -> Option<&str> {
657        self.base.order_id_tag.as_deref()
658    }
659
660    #[getter]
661    #[pyo3(name = "use_hyphens_in_client_order_ids")]
662    const fn py_use_hyphens_in_client_order_ids(&self) -> bool {
663        self.base.use_hyphens_in_client_order_ids
664    }
665
666    #[getter]
667    #[pyo3(name = "use_uuid_client_order_ids")]
668    const fn py_use_uuid_client_order_ids(&self) -> bool {
669        self.base.use_uuid_client_order_ids
670    }
671
672    #[getter]
673    #[pyo3(name = "external_order_instrument_ids")]
674    fn py_external_order_instrument_ids(&self) -> Option<Vec<InstrumentId>> {
675        self.base.external_order_instrument_ids.clone()
676    }
677
678    #[getter]
679    #[pyo3(name = "instrument_id")]
680    const fn py_instrument_id(&self) -> InstrumentId {
681        self.instrument_id
682    }
683
684    #[getter]
685    #[pyo3(name = "client_id")]
686    const fn py_client_id(&self) -> Option<ClientId> {
687        self.client_id
688    }
689
690    #[getter]
691    #[pyo3(name = "order_qty")]
692    const fn py_order_qty(&self) -> Quantity {
693        self.order_qty
694    }
695
696    #[getter]
697    #[pyo3(name = "order_display_qty")]
698    const fn py_order_display_qty(&self) -> Option<Quantity> {
699        self.order_display_qty
700    }
701
702    #[getter]
703    #[pyo3(name = "order_expire_time_delta_mins")]
704    const fn py_order_expire_time_delta_mins(&self) -> Option<u64> {
705        self.order_expire_time_delta_mins
706    }
707
708    #[getter]
709    #[pyo3(name = "order_params")]
710    fn py_order_params(&self, py: Python<'_>) -> PyResult<Option<Py<PyDict>>> {
711        self.order_params
712            .as_ref()
713            .map(|params| params.to_pydict(py))
714            .transpose()
715    }
716
717    #[getter]
718    #[pyo3(name = "subscribe_book")]
719    const fn py_subscribe_book(&self) -> bool {
720        self.subscribe_book
721    }
722
723    #[getter]
724    #[pyo3(name = "subscribe_quotes")]
725    const fn py_subscribe_quotes(&self) -> bool {
726        self.subscribe_quotes
727    }
728
729    #[getter]
730    #[pyo3(name = "subscribe_trades")]
731    const fn py_subscribe_trades(&self) -> bool {
732        self.subscribe_trades
733    }
734
735    #[getter]
736    #[pyo3(name = "book_type")]
737    const fn py_book_type(&self) -> BookType {
738        self.book_type
739    }
740
741    #[getter]
742    #[pyo3(name = "book_depth")]
743    const fn py_book_depth(&self) -> Option<usize> {
744        self.book_depth
745    }
746
747    #[getter]
748    #[pyo3(name = "book_interval_ms")]
749    const fn py_book_interval_ms(&self) -> usize {
750        self.book_interval_ms
751    }
752
753    #[getter]
754    #[pyo3(name = "book_levels_to_print")]
755    const fn py_book_levels_to_print(&self) -> usize {
756        self.book_levels_to_print
757    }
758
759    #[getter]
760    #[pyo3(name = "open_position_on_start_qty")]
761    const fn py_open_position_on_start_qty(&self) -> Option<Decimal> {
762        self.open_position_on_start_qty
763    }
764
765    #[getter]
766    #[pyo3(name = "open_position_on_first_quote")]
767    const fn py_open_position_on_first_quote(&self) -> bool {
768        self.open_position_on_first_quote
769    }
770
771    #[getter]
772    #[pyo3(name = "open_position_time_in_force")]
773    const fn py_open_position_time_in_force(&self) -> TimeInForce {
774        self.open_position_time_in_force
775    }
776
777    #[getter]
778    #[pyo3(name = "enable_limit_buys")]
779    const fn py_enable_limit_buys(&self) -> bool {
780        self.enable_limit_buys
781    }
782
783    #[getter]
784    #[pyo3(name = "enable_limit_sells")]
785    const fn py_enable_limit_sells(&self) -> bool {
786        self.enable_limit_sells
787    }
788
789    #[getter]
790    #[pyo3(name = "enable_stop_buys")]
791    const fn py_enable_stop_buys(&self) -> bool {
792        self.enable_stop_buys
793    }
794
795    #[getter]
796    #[pyo3(name = "enable_stop_sells")]
797    const fn py_enable_stop_sells(&self) -> bool {
798        self.enable_stop_sells
799    }
800
801    #[getter]
802    #[pyo3(name = "tob_offset_ticks")]
803    const fn py_tob_offset_ticks(&self) -> u64 {
804        self.tob_offset_ticks
805    }
806
807    #[getter]
808    #[pyo3(name = "limit_time_in_force")]
809    const fn py_limit_time_in_force(&self) -> Option<TimeInForce> {
810        self.limit_time_in_force
811    }
812
813    #[getter]
814    #[pyo3(name = "stop_order_type")]
815    const fn py_stop_order_type(&self) -> OrderType {
816        self.stop_order_type
817    }
818
819    #[getter]
820    #[pyo3(name = "stop_offset_ticks")]
821    const fn py_stop_offset_ticks(&self) -> u64 {
822        self.stop_offset_ticks
823    }
824
825    #[getter]
826    #[pyo3(name = "stop_limit_offset_ticks")]
827    const fn py_stop_limit_offset_ticks(&self) -> Option<u64> {
828        self.stop_limit_offset_ticks
829    }
830
831    #[getter]
832    #[pyo3(name = "stop_trigger_type")]
833    const fn py_stop_trigger_type(&self) -> TriggerType {
834        self.stop_trigger_type
835    }
836
837    #[getter]
838    #[pyo3(name = "stop_time_in_force")]
839    const fn py_stop_time_in_force(&self) -> Option<TimeInForce> {
840        self.stop_time_in_force
841    }
842
843    #[getter]
844    #[pyo3(name = "trailing_offset")]
845    const fn py_trailing_offset(&self) -> Option<Decimal> {
846        self.trailing_offset
847    }
848
849    #[getter]
850    #[pyo3(name = "trailing_offset_type")]
851    const fn py_trailing_offset_type(&self) -> TrailingOffsetType {
852        self.trailing_offset_type
853    }
854
855    #[getter]
856    #[pyo3(name = "enable_brackets")]
857    const fn py_enable_brackets(&self) -> bool {
858        self.enable_brackets
859    }
860
861    #[getter]
862    #[pyo3(name = "batch_submit_limit_pair")]
863    const fn py_batch_submit_limit_pair(&self) -> bool {
864        self.batch_submit_limit_pair
865    }
866
867    #[getter]
868    #[pyo3(name = "bracket_entry_order_type")]
869    const fn py_bracket_entry_order_type(&self) -> OrderType {
870        self.bracket_entry_order_type
871    }
872
873    #[getter]
874    #[pyo3(name = "bracket_contingency_type")]
875    const fn py_bracket_contingency_type(&self) -> ContingencyType {
876        self.bracket_contingency_type
877    }
878
879    #[getter]
880    #[pyo3(name = "bracket_tp_order_type")]
881    const fn py_bracket_tp_order_type(&self) -> OrderType {
882        self.bracket_tp_order_type
883    }
884
885    #[getter]
886    #[pyo3(name = "bracket_offset_ticks")]
887    const fn py_bracket_offset_ticks(&self) -> u64 {
888        self.bracket_offset_ticks
889    }
890
891    #[getter]
892    #[pyo3(name = "modify_orders_to_maintain_tob_offset")]
893    const fn py_modify_orders_to_maintain_tob_offset(&self) -> bool {
894        self.modify_orders_to_maintain_tob_offset
895    }
896
897    #[getter]
898    #[pyo3(name = "modify_stop_orders_to_maintain_offset")]
899    const fn py_modify_stop_orders_to_maintain_offset(&self) -> bool {
900        self.modify_stop_orders_to_maintain_offset
901    }
902
903    #[getter]
904    #[pyo3(name = "cancel_replace_orders_to_maintain_tob_offset")]
905    const fn py_cancel_replace_orders_to_maintain_tob_offset(&self) -> bool {
906        self.cancel_replace_orders_to_maintain_tob_offset
907    }
908
909    #[getter]
910    #[pyo3(name = "cancel_replace_stop_orders_to_maintain_offset")]
911    const fn py_cancel_replace_stop_orders_to_maintain_offset(&self) -> bool {
912        self.cancel_replace_stop_orders_to_maintain_offset
913    }
914
915    #[getter]
916    #[pyo3(name = "trigger_limit_order_maintenance_once")]
917    const fn py_trigger_limit_order_maintenance_once(&self) -> bool {
918        self.trigger_limit_order_maintenance_once
919    }
920
921    #[getter]
922    #[pyo3(name = "use_post_only")]
923    const fn py_use_post_only(&self) -> bool {
924        self.use_post_only
925    }
926
927    #[getter]
928    #[pyo3(name = "limit_aggressive")]
929    const fn py_limit_aggressive(&self) -> bool {
930        self.limit_aggressive
931    }
932
933    #[getter]
934    #[pyo3(name = "use_quote_quantity")]
935    const fn py_use_quote_quantity(&self) -> bool {
936        self.use_quote_quantity
937    }
938
939    #[getter]
940    #[pyo3(name = "emulation_trigger")]
941    const fn py_emulation_trigger(&self) -> Option<TriggerType> {
942        self.emulation_trigger
943    }
944
945    #[getter]
946    #[pyo3(name = "use_individual_cancels_on_stop")]
947    const fn py_use_individual_cancels_on_stop(&self) -> bool {
948        self.use_individual_cancels_on_stop
949    }
950
951    #[getter]
952    #[pyo3(name = "cancel_orders_on_stop")]
953    const fn py_cancel_orders_on_stop(&self) -> bool {
954        self.cancel_orders_on_stop
955    }
956
957    #[getter]
958    #[pyo3(name = "close_positions_on_stop")]
959    const fn py_close_positions_on_stop(&self) -> bool {
960        self.close_positions_on_stop
961    }
962
963    #[getter]
964    #[pyo3(name = "close_positions_qty_precision")]
965    const fn py_close_positions_qty_precision(&self) -> Option<u8> {
966        self.close_positions_qty_precision
967    }
968
969    #[getter]
970    #[pyo3(name = "close_positions_time_in_force")]
971    const fn py_close_positions_time_in_force(&self) -> Option<TimeInForce> {
972        self.close_positions_time_in_force
973    }
974
975    #[getter]
976    #[pyo3(name = "reduce_only_on_stop")]
977    const fn py_reduce_only_on_stop(&self) -> bool {
978        self.reduce_only_on_stop
979    }
980
981    #[getter]
982    #[pyo3(name = "use_batch_cancel_on_stop")]
983    const fn py_use_batch_cancel_on_stop(&self) -> bool {
984        self.use_batch_cancel_on_stop
985    }
986
987    #[getter]
988    #[pyo3(name = "dry_run")]
989    const fn py_dry_run(&self) -> bool {
990        self.dry_run
991    }
992
993    #[getter]
994    #[pyo3(name = "log_data")]
995    const fn py_log_data(&self) -> bool {
996        self.log_data
997    }
998
999    #[getter]
1000    #[pyo3(name = "test_reject_post_only")]
1001    const fn py_test_reject_post_only(&self) -> bool {
1002        self.test_reject_post_only
1003    }
1004
1005    #[getter]
1006    #[pyo3(name = "test_reject_reduce_only")]
1007    const fn py_test_reject_reduce_only(&self) -> bool {
1008        self.test_reject_reduce_only
1009    }
1010
1011    #[getter]
1012    #[pyo3(name = "test_modify_rejected")]
1013    const fn py_test_modify_rejected(&self) -> bool {
1014        self.test_modify_rejected
1015    }
1016
1017    #[getter]
1018    #[pyo3(name = "can_unsubscribe")]
1019    const fn py_can_unsubscribe(&self) -> bool {
1020        self.can_unsubscribe
1021    }
1022
1023    #[getter]
1024    #[pyo3(name = "clamp_to_instrument_price_range")]
1025    const fn py_clamp_to_instrument_price_range(&self) -> bool {
1026        self.clamp_to_instrument_price_range
1027    }
1028
1029    #[getter]
1030    #[pyo3(name = "log_events")]
1031    const fn py_log_events(&self) -> bool {
1032        self.base.log_events
1033    }
1034
1035    #[getter]
1036    #[pyo3(name = "log_commands")]
1037    const fn py_log_commands(&self) -> bool {
1038        self.base.log_commands
1039    }
1040
1041    fn __repr__(&self) -> String {
1042        format!("{self:?}")
1043    }
1044}