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 std::fmt::Display;
1718use nautilus_core::{UUID4, UnixNanos};
19use nautilus_model::{
20 enums::{LiquiditySide, OrderSide},
21 identifiers::{AccountId, ClientOrderId, InstrumentId, PositionId, TradeId, VenueOrderId},
22 types::{Money, Price, Quantity},
23};
24use serde::{Deserialize, Serialize};
2526/// Represents a fill report of a single order execution.
27#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
28#[serde(tag = "type")]
29#[cfg_attr(
30 feature = "python",
31 pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.execution")
32)]
33pub struct FillReport {
34/// The account ID associated with the position.
35pub account_id: AccountId,
36/// The instrument ID associated with the event.
37pub instrument_id: InstrumentId,
38/// The venue assigned order ID.
39pub venue_order_id: VenueOrderId,
40/// The trade match ID (assigned by the venue).
41pub trade_id: TradeId,
42/// The order side.
43pub order_side: OrderSide,
44/// The last fill quantity for the position.
45pub last_qty: Quantity,
46/// The last fill price for the position.
47pub last_px: Price,
48/// The commission generated from the fill.
49pub commission: Money,
50/// The liquidity side of the execution.
51pub liquidity_side: LiquiditySide,
52/// The unique identifier for the event.
53pub report_id: UUID4,
54/// UNIX timestamp (nanoseconds) when the event occurred.
55pub ts_event: UnixNanos,
56/// UNIX timestamp (nanoseconds) when the event was initialized.
57pub ts_init: UnixNanos,
58/// The client order ID.
59pub client_order_id: Option<ClientOrderId>,
60/// The position ID (assigned by the venue).
61pub venue_position_id: Option<PositionId>,
62}
6364impl FillReport {
65/// Creates a new [`FillReport`] instance with required fields.
66#[allow(clippy::too_many_arguments)]
67 #[must_use]
68pub fn new(
69 account_id: AccountId,
70 instrument_id: InstrumentId,
71 venue_order_id: VenueOrderId,
72 trade_id: TradeId,
73 order_side: OrderSide,
74 last_qty: Quantity,
75 last_px: Price,
76 commission: Money,
77 liquidity_side: LiquiditySide,
78 client_order_id: Option<ClientOrderId>,
79 venue_position_id: Option<PositionId>,
80 ts_event: UnixNanos,
81 ts_init: UnixNanos,
82 report_id: Option<UUID4>,
83 ) -> Self {
84Self {
85 account_id,
86 instrument_id,
87 venue_order_id,
88 trade_id,
89 order_side,
90 last_qty,
91 last_px,
92 commission,
93 liquidity_side,
94 report_id: report_id.unwrap_or_default(),
95 ts_event,
96 ts_init,
97 client_order_id,
98 venue_position_id,
99 }
100 }
101102/// Checks if the fill has a client order ID.
103#[must_use]
104pub const fn has_client_order_id(&self) -> bool {
105self.client_order_id.is_some()
106 }
107108/// Utility method to check if the fill has a venue position ID.
109#[must_use]
110pub const fn has_venue_position_id(&self) -> bool {
111self.venue_position_id.is_some()
112 }
113}
114115impl Display for FillReport {
116fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
117write!(
118 f,
119"FillReport(instrument={}, side={}, qty={}, last_px={}, trade_id={}, venue_order_id={}, commission={}, liquidity={})",
120self.instrument_id,
121self.order_side,
122self.last_qty,
123self.last_px,
124self.trade_id,
125self.venue_order_id,
126self.commission,
127self.liquidity_side,
128 )
129 }
130}