nautilus_common/clients/execution.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
16//! Execution client trait definition.
17
18use async_trait::async_trait;
19use nautilus_core::UnixNanos;
20use nautilus_model::{
21 accounts::AccountAny,
22 enums::OmsType,
23 identifiers::{AccountId, ClientId, Venue},
24 reports::{ExecutionMassStatus, FillReport, OrderStatusReport, PositionStatusReport},
25 types::{AccountBalance, MarginBalance},
26};
27
28use super::log_not_implemented;
29use crate::messages::execution::{
30 BatchCancelOrders, CancelAllOrders, CancelOrder, GenerateFillReports,
31 GenerateOrderStatusReport, GenerateOrderStatusReports, GeneratePositionStatusReports,
32 ModifyOrder, QueryAccount, QueryOrder, SubmitOrder, SubmitOrderList,
33};
34
35/// Defines the interface for an execution client managing order operations.
36///
37/// # Thread Safety
38///
39/// Client instances are not intended to be sent across threads. The `?Send` bound
40/// allows implementations to hold non-Send state for any Python interop.
41#[async_trait(?Send)]
42pub trait ExecutionClient {
43 fn is_connected(&self) -> bool;
44 fn client_id(&self) -> ClientId;
45 fn account_id(&self) -> AccountId;
46 fn venue(&self) -> Venue;
47 fn oms_type(&self) -> OmsType;
48 fn get_account(&self) -> Option<AccountAny>;
49
50 /// Generates and publishes the account state event.
51 ///
52 /// # Errors
53 ///
54 /// Returns an error if generating the account state fails.
55 fn generate_account_state(
56 &self,
57 balances: Vec<AccountBalance>,
58 margins: Vec<MarginBalance>,
59 reported: bool,
60 ts_event: UnixNanos,
61 ) -> anyhow::Result<()>;
62
63 /// Starts the execution client.
64 ///
65 /// # Errors
66 ///
67 /// Returns an error if the client fails to start.
68 fn start(&mut self) -> anyhow::Result<()>;
69
70 /// Stops the execution client.
71 ///
72 /// # Errors
73 ///
74 /// Returns an error if the client fails to stop.
75 fn stop(&mut self) -> anyhow::Result<()>;
76
77 /// Connects the client to the execution venue.
78 ///
79 /// # Errors
80 ///
81 /// Returns an error if connection fails.
82 async fn connect(&mut self) -> anyhow::Result<()> {
83 Ok(())
84 }
85
86 /// Disconnects the client from the execution venue.
87 ///
88 /// # Errors
89 ///
90 /// Returns an error if disconnection fails.
91 async fn disconnect(&mut self) -> anyhow::Result<()> {
92 Ok(())
93 }
94
95 /// Submits a single order command to the execution venue.
96 ///
97 /// # Errors
98 ///
99 /// Returns an error if submission fails.
100 fn submit_order(&self, cmd: &SubmitOrder) -> anyhow::Result<()> {
101 log_not_implemented(cmd);
102 Ok(())
103 }
104
105 /// Submits a list of orders to the execution venue.
106 ///
107 /// # Errors
108 ///
109 /// Returns an error if submission fails.
110 fn submit_order_list(&self, cmd: &SubmitOrderList) -> anyhow::Result<()> {
111 log_not_implemented(cmd);
112 Ok(())
113 }
114
115 /// Modifies an existing order.
116 ///
117 /// # Errors
118 ///
119 /// Returns an error if modification fails.
120 fn modify_order(&self, cmd: &ModifyOrder) -> anyhow::Result<()> {
121 log_not_implemented(cmd);
122 Ok(())
123 }
124
125 /// Cancels a specific order.
126 ///
127 /// # Errors
128 ///
129 /// Returns an error if cancellation fails.
130 fn cancel_order(&self, cmd: &CancelOrder) -> anyhow::Result<()> {
131 log_not_implemented(cmd);
132 Ok(())
133 }
134
135 /// Cancels all orders.
136 ///
137 /// # Errors
138 ///
139 /// Returns an error if cancellation fails.
140 fn cancel_all_orders(&self, cmd: &CancelAllOrders) -> anyhow::Result<()> {
141 log_not_implemented(cmd);
142 Ok(())
143 }
144
145 /// Cancels a batch of orders.
146 ///
147 /// # Errors
148 ///
149 /// Returns an error if batch cancellation fails.
150 fn batch_cancel_orders(&self, cmd: &BatchCancelOrders) -> anyhow::Result<()> {
151 log_not_implemented(cmd);
152 Ok(())
153 }
154
155 /// Queries the status of an account.
156 ///
157 /// # Errors
158 ///
159 /// Returns an error if the query fails.
160 fn query_account(&self, cmd: &QueryAccount) -> anyhow::Result<()> {
161 log_not_implemented(cmd);
162 Ok(())
163 }
164
165 /// Queries the status of an order.
166 ///
167 /// # Errors
168 ///
169 /// Returns an error if the query fails.
170 fn query_order(&self, cmd: &QueryOrder) -> anyhow::Result<()> {
171 log_not_implemented(cmd);
172 Ok(())
173 }
174
175 /// Generates a single order status report.
176 ///
177 /// # Errors
178 ///
179 /// Returns an error if report generation fails.
180 async fn generate_order_status_report(
181 &self,
182 cmd: &GenerateOrderStatusReport,
183 ) -> anyhow::Result<Option<OrderStatusReport>> {
184 log_not_implemented(cmd);
185 Ok(None)
186 }
187
188 /// Generates multiple order status reports.
189 ///
190 /// # Errors
191 ///
192 /// Returns an error if report generation fails.
193 async fn generate_order_status_reports(
194 &self,
195 cmd: &GenerateOrderStatusReports,
196 ) -> anyhow::Result<Vec<OrderStatusReport>> {
197 log_not_implemented(cmd);
198 Ok(Vec::new())
199 }
200
201 /// Generates fill reports based on execution results.
202 ///
203 /// # Errors
204 ///
205 /// Returns an error if fill report generation fails.
206 async fn generate_fill_reports(
207 &self,
208 cmd: GenerateFillReports,
209 ) -> anyhow::Result<Vec<FillReport>> {
210 log_not_implemented(&cmd);
211 Ok(Vec::new())
212 }
213
214 /// Generates position status reports.
215 ///
216 /// # Errors
217 ///
218 /// Returns an error if generation fails.
219 async fn generate_position_status_reports(
220 &self,
221 cmd: &GeneratePositionStatusReports,
222 ) -> anyhow::Result<Vec<PositionStatusReport>> {
223 log_not_implemented(cmd);
224 Ok(Vec::new())
225 }
226
227 /// Generates mass status for executions.
228 ///
229 /// # Errors
230 ///
231 /// Returns an error if status generation fails.
232 async fn generate_mass_status(
233 &self,
234 lookback_mins: Option<u64>,
235 ) -> anyhow::Result<Option<ExecutionMassStatus>> {
236 log_not_implemented(&lookback_mins);
237 Ok(None)
238 }
239}