nautilus_execution/client/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 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 nautilus_core::UnixNanos;
17use nautilus_model::{
18    accounts::AccountAny,
19    enums::OmsType,
20    identifiers::{AccountId, ClientId, Venue},
21    types::{AccountBalance, MarginBalance},
22};
23
24use crate::{
25    messages::{
26        BatchCancelOrders, CancelAllOrders, CancelOrder, ModifyOrder, QueryOrder, SubmitOrder,
27        SubmitOrderList,
28        reports::{GenerateFillReports, GenerateOrderStatusReport, GeneratePositionReports},
29    },
30    reports::{
31        fill::FillReport, mass_status::ExecutionMassStatus, order::OrderStatusReport,
32        position::PositionStatusReport,
33    },
34};
35
36pub mod base;
37
38pub trait ExecutionClient {
39    fn is_connected(&self) -> bool;
40    fn client_id(&self) -> ClientId;
41    fn account_id(&self) -> AccountId;
42    fn venue(&self) -> Venue;
43    fn oms_type(&self) -> OmsType;
44    fn get_account(&self) -> Option<AccountAny>;
45    fn generate_account_state(
46        &self,
47        balances: Vec<AccountBalance>,
48        margins: Vec<MarginBalance>,
49        reported: bool,
50        ts_event: UnixNanos,
51    ) -> anyhow::Result<()>;
52    fn start(&mut self) -> anyhow::Result<()>;
53    fn stop(&mut self) -> anyhow::Result<()>;
54    fn submit_order(&self, command: SubmitOrder) -> anyhow::Result<()>;
55    fn submit_order_list(&self, command: SubmitOrderList) -> anyhow::Result<()>;
56    fn modify_order(&self, command: ModifyOrder) -> anyhow::Result<()>;
57    fn cancel_order(&self, command: CancelOrder) -> anyhow::Result<()>;
58    fn cancel_all_orders(&self, command: CancelAllOrders) -> anyhow::Result<()>;
59    fn batch_cancel_orders(&self, command: BatchCancelOrders) -> anyhow::Result<()>;
60    fn query_order(&self, command: QueryOrder) -> anyhow::Result<()>;
61}
62
63pub trait LiveExecutionClient: ExecutionClient {
64    fn connect(&self) -> anyhow::Result<()>;
65    fn disconnect(&self) -> anyhow::Result<()>;
66    fn generate_order_status_report(
67        &self,
68        report: GenerateOrderStatusReport,
69    ) -> anyhow::Result<Option<OrderStatusReport>>;
70    fn generate_order_status_reports(
71        &self,
72        report: GenerateOrderStatusReport,
73    ) -> anyhow::Result<Vec<OrderStatusReport>>;
74    fn generate_fill_reports(&self, report: GenerateFillReports)
75    -> anyhow::Result<Vec<FillReport>>;
76    fn generate_position_status_reports(
77        &self,
78        report: GeneratePositionReports,
79    ) -> anyhow::Result<Vec<PositionStatusReport>>;
80    fn generate_mass_status(
81        &self,
82        lookback_mins: Option<u64>,
83    ) -> anyhow::Result<Option<ExecutionMassStatus>>;
84}