nautilus_execution/order_emulator/
adapter.rs1use 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 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}