nautilus_execution/reports/
mass_status.rs1use indexmap::IndexMap;
17use nautilus_core::{UnixNanos, UUID4};
18use nautilus_model::identifiers::{AccountId, ClientId, InstrumentId, Venue, VenueOrderId};
19use serde::{Deserialize, Serialize};
20
21use crate::reports::{fill::FillReport, order::OrderStatusReport, position::PositionStatusReport};
22
23#[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 pub client_id: ClientId,
34 pub account_id: AccountId,
36 pub venue: Venue,
38 pub report_id: UUID4,
40 pub ts_init: UnixNanos,
42 order_reports: IndexMap<VenueOrderId, OrderStatusReport>,
44 fill_reports: IndexMap<VenueOrderId, Vec<FillReport>>,
46 position_reports: IndexMap<InstrumentId, Vec<PositionStatusReport>>,
48}
49
50impl ExecutionMassStatus {
51 #[must_use]
53 pub fn new(
54 client_id: ClientId,
55 account_id: AccountId,
56 venue: Venue,
57 ts_init: UnixNanos,
58 report_id: Option<UUID4>,
59 ) -> Self {
60 Self {
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 }
71
72 #[must_use]
74 pub fn order_reports(&self) -> IndexMap<VenueOrderId, OrderStatusReport> {
75 self.order_reports.clone()
76 }
77
78 #[must_use]
80 pub fn fill_reports(&self) -> IndexMap<VenueOrderId, Vec<FillReport>> {
81 self.fill_reports.clone()
82 }
83
84 #[must_use]
86 pub fn position_reports(&self) -> IndexMap<InstrumentId, Vec<PositionStatusReport>> {
87 self.position_reports.clone()
88 }
89
90 pub fn add_order_reports(&mut self, reports: Vec<OrderStatusReport>) {
92 for report in reports {
93 self.order_reports.insert(report.venue_order_id, report);
94 }
95 }
96
97 pub fn add_fill_reports(&mut self, reports: Vec<FillReport>) {
99 for report in reports {
100 self.fill_reports
101 .entry(report.venue_order_id)
102 .or_default()
103 .push(report);
104 }
105 }
106
107 pub fn add_position_reports(&mut self, reports: Vec<PositionStatusReport>) {
109 for report in reports {
110 self.position_reports
111 .entry(report.instrument_id)
112 .or_default()
113 .push(report);
114 }
115 }
116}
117
118impl std::fmt::Display for ExecutionMassStatus {
119 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
120 write!(
121 f,
122 "ExecutionMassStatus(client_id={}, account_id={}, venue={}, order_reports={:?}, fill_reports={:?}, position_reports={:?}, report_id={}, ts_init={})",
123 self.client_id,
124 self.account_id,
125 self.venue,
126 self.order_reports,
127 self.fill_reports,
128 self.position_reports,
129 self.report_id,
130 self.ts_init,
131 )
132 }
133}