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