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_core::UnixNanos;
28use nautilus_model::{
29 enums::OmsType,
30 identifiers::{
31 AccountId, ClientId, ClientOrderId, InstrumentId, StrategyId, Venue, VenueOrderId,
32 },
33 instruments::InstrumentAny,
34 reports::{ExecutionMassStatus, FillReport, OrderStatusReport, PositionStatusReport},
35};
36
37pub mod core;
38
39use nautilus_common::clients::ExecutionClient;
40
41pub struct ExecutionClientAdapter {
43 pub(crate) client: Box<dyn ExecutionClient>,
44 pub client_id: ClientId,
45 pub venue: Venue,
46 pub account_id: AccountId,
47 pub oms_type: OmsType,
48}
49
50impl Deref for ExecutionClientAdapter {
51 type Target = Box<dyn ExecutionClient>;
52
53 fn deref(&self) -> &Self::Target {
54 &self.client
55 }
56}
57
58impl DerefMut for ExecutionClientAdapter {
59 fn deref_mut(&mut self) -> &mut Self::Target {
60 &mut self.client
61 }
62}
63
64impl Debug for ExecutionClientAdapter {
65 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
66 f.debug_struct(stringify!(ExecutionClientAdapter))
67 .field("client_id", &self.client_id)
68 .field("venue", &self.venue)
69 .field("account_id", &self.account_id)
70 .field("oms_type", &self.oms_type)
71 .finish()
72 }
73}
74
75impl ExecutionClientAdapter {
76 #[must_use]
78 pub fn new(client: Box<dyn ExecutionClient>) -> Self {
79 let client_id = client.client_id();
80 let venue = client.venue();
81 let account_id = client.account_id();
82 let oms_type = client.oms_type();
83
84 Self {
85 client,
86 client_id,
87 venue,
88 account_id,
89 oms_type,
90 }
91 }
92
93 pub async fn connect(&mut self) -> anyhow::Result<()> {
99 self.client.connect().await
100 }
101
102 pub async fn disconnect(&mut self) -> anyhow::Result<()> {
108 self.client.disconnect().await
109 }
110
111 pub async fn generate_order_status_report(
117 &self,
118 cmd: &GenerateOrderStatusReport,
119 ) -> anyhow::Result<Option<OrderStatusReport>> {
120 self.client.generate_order_status_report(cmd).await
121 }
122
123 pub async fn generate_order_status_reports(
129 &self,
130 cmd: &GenerateOrderStatusReports,
131 ) -> anyhow::Result<Vec<OrderStatusReport>> {
132 self.client.generate_order_status_reports(cmd).await
133 }
134
135 pub async fn generate_fill_reports(
141 &self,
142 cmd: GenerateFillReports,
143 ) -> anyhow::Result<Vec<FillReport>> {
144 self.client.generate_fill_reports(cmd).await
145 }
146
147 pub async fn generate_position_status_reports(
153 &self,
154 cmd: &GeneratePositionStatusReports,
155 ) -> anyhow::Result<Vec<PositionStatusReport>> {
156 self.client.generate_position_status_reports(cmd).await
157 }
158
159 pub async fn generate_mass_status(
165 &self,
166 lookback_mins: Option<u64>,
167 ) -> anyhow::Result<Option<ExecutionMassStatus>> {
168 self.client.generate_mass_status(lookback_mins).await
169 }
170
171 pub fn on_instrument(&mut self, instrument: InstrumentAny) {
173 self.client.on_instrument(instrument);
174 }
175
176 pub fn register_external_order(
181 &self,
182 client_order_id: ClientOrderId,
183 venue_order_id: VenueOrderId,
184 instrument_id: InstrumentId,
185 strategy_id: StrategyId,
186 ts_init: UnixNanos,
187 ) {
188 self.client.register_external_order(
189 client_order_id,
190 venue_order_id,
191 instrument_id,
192 strategy_id,
193 ts_init,
194 );
195 }
196}