Skip to main content

nautilus_model/events/order/spec/
modify_denied.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//
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// -------------------------------------------------------------------------------------------------
15
16use nautilus_core::{UUID4, UnixNanos};
17use ustr::Ustr;
18
19use crate::{
20    events::OrderModifyDenied,
21    identifiers::{AccountId, ClientOrderId, InstrumentId, StrategyId, TraderId, VenueOrderId},
22    stubs::{TestDefault, test_uuid},
23};
24
25/// Test-only fluent spec for [`OrderModifyDenied`].
26///
27/// All fields carry sensible defaults so callers only set what differs.
28/// `build()` constructs the event through [`OrderModifyDenied::new`] so any future invariants
29/// added to the production constructor are exercised by tests built on this spec.
30#[derive(Debug, Clone, bon::Builder)]
31#[builder(finish_fn = into_spec)]
32pub struct OrderModifyDeniedSpec {
33    #[builder(default = TraderId::test_default())]
34    pub trader_id: TraderId,
35    #[builder(default = StrategyId::test_default())]
36    pub strategy_id: StrategyId,
37    #[builder(default = InstrumentId::test_default())]
38    pub instrument_id: InstrumentId,
39    #[builder(default = ClientOrderId::test_default())]
40    pub client_order_id: ClientOrderId,
41    #[builder(default = Ustr::from("TEST"))]
42    pub reason: Ustr,
43    #[builder(default = test_uuid())]
44    pub event_id: UUID4,
45    #[builder(default = UnixNanos::default())]
46    pub ts_event: UnixNanos,
47    #[builder(default = UnixNanos::default())]
48    pub ts_init: UnixNanos,
49    pub venue_order_id: Option<VenueOrderId>,
50    pub account_id: Option<AccountId>,
51    pub causation_id: Option<UUID4>,
52}
53
54impl<S: order_modify_denied_spec_builder::IsComplete> OrderModifyDeniedSpecBuilder<S> {
55    /// Builds the spec and constructs an [`OrderModifyDenied`] through its production constructor.
56    #[must_use]
57    pub fn build(self) -> OrderModifyDenied {
58        let spec = self.into_spec();
59
60        let mut event = OrderModifyDenied::new(
61            spec.trader_id,
62            spec.strategy_id,
63            spec.instrument_id,
64            spec.client_order_id,
65            spec.reason,
66            spec.event_id,
67            spec.ts_event,
68            spec.ts_init,
69            spec.venue_order_id,
70            spec.account_id,
71        );
72        event.causation_id = spec.causation_id;
73        event
74    }
75}