1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 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// -------------------------------------------------------------------------------------------------
1516use indexmap::IndexMap;
17use nautilus_core::{UUID4, UnixNanos};
18use nautilus_model::identifiers::{AccountId, ClientId, InstrumentId, Venue, VenueOrderId};
19use serde::{Deserialize, Serialize};
2021use crate::reports::{fill::FillReport, order::OrderStatusReport, position::PositionStatusReport};
2223/// Represents an execution mass status report for an execution client - including
24/// status of all orders, trades for those orders and open positions.
25#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
26#[serde(tag = "type")]
27#[cfg_attr(
28 feature = "python",
29 pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.execution")
30)]
31pub struct ExecutionMassStatus {
32/// The client ID for the report.
33pub client_id: ClientId,
34/// The account ID for the report.
35pub account_id: AccountId,
36/// The venue for the report.
37pub venue: Venue,
38/// The report ID.
39pub report_id: UUID4,
40/// UNIX timestamp (nanoseconds) when the object was initialized.
41pub ts_init: UnixNanos,
42/// The order status reports.
43order_reports: IndexMap<VenueOrderId, OrderStatusReport>,
44/// The fill reports.
45fill_reports: IndexMap<VenueOrderId, Vec<FillReport>>,
46/// The position status reports.
47position_reports: IndexMap<InstrumentId, Vec<PositionStatusReport>>,
48}
4950impl ExecutionMassStatus {
51/// Creates a new execution mass status report.
52#[must_use]
53pub fn new(
54 client_id: ClientId,
55 account_id: AccountId,
56 venue: Venue,
57 ts_init: UnixNanos,
58 report_id: Option<UUID4>,
59 ) -> Self {
60Self {
61 client_id,
62 account_id,
63 venue,
64 report_id: report_id.unwrap_or_default(),
65 ts_init,
66 order_reports: IndexMap::new(),
67 fill_reports: IndexMap::new(),
68 position_reports: IndexMap::new(),
69 }
70 }
7172/// Get a copy of the order reports map.
73#[must_use]
74pub fn order_reports(&self) -> IndexMap<VenueOrderId, OrderStatusReport> {
75self.order_reports.clone()
76 }
7778/// Get a copy of the fill reports map.
79#[must_use]
80pub fn fill_reports(&self) -> IndexMap<VenueOrderId, Vec<FillReport>> {
81self.fill_reports.clone()
82 }
8384/// Get a copy of the position reports map.
85#[must_use]
86pub fn position_reports(&self) -> IndexMap<InstrumentId, Vec<PositionStatusReport>> {
87self.position_reports.clone()
88 }
8990/// Add order reports to the mass status.
91pub fn add_order_reports(&mut self, reports: Vec<OrderStatusReport>) {
92for report in reports {
93self.order_reports.insert(report.venue_order_id, report);
94 }
95 }
9697/// Add fill reports to the mass status.
98pub fn add_fill_reports(&mut self, reports: Vec<FillReport>) {
99for report in reports {
100self.fill_reports
101 .entry(report.venue_order_id)
102 .or_default()
103 .push(report);
104 }
105 }
106107/// Add position reports to the mass status.
108pub fn add_position_reports(&mut self, reports: Vec<PositionStatusReport>) {
109for report in reports {
110self.position_reports
111 .entry(report.instrument_id)
112 .or_default()
113 .push(report);
114 }
115 }
116}
117118impl std::fmt::Display for ExecutionMassStatus {
119fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
120write!(
121 f,
122"ExecutionMassStatus(client_id={}, account_id={}, venue={}, order_reports={:?}, fill_reports={:?}, position_reports={:?}, report_id={}, ts_init={})",
123self.client_id,
124self.account_id,
125self.venue,
126self.order_reports,
127self.fill_reports,
128self.position_reports,
129self.report_id,
130self.ts_init,
131 )
132 }
133}