nautilus_live/execution/
client.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
16//! Execution client definitions for live trading.
17
18use std::{cell::Ref, fmt::Debug};
19
20use async_trait::async_trait;
21use nautilus_common::{
22    clock::Clock,
23    messages::{
24        ExecutionEvent,
25        execution::{GenerateFillReports, GenerateOrderStatusReport, GeneratePositionReports},
26    },
27};
28use nautilus_execution::client::ExecutionClient;
29use nautilus_model::reports::{
30    ExecutionMassStatus, FillReport, OrderStatusReport, PositionStatusReport,
31};
32
33#[async_trait(?Send)]
34pub trait LiveExecutionClient: ExecutionClient {
35    /// Establishes a connection for live execution.
36    ///
37    /// # Errors
38    ///
39    /// Returns an error if connection fails.
40    async fn connect(&mut self) -> anyhow::Result<()>;
41
42    /// Disconnects the live execution client.
43    ///
44    /// # Errors
45    ///
46    /// Returns an error if disconnection fails.
47    async fn disconnect(&mut self) -> anyhow::Result<()>;
48
49    fn get_message_channel(&self) -> tokio::sync::mpsc::UnboundedSender<ExecutionEvent>;
50
51    fn get_clock(&self) -> Ref<'_, dyn Clock>;
52
53    /// Generates a single order status report.
54    ///
55    /// # Errors
56    ///
57    /// Returns an error if report generation fails.
58    async fn generate_order_status_report(
59        &self,
60        cmd: &GenerateOrderStatusReport,
61    ) -> anyhow::Result<Option<OrderStatusReport>> {
62        log_not_implemented(cmd);
63        Ok(None)
64    }
65
66    /// Generates multiple order status reports.
67    ///
68    /// # Errors
69    ///
70    /// Returns an error if report generation fails.
71    async fn generate_order_status_reports(
72        &self,
73        cmd: &GenerateOrderStatusReport,
74    ) -> anyhow::Result<Vec<OrderStatusReport>> {
75        log_not_implemented(cmd);
76        Ok(Vec::new())
77    }
78
79    /// Generates fill reports based on execution results.
80    ///
81    /// # Errors
82    ///
83    /// Returns an error if fill report generation fails.
84    async fn generate_fill_reports(
85        &self,
86        cmd: GenerateFillReports,
87    ) -> anyhow::Result<Vec<FillReport>> {
88        log_not_implemented(&cmd);
89        Ok(Vec::new())
90    }
91
92    /// Generates position status reports.
93    ///
94    /// # Errors
95    ///
96    /// Returns an error if generation fails.
97    async fn generate_position_status_reports(
98        &self,
99        cmd: &GeneratePositionReports,
100    ) -> anyhow::Result<Vec<PositionStatusReport>> {
101        log_not_implemented(cmd);
102        Ok(Vec::new())
103    }
104
105    /// Generates mass status for executions.
106    ///
107    /// # Errors
108    ///
109    /// Returns an error if status generation fails.
110    async fn generate_mass_status(
111        &self,
112        lookback_mins: Option<u64>,
113    ) -> anyhow::Result<Option<ExecutionMassStatus>> {
114        log_not_implemented(&lookback_mins);
115        Ok(None)
116    }
117}
118
119#[inline(always)]
120fn log_not_implemented<T: Debug>(cmd: &T) {
121    log::warn!("{cmd:?} – handler not implemented");
122}