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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// 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 cratePolicyGroupId;
use crate;
use crateAccountBlock;
/// A delta/absolute pair for one position field.
/// A delta/absolute pair for a realized PnL field.
/// Result of one realized-PnL calculation.
///
/// The value is authoritative only when the result is `Ok`. An `Err` explains
/// why the calculation halted for the current operation.
pub type PnlOutcome = ;
/// Current state of a realized-PnL accumulator.
/// Account-level realized PnL outcome for one account ledger.
///
/// SpotFunds emits an outcome only when a fill reduces, closes, or reverses a
/// position, or when a non-zero fee contributes to the ledger. Opening,
/// same-direction, and zero-quantity fills without a non-zero fee omit the
/// account line. A zero fee alone also omits it.
///
/// SpotFunds emits a halted outcome only for the operation that transitions
/// the ledger to halted. Later operations omit the unchanged halt until an
/// explicit account-PnL correction re-arms the ledger.
/// Reason why a realized-PnL calculation halted.
///
/// When one operation encounters multiple failures, SpotFunds selects one
/// reason in this priority order:
///
/// 1. [`ArithmeticOverflow`](Self::ArithmeticOverflow)
/// 2. [`MissingAccountCurrency`](Self::MissingAccountCurrency)
/// 3. [`MissingFx`](Self::MissingFx)
/// 4. [`MissingCostBasis`](Self::MissingCostBasis)
/// 5. [`MissingInitialPnl`](Self::MissingInitialPnl)
/// Raw outcome data produced by a policy for one asset.
///
/// Policies return `Vec<AccountOutcomeEntry>` without group information;
/// the engine attaches the policy's [`PolicyGroupId`] when assembling the final
/// [`AccountAdjustmentBatchResult`] (for batch hooks) or
/// [`crate::pretrade::PreTradeReservation::account_adjustments`] (for regular
/// pre-trade) or
/// [`crate::pretrade::DropCopyOperation::account_adjustments`] (for
/// an applied drop-copy operation).
/// Account position outcome with the group tag of the business entity that
/// produced it.
///
/// The engine wraps each [`AccountOutcomeEntry`] returned by a policy with
/// that business entity's [`PolicyGroupId`] before appending it to the result list.
/// Business entities sharing a group tag produce adjacent entries with the same
/// `policy_group_id`, in business entity registration order.
/// Outcome of a successful [`crate::Engine::apply_account_adjustment`] batch.