Skip to main content

nautilus_execution/order_emulator/
adapter.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 std::{
17    cell::{Ref, RefCell, RefMut},
18    rc::Rc,
19};
20
21use nautilus_common::{cache::Cache, clock::Clock};
22
23use crate::order_emulator::emulator::OrderEmulator;
24
25#[derive(Debug)]
26pub struct OrderEmulatorAdapter {
27    emulator: Rc<RefCell<OrderEmulator>>,
28}
29
30impl OrderEmulatorAdapter {
31    /// Creates a new [`OrderEmulatorAdapter`] instance.
32    pub fn new(clock: Rc<RefCell<dyn Clock>>, cache: Rc<RefCell<Cache>>) -> Self {
33        let emulator = Rc::new(RefCell::new(OrderEmulator::new(clock, cache)));
34
35        Self { emulator }
36    }
37
38    #[must_use]
39    pub fn get_emulator(&self) -> Ref<'_, OrderEmulator> {
40        self.emulator.borrow()
41    }
42
43    #[must_use]
44    pub fn get_emulator_mut(&self) -> RefMut<'_, OrderEmulator> {
45        self.emulator.borrow_mut()
46    }
47
48    #[must_use]
49    pub fn emulator(&self) -> Rc<RefCell<OrderEmulator>> {
50        self.emulator.clone()
51    }
52
53    pub fn start(&self) {
54        self.emulator.borrow_mut().start();
55    }
56
57    pub fn stop(&self) {
58        self.emulator.borrow().stop();
59    }
60
61    pub fn reset(&self) {
62        self.emulator.borrow_mut().reset();
63    }
64
65    pub fn dispose(&self) {
66        self.emulator.borrow_mut().dispose();
67    }
68}