nautilus_execution/engine/
stubs.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::{cell::RefCell, rc::Rc};
17
18use async_trait::async_trait;
19use nautilus_common::{
20    cache::Cache,
21    clients::ExecutionClient,
22    clock::{Clock, TestClock},
23    messages::execution::{
24        BatchCancelOrders, CancelAllOrders, CancelOrder, ModifyOrder, QueryAccount, QueryOrder,
25        SubmitOrder, SubmitOrderList,
26    },
27};
28use nautilus_core::UnixNanos;
29use nautilus_model::{
30    accounts::AccountAny,
31    enums::OmsType,
32    identifiers::{AccountId, ClientId, Venue},
33    types::{AccountBalance, MarginBalance},
34};
35
36/// A stub execution client for testing purposes.
37///
38/// This client provides a minimal implementation of the `ExecutionClient` trait
39/// that can be used in unit tests without requiring actual venue connectivity.
40#[derive(Clone, Debug)]
41#[allow(dead_code)]
42pub struct StubExecutionClient {
43    client_id: ClientId,
44    account_id: AccountId,
45    venue: Venue,
46    oms_type: OmsType,
47    is_connected: bool,
48    clock: Rc<RefCell<dyn Clock>>,
49    cache: Rc<RefCell<Cache>>,
50}
51
52impl StubExecutionClient {
53    /// Creates a new [`StubExecutionClient`] instance.
54    #[allow(dead_code)]
55    pub fn new(
56        client_id: ClientId,
57        account_id: AccountId,
58        venue: Venue,
59        oms_type: OmsType,
60        clock: Option<Rc<RefCell<dyn Clock>>>,
61    ) -> Self {
62        Self {
63            client_id,
64            account_id,
65            venue,
66            oms_type,
67            is_connected: false,
68            clock: clock.unwrap_or_else(|| Rc::new(RefCell::new(TestClock::new()))),
69            cache: Rc::new(RefCell::new(Cache::new(None, None))),
70        }
71    }
72}
73
74#[async_trait(?Send)]
75impl ExecutionClient for StubExecutionClient {
76    fn is_connected(&self) -> bool {
77        self.is_connected
78    }
79
80    fn client_id(&self) -> ClientId {
81        self.client_id
82    }
83
84    fn account_id(&self) -> AccountId {
85        self.account_id
86    }
87
88    fn venue(&self) -> Venue {
89        self.venue
90    }
91
92    fn oms_type(&self) -> OmsType {
93        self.oms_type
94    }
95
96    fn get_account(&self) -> Option<AccountAny> {
97        None // Stub implementation returns None
98    }
99
100    fn generate_account_state(
101        &self,
102        _balances: Vec<AccountBalance>,
103        _margins: Vec<MarginBalance>,
104        _reported: bool,
105        _ts_event: UnixNanos,
106    ) -> anyhow::Result<()> {
107        Ok(()) // Stub implementation always succeeds
108    }
109
110    fn start(&mut self) -> anyhow::Result<()> {
111        self.is_connected = true;
112        Ok(())
113    }
114
115    fn stop(&mut self) -> anyhow::Result<()> {
116        self.is_connected = false;
117        Ok(())
118    }
119
120    fn submit_order(&self, _cmd: &SubmitOrder) -> anyhow::Result<()> {
121        Ok(()) // Stub implementation always succeeds
122    }
123
124    fn submit_order_list(&self, _cmd: &SubmitOrderList) -> anyhow::Result<()> {
125        Ok(()) // Stub implementation always succeeds
126    }
127
128    fn modify_order(&self, _cmd: &ModifyOrder) -> anyhow::Result<()> {
129        Ok(()) // Stub implementation always succeeds
130    }
131
132    fn cancel_order(&self, _cmd: &CancelOrder) -> anyhow::Result<()> {
133        Ok(()) // Stub implementation always succeeds
134    }
135
136    fn cancel_all_orders(&self, _cmd: &CancelAllOrders) -> anyhow::Result<()> {
137        Ok(()) // Stub implementation always succeeds
138    }
139
140    fn batch_cancel_orders(&self, _cmd: &BatchCancelOrders) -> anyhow::Result<()> {
141        Ok(()) // Stub implementation always succeeds
142    }
143
144    fn query_account(&self, _cmd: &QueryAccount) -> anyhow::Result<()> {
145        Ok(()) // Stub implementation always succeeds
146    }
147
148    fn query_order(&self, _cmd: &QueryOrder) -> anyhow::Result<()> {
149        Ok(()) // Stub implementation always succeeds
150    }
151}