nautilus_model/reports/
mass_status.rs

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