Skip to main content

nautilus_trading/examples/actors/imbalance/
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 the book imbalance actor.
17
18use nautilus_model::identifiers::{ActorId, InstrumentId};
19
20/// Configuration for the order book imbalance actor.
21#[derive(Debug, Clone)]
22#[cfg_attr(
23    feature = "python",
24    pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.trading", from_py_object)
25)]
26pub struct BookImbalanceActorConfig {
27    /// Instruments to subscribe to.
28    pub instrument_ids: Vec<InstrumentId>,
29    /// How often (in update count) to log a progress line. Set to 0 to disable.
30    pub log_interval: u64,
31    /// Actor identifier. Defaults to `BOOK_IMBALANCE-001`.
32    pub actor_id: Option<ActorId>,
33}
34
35impl BookImbalanceActorConfig {
36    /// Creates a new [`BookImbalanceActorConfig`].
37    #[must_use]
38    pub fn new(instrument_ids: Vec<InstrumentId>) -> Self {
39        Self {
40            instrument_ids,
41            log_interval: 100,
42            actor_id: None,
43        }
44    }
45
46    #[must_use]
47    pub fn with_log_interval(mut self, interval: u64) -> Self {
48        self.log_interval = interval;
49        self
50    }
51
52    #[must_use]
53    pub fn with_actor_id(mut self, actor_id: ActorId) -> Self {
54        self.actor_id = Some(actor_id);
55        self
56    }
57}
58
59#[cfg(feature = "python")]
60#[pyo3::pymethods]
61impl BookImbalanceActorConfig {
62    #[new]
63    #[pyo3(signature = (instrument_ids, log_interval=100, actor_id=None))]
64    fn py_new(
65        instrument_ids: Vec<InstrumentId>,
66        log_interval: u64,
67        actor_id: Option<ActorId>,
68    ) -> Self {
69        let mut config = Self::new(instrument_ids).with_log_interval(log_interval);
70
71        if let Some(id) = actor_id {
72            config.actor_id = Some(id);
73        }
74
75        config
76    }
77
78    #[getter]
79    fn instrument_ids(&self) -> Vec<InstrumentId> {
80        self.instrument_ids.clone()
81    }
82
83    #[getter]
84    fn log_interval(&self) -> u64 {
85        self.log_interval
86    }
87
88    #[getter]
89    fn actor_id(&self) -> Option<ActorId> {
90        self.actor_id
91    }
92}