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