nautilus_execution/engine/
stubs.rs1use 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#[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 #[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 }
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(()) }
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(()) }
123
124 fn submit_order_list(&self, _cmd: &SubmitOrderList) -> anyhow::Result<()> {
125 Ok(()) }
127
128 fn modify_order(&self, _cmd: &ModifyOrder) -> anyhow::Result<()> {
129 Ok(()) }
131
132 fn cancel_order(&self, _cmd: &CancelOrder) -> anyhow::Result<()> {
133 Ok(()) }
135
136 fn cancel_all_orders(&self, _cmd: &CancelAllOrders) -> anyhow::Result<()> {
137 Ok(()) }
139
140 fn batch_cancel_orders(&self, _cmd: &BatchCancelOrders) -> anyhow::Result<()> {
141 Ok(()) }
143
144 fn query_account(&self, _cmd: &QueryAccount) -> anyhow::Result<()> {
145 Ok(()) }
147
148 fn query_order(&self, _cmd: &QueryOrder) -> anyhow::Result<()> {
149 Ok(()) }
151}