Skip to main content

nautilus_common/messages/execution/
report.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
16use std::fmt::Display;
17
18use derive_builder::Builder;
19use nautilus_core::{Params, UUID4, UnixNanos};
20use nautilus_model::identifiers::{
21    ClientId, ClientOrderId, InstrumentId, TraderId, Venue, VenueOrderId,
22};
23use serde::{Deserialize, Serialize};
24
25use crate::enums::LogLevel;
26
27const fn default_report_log_level() -> LogLevel {
28    LogLevel::Info
29}
30
31#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Builder)]
32pub struct GenerateOrderStatusReport {
33    #[builder(default = "UUID4::new()")]
34    pub command_id: UUID4,
35    pub ts_init: UnixNanos,
36    #[builder(default)]
37    pub instrument_id: Option<InstrumentId>,
38    #[builder(default)]
39    pub client_order_id: Option<ClientOrderId>,
40    #[builder(default)]
41    pub venue_order_id: Option<VenueOrderId>,
42    #[builder(default)]
43    pub params: Option<Params>,
44    #[builder(default)]
45    #[serde(default, skip_serializing_if = "Option::is_none")]
46    pub correlation_id: Option<UUID4>,
47    #[builder(default)]
48    #[serde(default, skip_serializing_if = "Option::is_none")]
49    pub causation_id: Option<UUID4>,
50}
51
52impl GenerateOrderStatusReport {
53    #[must_use]
54    pub fn new(
55        command_id: UUID4,
56        ts_init: UnixNanos,
57        instrument_id: Option<InstrumentId>,
58        client_order_id: Option<ClientOrderId>,
59        venue_order_id: Option<VenueOrderId>,
60        params: Option<Params>,
61        correlation_id: Option<UUID4>,
62    ) -> Self {
63        Self {
64            command_id,
65            ts_init,
66            instrument_id,
67            client_order_id,
68            venue_order_id,
69            params,
70            correlation_id,
71            causation_id: None,
72        }
73    }
74}
75
76impl Display for GenerateOrderStatusReport {
77    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
78        write!(
79            f,
80            "{}(instrument_id={:?}, client_order_id={:?}, venue_order_id={:?}, command_id={})",
81            stringify!(GenerateOrderStatusReport),
82            self.instrument_id,
83            self.client_order_id,
84            self.venue_order_id,
85            self.command_id,
86        )
87    }
88}
89
90#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Builder)]
91pub struct GenerateOrderStatusReports {
92    #[builder(default = "UUID4::new()")]
93    pub command_id: UUID4,
94    pub ts_init: UnixNanos,
95    pub open_only: bool,
96    #[builder(default)]
97    pub instrument_id: Option<InstrumentId>,
98    #[builder(default)]
99    pub start: Option<UnixNanos>,
100    #[builder(default)]
101    pub end: Option<UnixNanos>,
102    #[builder(default)]
103    pub params: Option<Params>,
104    /// The log level for receipt logging.
105    #[builder(default = "default_report_log_level()")]
106    #[serde(default = "default_report_log_level")]
107    pub log_receipt_level: LogLevel,
108    #[builder(default)]
109    #[serde(default, skip_serializing_if = "Option::is_none")]
110    pub correlation_id: Option<UUID4>,
111    #[builder(default)]
112    #[serde(default, skip_serializing_if = "Option::is_none")]
113    pub causation_id: Option<UUID4>,
114}
115
116impl GenerateOrderStatusReports {
117    #[expect(clippy::too_many_arguments)]
118    #[must_use]
119    pub fn new(
120        command_id: UUID4,
121        ts_init: UnixNanos,
122        open_only: bool,
123        instrument_id: Option<InstrumentId>,
124        start: Option<UnixNanos>,
125        end: Option<UnixNanos>,
126        params: Option<Params>,
127        correlation_id: Option<UUID4>,
128    ) -> Self {
129        Self {
130            command_id,
131            ts_init,
132            open_only,
133            instrument_id,
134            start,
135            end,
136            params,
137            log_receipt_level: LogLevel::Info,
138            correlation_id,
139            causation_id: None,
140        }
141    }
142}
143
144impl Display for GenerateOrderStatusReports {
145    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
146        write!(
147            f,
148            "{}(open_only={}, instrument_id={:?}, command_id={})",
149            stringify!(GenerateOrderStatusReports),
150            self.open_only,
151            self.instrument_id,
152            self.command_id,
153        )
154    }
155}
156
157#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Builder)]
158pub struct GenerateFillReports {
159    #[builder(default = "UUID4::new()")]
160    pub command_id: UUID4,
161    pub ts_init: UnixNanos,
162    #[builder(default)]
163    pub instrument_id: Option<InstrumentId>,
164    #[builder(default)]
165    pub venue_order_id: Option<VenueOrderId>,
166    #[builder(default)]
167    pub start: Option<UnixNanos>,
168    #[builder(default)]
169    pub end: Option<UnixNanos>,
170    #[builder(default)]
171    pub params: Option<Params>,
172    /// The log level for receipt logging.
173    #[builder(default = "default_report_log_level()")]
174    #[serde(default = "default_report_log_level")]
175    pub log_receipt_level: LogLevel,
176    #[builder(default)]
177    #[serde(default, skip_serializing_if = "Option::is_none")]
178    pub correlation_id: Option<UUID4>,
179    #[builder(default)]
180    #[serde(default, skip_serializing_if = "Option::is_none")]
181    pub causation_id: Option<UUID4>,
182}
183
184impl GenerateFillReports {
185    #[expect(clippy::too_many_arguments)]
186    #[must_use]
187    pub fn new(
188        command_id: UUID4,
189        ts_init: UnixNanos,
190        instrument_id: Option<InstrumentId>,
191        venue_order_id: Option<VenueOrderId>,
192        start: Option<UnixNanos>,
193        end: Option<UnixNanos>,
194        params: Option<Params>,
195        correlation_id: Option<UUID4>,
196    ) -> Self {
197        Self {
198            command_id,
199            ts_init,
200            instrument_id,
201            venue_order_id,
202            start,
203            end,
204            params,
205            log_receipt_level: LogLevel::Info,
206            correlation_id,
207            causation_id: None,
208        }
209    }
210}
211
212impl Display for GenerateFillReports {
213    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
214        write!(
215            f,
216            "{}(instrument_id={:?}, venue_order_id={:?}, command_id={})",
217            stringify!(GenerateFillReports),
218            self.instrument_id,
219            self.venue_order_id,
220            self.command_id,
221        )
222    }
223}
224
225#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Builder)]
226pub struct GeneratePositionStatusReports {
227    #[builder(default = "UUID4::new()")]
228    pub command_id: UUID4,
229    pub ts_init: UnixNanos,
230    #[builder(default)]
231    pub instrument_id: Option<InstrumentId>,
232    #[builder(default)]
233    pub start: Option<UnixNanos>,
234    #[builder(default)]
235    pub end: Option<UnixNanos>,
236    #[builder(default)]
237    pub params: Option<Params>,
238    /// The log level for receipt logging.
239    #[builder(default = "default_report_log_level()")]
240    #[serde(default = "default_report_log_level")]
241    pub log_receipt_level: LogLevel,
242    #[builder(default)]
243    #[serde(default, skip_serializing_if = "Option::is_none")]
244    pub correlation_id: Option<UUID4>,
245    #[builder(default)]
246    #[serde(default, skip_serializing_if = "Option::is_none")]
247    pub causation_id: Option<UUID4>,
248}
249
250impl GeneratePositionStatusReports {
251    #[must_use]
252    pub fn new(
253        command_id: UUID4,
254        ts_init: UnixNanos,
255        instrument_id: Option<InstrumentId>,
256        start: Option<UnixNanos>,
257        end: Option<UnixNanos>,
258        params: Option<Params>,
259        correlation_id: Option<UUID4>,
260    ) -> Self {
261        Self {
262            command_id,
263            ts_init,
264            instrument_id,
265            start,
266            end,
267            params,
268            log_receipt_level: LogLevel::Info,
269            correlation_id,
270            causation_id: None,
271        }
272    }
273}
274
275impl Display for GeneratePositionStatusReports {
276    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
277        write!(
278            f,
279            "{}(instrument_id={:?}, command_id={})",
280            stringify!(GeneratePositionStatusReports),
281            self.instrument_id,
282            self.command_id,
283        )
284    }
285}
286
287#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Builder)]
288pub struct GenerateExecutionMassStatus {
289    pub trader_id: TraderId,
290    pub client_id: ClientId,
291    #[builder(default)]
292    pub venue: Option<Venue>,
293    #[builder(default = "UUID4::new()")]
294    pub command_id: UUID4,
295    pub ts_init: UnixNanos,
296    #[builder(default)]
297    pub params: Option<Params>,
298    #[builder(default)]
299    #[serde(default, skip_serializing_if = "Option::is_none")]
300    pub correlation_id: Option<UUID4>,
301    #[builder(default)]
302    #[serde(default, skip_serializing_if = "Option::is_none")]
303    pub causation_id: Option<UUID4>,
304}
305
306impl GenerateExecutionMassStatus {
307    #[must_use]
308    pub fn new(
309        trader_id: TraderId,
310        client_id: ClientId,
311        venue: Option<Venue>,
312        command_id: UUID4,
313        ts_init: UnixNanos,
314        params: Option<Params>,
315        correlation_id: Option<UUID4>,
316    ) -> Self {
317        Self {
318            trader_id,
319            client_id,
320            venue,
321            command_id,
322            ts_init,
323            params,
324            correlation_id,
325            causation_id: None,
326        }
327    }
328}
329
330impl Display for GenerateExecutionMassStatus {
331    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
332        write!(
333            f,
334            "{}(trader_id={}, client_id={}, venue={:?}, command_id={})",
335            stringify!(GenerateExecutionMassStatus),
336            self.trader_id,
337            self.client_id,
338            self.venue,
339            self.command_id,
340        )
341    }
342}