Skip to main content

nautilus_execution/matching_engine/
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
16use serde::{Deserialize, Serialize};
17
18/// Configuration for `OrderMatchingEngine` instances.
19///
20/// With `defer_option_settlement`, automatic checks at the exact option expiry
21/// timestamp cancel orders but defer settlement to `process_instrument_expiration`.
22/// To settle at expiry, the caller schedules that call after processing the
23/// timestamp's market data. Automatic checks after expiry can also settle.
24/// Explicit contract-close events bypass this deferral.
25#[derive(Debug, Clone, Deserialize, Serialize, bon::Builder)]
26#[serde(default, deny_unknown_fields)]
27pub struct OrderMatchingEngineConfig {
28    #[builder(default = true)]
29    pub bar_execution: bool,
30    #[builder(default)]
31    pub bar_adaptive_high_low_ordering: bool,
32    #[builder(default = true)]
33    pub trade_execution: bool,
34    #[builder(default)]
35    pub liquidity_consumption: bool,
36    #[builder(default = true)]
37    pub reject_stop_orders: bool,
38    #[builder(default = true)]
39    pub support_gtd_orders: bool,
40    #[builder(default = true)]
41    pub support_contingent_orders: bool,
42    #[builder(default = true)]
43    pub use_position_ids: bool,
44    #[builder(default)]
45    pub use_random_ids: bool,
46    #[builder(default = true)]
47    pub use_reduce_only: bool,
48    #[builder(default)]
49    pub use_market_order_acks: bool,
50    #[builder(default)]
51    pub queue_position: bool,
52    #[builder(default)]
53    pub oto_full_trigger: bool,
54    #[builder(default)]
55    pub defer_option_settlement: bool,
56    pub price_protection_points: Option<u32>,
57}
58
59impl Default for OrderMatchingEngineConfig {
60    fn default() -> Self {
61        Self::builder().build()
62    }
63}
64
65#[cfg(test)]
66mod tests {
67    use rstest::rstest;
68
69    use super::*;
70
71    #[rstest]
72    fn test_default() {
73        let config = OrderMatchingEngineConfig::default();
74        assert!(config.bar_execution);
75        assert!(!config.bar_adaptive_high_low_ordering);
76        assert!(config.trade_execution);
77        assert!(!config.liquidity_consumption);
78        assert!(config.reject_stop_orders);
79        assert!(config.support_gtd_orders);
80        assert!(config.support_contingent_orders);
81        assert!(config.use_position_ids);
82        assert!(!config.use_random_ids);
83        assert!(config.use_reduce_only);
84        assert!(!config.use_market_order_acks);
85        assert!(!config.queue_position);
86        assert!(!config.oto_full_trigger);
87        assert!(!config.defer_option_settlement);
88        assert_eq!(config.price_protection_points, None);
89    }
90}