nautilus_execution/reports/mass_status.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
// -------------------------------------------------------------------------------------------------
// Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
// https://nautechsystems.io
//
// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -------------------------------------------------------------------------------------------------
use indexmap::IndexMap;
use nautilus_core::{UnixNanos, UUID4};
use nautilus_model::identifiers::{AccountId, ClientId, InstrumentId, Venue, VenueOrderId};
use serde::{Deserialize, Serialize};
use crate::reports::{fill::FillReport, order::OrderStatusReport, position::PositionStatusReport};
/// Represents an execution mass status report for an execution client - including
/// status of all orders, trades for those orders and open positions.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
#[cfg_attr(
feature = "python",
pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.execution")
)]
pub struct ExecutionMassStatus {
/// The client ID for the report.
pub client_id: ClientId,
/// The account ID for the report.
pub account_id: AccountId,
/// The venue for the report.
pub venue: Venue,
/// The report ID.
pub report_id: UUID4,
/// UNIX timestamp (nanoseconds) when the object was initialized.
pub ts_init: UnixNanos,
/// The order status reports.
order_reports: IndexMap<VenueOrderId, OrderStatusReport>,
/// The fill reports.
fill_reports: IndexMap<VenueOrderId, Vec<FillReport>>,
/// The position status reports.
position_reports: IndexMap<InstrumentId, Vec<PositionStatusReport>>,
}
impl ExecutionMassStatus {
/// Creates a new execution mass status report.
#[must_use]
pub fn new(
client_id: ClientId,
account_id: AccountId,
venue: Venue,
ts_init: UnixNanos,
report_id: Option<UUID4>,
) -> Self {
Self {
client_id,
account_id,
venue,
report_id: report_id.unwrap_or_default(),
ts_init,
order_reports: IndexMap::new(),
fill_reports: IndexMap::new(),
position_reports: IndexMap::new(),
}
}
/// Get a copy of the order reports map.
#[must_use]
pub fn order_reports(&self) -> IndexMap<VenueOrderId, OrderStatusReport> {
self.order_reports.clone()
}
/// Get a copy of the fill reports map.
#[must_use]
pub fn fill_reports(&self) -> IndexMap<VenueOrderId, Vec<FillReport>> {
self.fill_reports.clone()
}
/// Get a copy of the position reports map.
#[must_use]
pub fn position_reports(&self) -> IndexMap<InstrumentId, Vec<PositionStatusReport>> {
self.position_reports.clone()
}
/// Add order reports to the mass status.
pub fn add_order_reports(&mut self, reports: Vec<OrderStatusReport>) {
for report in reports {
self.order_reports.insert(report.venue_order_id, report);
}
}
/// Add fill reports to the mass status.
pub fn add_fill_reports(&mut self, reports: Vec<FillReport>) {
for report in reports {
self.fill_reports
.entry(report.venue_order_id)
.or_default()
.push(report);
}
}
/// Add position reports to the mass status.
pub fn add_position_reports(&mut self, reports: Vec<PositionStatusReport>) {
for report in reports {
self.position_reports
.entry(report.instrument_id)
.or_default()
.push(report);
}
}
}
impl std::fmt::Display for ExecutionMassStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"ExecutionMassStatus(client_id={}, account_id={}, venue={}, order_reports={:?}, fill_reports={:?}, position_reports={:?}, report_id={}, ts_init={})",
self.client_id,
self.account_id,
self.venue,
self.order_reports,
self.fill_reports,
self.position_reports,
self.report_id,
self.ts_init,
)
}
}