Skip to main content

nautilus_execution/matching_engine/
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};
22use nautilus_model::{
23    enums::{AccountType, BookType, OmsType},
24    instruments::InstrumentAny,
25};
26
27use crate::{
28    matching_engine::{config::OrderMatchingEngineConfig, engine::OrderMatchingEngine},
29    models::{fee::FeeModelAny, fill::FillModelAny},
30};
31
32#[derive(Debug)]
33pub struct OrderEngineAdapter {
34    engine: Rc<RefCell<OrderMatchingEngine>>,
35}
36
37impl OrderEngineAdapter {
38    #[expect(clippy::too_many_arguments)]
39    pub fn new(
40        instrument: InstrumentAny,
41        raw_id: u32,
42        fill_model: FillModelAny,
43        fee_model: FeeModelAny,
44        book_type: BookType,
45        oms_type: OmsType,
46        account_type: AccountType,
47        clock: Rc<RefCell<dyn Clock>>,
48        cache: Rc<RefCell<Cache>>,
49        config: OrderMatchingEngineConfig,
50    ) -> Self {
51        let engine = Rc::new(RefCell::new(OrderMatchingEngine::new(
52            instrument,
53            raw_id,
54            fill_model,
55            fee_model,
56            book_type,
57            oms_type,
58            account_type,
59            clock,
60            cache,
61            config,
62        )));
63
64        Self { engine }
65    }
66
67    #[must_use]
68    pub fn get_engine(&self) -> Ref<'_, OrderMatchingEngine> {
69        self.engine.borrow()
70    }
71
72    #[must_use]
73    pub fn get_engine_mut(&self) -> RefMut<'_, OrderMatchingEngine> {
74        self.engine.borrow_mut()
75    }
76}