nautilus_execution/client/
mod.rs1use std::{
19 fmt::Debug,
20 ops::{Deref, DerefMut},
21};
22
23use nautilus_common::messages::execution::{
24 GenerateFillReports, GenerateOrderStatusReport, GenerateOrderStatusReports,
25 GeneratePositionStatusReports,
26};
27use nautilus_model::{
28 enums::OmsType,
29 identifiers::{AccountId, ClientId, Venue},
30 reports::{ExecutionMassStatus, FillReport, OrderStatusReport, PositionStatusReport},
31};
32
33pub mod base;
34
35use nautilus_common::clients::ExecutionClient;
36
37pub struct ExecutionClientAdapter {
39 pub(crate) client: Box<dyn ExecutionClient>,
40 pub client_id: ClientId,
41 pub venue: Venue,
42 pub account_id: AccountId,
43 pub oms_type: OmsType,
44}
45
46impl Deref for ExecutionClientAdapter {
47 type Target = Box<dyn ExecutionClient>;
48
49 fn deref(&self) -> &Self::Target {
50 &self.client
51 }
52}
53
54impl DerefMut for ExecutionClientAdapter {
55 fn deref_mut(&mut self) -> &mut Self::Target {
56 &mut self.client
57 }
58}
59
60impl Debug for ExecutionClientAdapter {
61 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62 f.debug_struct(stringify!(ExecutionClientAdapter))
63 .field("client_id", &self.client_id)
64 .field("venue", &self.venue)
65 .field("account_id", &self.account_id)
66 .field("oms_type", &self.oms_type)
67 .finish()
68 }
69}
70
71impl ExecutionClientAdapter {
72 #[must_use]
74 pub fn new(client: Box<dyn ExecutionClient>) -> Self {
75 let client_id = client.client_id();
76 let venue = client.venue();
77 let account_id = client.account_id();
78 let oms_type = client.oms_type();
79
80 Self {
81 client,
82 client_id,
83 venue,
84 account_id,
85 oms_type,
86 }
87 }
88
89 pub async fn connect(&mut self) -> anyhow::Result<()> {
95 self.client.connect().await
96 }
97
98 pub async fn disconnect(&mut self) -> anyhow::Result<()> {
104 self.client.disconnect().await
105 }
106
107 pub async fn generate_order_status_report(
113 &self,
114 cmd: &GenerateOrderStatusReport,
115 ) -> anyhow::Result<Option<OrderStatusReport>> {
116 self.client.generate_order_status_report(cmd).await
117 }
118
119 pub async fn generate_order_status_reports(
125 &self,
126 cmd: &GenerateOrderStatusReports,
127 ) -> anyhow::Result<Vec<OrderStatusReport>> {
128 self.client.generate_order_status_reports(cmd).await
129 }
130
131 pub async fn generate_fill_reports(
137 &self,
138 cmd: GenerateFillReports,
139 ) -> anyhow::Result<Vec<FillReport>> {
140 self.client.generate_fill_reports(cmd).await
141 }
142
143 pub async fn generate_position_status_reports(
149 &self,
150 cmd: &GeneratePositionStatusReports,
151 ) -> anyhow::Result<Vec<PositionStatusReport>> {
152 self.client.generate_position_status_reports(cmd).await
153 }
154
155 pub async fn generate_mass_status(
161 &self,
162 lookback_mins: Option<u64>,
163 ) -> anyhow::Result<Option<ExecutionMassStatus>> {
164 self.client.generate_mass_status(lookback_mins).await
165 }
166}