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
134
135
136
137
// Copyright The Pit Project Owners. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// 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.
//
// Please see https://openpit.dev and the OWNERS file for details.
use ;
use crateAccountAdjustmentOutcome;
/// Inert verdict of a pre-trade dry-run.
///
/// A dry-run runs every pre-trade policy against the current engine state and
/// reports what *would* happen, with zero effect on that state: no rate-limit
/// budget is spent, no reservation or hold is applied, and no account is
/// blocked. Repeating a dry-run never moves engine state.
///
/// Unlike [`PreTradeReservation`](crate::pretrade::PreTradeReservation), this
/// report carries no commit/rollback capability. It is inert by construction -
/// there is nothing to finalize - so it exposes no `commit`/`rollback` methods.
/// The fields describe the outcome the equivalent real call would have produced:
///
/// - [`is_pass`](Self::is_pass) / [`rejects`](Self::rejects): whether the order
/// would have been admitted, and the rejects it would have collected
/// otherwise.
/// - [`lock`](Self::lock): the [`PreTradeLock`] the main stage would have
/// produced (empty when the start stage would have rejected, or when no
/// policy locks anything).
/// - [`account_adjustments`](Self::account_adjustments): the per-asset
/// `held`/`available` outcomes the main stage would have produced, with the
/// same numbers a real reservation would report for the same order and state.
/// - [`account_block`](Self::account_block): the [`AccountBlock`] an
/// account-scope reject would have latched - reported here, but *not* recorded
/// in the engine's blocked-accounts registry.
///
/// # Examples
///
/// ```rust
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use openpit::param::{Asset, Price, Quantity, Side, TradeAmount};
/// use openpit::{Engine, Instrument, OrderOperation};
/// use openpit::pretrade::policies::OrderValidationPolicy;
///
/// let engine = Engine::builder::<OrderOperation, (), ()>()
/// .no_sync()
/// .pre_trade(OrderValidationPolicy::new())
/// .build()?;
/// let order = OrderOperation {
/// instrument: Instrument::new(Asset::new("AAPL")?, Asset::new("USD")?),
/// account_id: openpit::param::AccountId::from_u64(99224416),
/// side: Side::Buy,
/// trade_amount: TradeAmount::Quantity(Quantity::from_str("10")?),
/// price: Some(Price::from_str("185")?),
/// };
///
/// // A dry-run leaves the engine untouched: a later real call behaves as if
/// // the dry-run never happened.
/// let report = engine.execute_pre_trade_dry_run(order.clone());
/// if report.is_pass() {
/// let mut reservation = engine.start_pre_trade(order)?.execute()?;
/// reservation.commit();
/// }
/// # Ok(())
/// # }
/// ```