nautilus_trading/algorithm/
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//! Configuration for execution algorithms.
17
18use nautilus_core::serialization::default_true;
19use nautilus_model::identifiers::ExecAlgorithmId;
20use serde::{Deserialize, Serialize};
21
22/// Configuration for an execution algorithm.
23#[derive(Clone, Debug, Deserialize, Serialize)]
24#[cfg_attr(
25    feature = "python",
26    pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.trading")
27)]
28pub struct ExecutionAlgorithmConfig {
29    /// The unique ID for the execution algorithm.
30    pub exec_algorithm_id: Option<ExecAlgorithmId>,
31    /// If events should be logged by the algorithm.
32    #[serde(default = "default_true")]
33    pub log_events: bool,
34    /// If commands should be logged by the algorithm.
35    #[serde(default = "default_true")]
36    pub log_commands: bool,
37}
38
39impl Default for ExecutionAlgorithmConfig {
40    fn default() -> Self {
41        Self {
42            exec_algorithm_id: None,
43            log_events: true,
44            log_commands: true,
45        }
46    }
47}
48
49#[cfg(test)]
50mod tests {
51    use rstest::rstest;
52
53    use super::*;
54
55    #[rstest]
56    fn test_config_default() {
57        let config = ExecutionAlgorithmConfig::default();
58
59        assert!(config.exec_algorithm_id.is_none());
60        assert!(config.log_events);
61        assert!(config.log_commands);
62    }
63
64    #[rstest]
65    fn test_config_with_id() {
66        let exec_algorithm_id = ExecAlgorithmId::new("TWAP");
67        let config = ExecutionAlgorithmConfig {
68            exec_algorithm_id: Some(exec_algorithm_id),
69            ..Default::default()
70        };
71
72        assert_eq!(config.exec_algorithm_id, Some(exec_algorithm_id));
73    }
74
75    #[rstest]
76    fn test_config_serialization() {
77        let config = ExecutionAlgorithmConfig {
78            exec_algorithm_id: Some(ExecAlgorithmId::new("TWAP")),
79            log_events: false,
80            log_commands: true,
81        };
82
83        let json = serde_json::to_string(&config).unwrap();
84        let deserialized: ExecutionAlgorithmConfig = serde_json::from_str(&json).unwrap();
85
86        assert_eq!(config.exec_algorithm_id, deserialized.exec_algorithm_id);
87        assert_eq!(config.log_events, deserialized.log_events);
88        assert_eq!(config.log_commands, deserialized.log_commands);
89    }
90}