rusty_model/
order_update.rs

1use crate::enums::{OrderSide, OrderStatus, OrderType, TimeInForce};
2use crate::instruments::InstrumentId;
3use crate::types::{ClientId, OrderId};
4use rust_decimal::Decimal;
5use rusty_common::SmartString;
6use serde::{Deserialize, Serialize};
7
8/// Represents an update to an order's state.
9/// This can be a partial fill, a full fill, a cancellation, or a modification.
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct OrderUpdate {
12    /// Unique identifier for this order update.
13    pub id: SmartString,
14    /// The ID of the order this update pertains to.
15    pub order_id: OrderId,
16    /// The client-generated ID for the order.
17    pub client_order_id: ClientId,
18    /// The instrument the order is for.
19    pub instrument_id: InstrumentId,
20    /// The side of the order (Buy or Sell).
21    pub side: OrderSide,
22    /// The type of order (e.g., Limit, Market).
23    pub order_type: OrderType,
24    /// The current status of the order.
25    pub status: OrderStatus,
26    /// The total quantity of the order.
27    pub original_quantity: Decimal,
28    /// The quantity that has been filled by this update.
29    pub filled_quantity: Decimal,
30    /// The remaining quantity of the order.
31    pub remaining_quantity: Decimal,
32    /// The price at which this update occurred (e.g., fill price).
33    pub price: Option<Decimal>,
34    /// The average price of all fills for this order.
35    pub average_fill_price: Option<Decimal>,
36    /// The time in force for the order.
37    pub time_in_force: Option<TimeInForce>,
38    /// Exchange-specific execution ID for this update.
39    pub exchange_execution_id: Option<SmartString>,
40    /// Timestamp of the update from the exchange (in nanoseconds).
41    pub exchange_timestamp: u64,
42    /// Local system timestamp when the update was processed (in nanoseconds).
43    pub system_timestamp: u64,
44    /// Any reject reason if the order was rejected or cancelled with a reason.
45    pub reject_reason: Option<SmartString>,
46    /// Indicates if this is the final update for the order (e.g., fully filled, cancelled, rejected).
47    pub is_final: bool,
48}
49
50impl OrderUpdate {
51    /// Creates a new `OrderUpdate` instance.
52    #[allow(clippy::too_many_arguments)]
53    #[must_use]
54    pub const fn new(
55        id: SmartString,
56        order_id: OrderId,
57        client_order_id: ClientId,
58        instrument_id: InstrumentId,
59        side: OrderSide,
60        order_type: OrderType,
61        status: OrderStatus,
62        original_quantity: Decimal,
63        filled_quantity: Decimal,
64        remaining_quantity: Decimal,
65        price: Option<Decimal>,
66        average_fill_price: Option<Decimal>,
67        time_in_force: Option<TimeInForce>,
68        exchange_execution_id: Option<SmartString>,
69        exchange_timestamp: u64,
70        system_timestamp: u64,
71        reject_reason: Option<SmartString>,
72        is_final: bool,
73    ) -> Self {
74        Self {
75            id,
76            order_id,
77            client_order_id,
78            instrument_id,
79            side,
80            order_type,
81            status,
82            original_quantity,
83            filled_quantity,
84            remaining_quantity,
85            price,
86            average_fill_price,
87            time_in_force,
88            exchange_execution_id,
89            exchange_timestamp,
90            system_timestamp,
91            reject_reason,
92            is_final,
93        }
94    }
95}