Skip to main content

nautilus_model/events/order/spec/
fill_voided.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 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//  Unless required by applicable law or agreed to in writing, software
9//  distributed under the License is distributed on an "AS IS" BASIS,
10//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11//  See the License for the specific language governing permissions and
12//  limitations under the License.
13// -------------------------------------------------------------------------------------------------
14
15use indexmap::IndexMap;
16use nautilus_core::{UUID4, UnixNanos};
17use ustr::Ustr;
18
19use crate::{
20    enums::{LiquiditySide, OrderSide, OrderType},
21    events::OrderFillVoided,
22    identifiers::{
23        AccountId, ClientOrderId, InstrumentId, PositionId, StrategyId, TradeId, TraderId,
24        VenueOrderId,
25    },
26    stubs::{TestDefault, test_uuid},
27    types::{Currency, Money, Price, Quantity},
28};
29
30/// Test-only fluent spec for [`OrderFillVoided`].
31#[derive(Debug, Clone, bon::Builder)]
32#[builder(finish_fn = into_spec)]
33pub struct OrderFillVoidedSpec {
34    #[builder(default = TraderId::test_default())]
35    pub trader_id: TraderId,
36    #[builder(default = StrategyId::test_default())]
37    pub strategy_id: StrategyId,
38    #[builder(default = InstrumentId::test_default())]
39    pub instrument_id: InstrumentId,
40    #[builder(default = ClientOrderId::test_default())]
41    pub client_order_id: ClientOrderId,
42    #[builder(default = VenueOrderId::test_default())]
43    pub venue_order_id: VenueOrderId,
44    #[builder(default = AccountId::test_default())]
45    pub account_id: AccountId,
46    #[builder(default = Ustr::from("CORRECTION-001"))]
47    pub correction_id: Ustr,
48    #[builder(default = TradeId::test_default())]
49    pub trade_id: TradeId,
50    #[builder(default = Quantity::new(100_000.0, 0))]
51    pub voided_qty: Quantity,
52    pub commission_voided: Option<Money>,
53    #[builder(default = OrderSide::Buy)]
54    pub order_side: OrderSide,
55    #[builder(default = OrderType::Market)]
56    pub order_type: OrderType,
57    #[builder(default = Price::from("1.00000"))]
58    pub last_px: Price,
59    #[builder(default = Currency::USD())]
60    pub currency: Currency,
61    #[builder(default = LiquiditySide::Taker)]
62    pub liquidity_side: LiquiditySide,
63    pub position_id: Option<PositionId>,
64    pub reason: Option<Ustr>,
65    pub info: Option<IndexMap<Ustr, Ustr>>,
66    #[builder(default = test_uuid())]
67    pub event_id: UUID4,
68    #[builder(default = UnixNanos::default())]
69    pub ts_event: UnixNanos,
70    #[builder(default = UnixNanos::default())]
71    pub ts_init: UnixNanos,
72    #[builder(default = false)]
73    pub reconciliation: bool,
74    #[builder(default = false)]
75    pub is_reopened: bool,
76}
77
78impl<S: order_fill_voided_spec_builder::IsComplete> OrderFillVoidedSpecBuilder<S> {
79    /// Builds the spec through the production constructor.
80    #[must_use]
81    pub fn build(self) -> OrderFillVoided {
82        let spec = self.into_spec();
83        OrderFillVoided::new(
84            spec.trader_id,
85            spec.strategy_id,
86            spec.instrument_id,
87            spec.client_order_id,
88            spec.venue_order_id,
89            spec.account_id,
90            spec.correction_id,
91            spec.trade_id,
92            spec.voided_qty,
93            spec.commission_voided,
94            spec.order_side,
95            spec.order_type,
96            spec.last_px,
97            spec.currency,
98            spec.liquidity_side,
99            spec.position_id,
100            spec.reason,
101            spec.info,
102            spec.event_id,
103            spec.ts_event,
104            spec.ts_init,
105            spec.reconciliation,
106            spec.is_reopened,
107        )
108    }
109}