nautilus_model/reports/
mass_status.rs1use 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#[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 pub client_id: ClientId,
36 pub account_id: AccountId,
38 pub venue: Venue,
40 pub report_id: UUID4,
42 pub ts_init: UnixNanos,
44 order_reports: IndexMap<VenueOrderId, OrderStatusReport>,
46 fill_reports: IndexMap<VenueOrderId, Vec<FillReport>>,
48 position_reports: IndexMap<InstrumentId, Vec<PositionStatusReport>>,
50}
51
52impl ExecutionMassStatus {
53 #[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 #[must_use]
76 pub fn order_reports(&self) -> IndexMap<VenueOrderId, OrderStatusReport> {
77 self.order_reports.clone()
78 }
79
80 #[must_use]
82 pub fn fill_reports(&self) -> IndexMap<VenueOrderId, Vec<FillReport>> {
83 self.fill_reports.clone()
84 }
85
86 #[must_use]
88 pub fn position_reports(&self) -> IndexMap<InstrumentId, Vec<PositionStatusReport>> {
89 self.position_reports.clone()
90 }
91
92 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 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 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}