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