nautilus_execution/reconciliation/mod.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
16//! Execution state reconciliation.
17//!
18//! Pure functions for bringing the engine's local order, fill, and position state
19//! into line with what the venue reports. Called at startup (mass status) and
20//! continuously at runtime (open-order and position checks).
21//!
22//! Public entry points:
23//! - [`process_mass_status_for_reconciliation`] - partial-window fill reconstruction
24//! - [`reconcile_order_report`] - bring a cached order into line with a venue report
25//! - [`reconcile_fill_report`] - apply a venue fill to a cached order, with dedup
26//! - [`check_position_reconciliation`] - final qty and avg-px tolerance check
27//!
28//! Invariants maintained across all paths:
29//! 1. Final position quantity matches the venue within instrument precision.
30//! 2. Position average price matches within tolerance (default 0.01%).
31//! 3. All generated fills preserve correct unrealized PnL.
32//! 4. Synthetic `trade_id` and `venue_order_id` values are deterministic
33//! functions of the logical event, so restart replays dedupe.
34//!
35//! See `docs/concepts/live.md` for the operator-facing description.
36
37mod ids;
38mod orders;
39mod positions;
40mod types;
41
42#[cfg(test)]
43mod proptests;
44#[cfg(test)]
45mod tests;
46
47pub use ids::{
48 create_inferred_reconciliation_trade_id, create_position_reconciliation_venue_order_id,
49 create_synthetic_trade_id, create_synthetic_venue_order_id,
50};
51pub use orders::{
52 create_incremental_inferred_fill, create_inferred_fill, create_inferred_fill_for_qty,
53 create_reconciliation_accepted, create_reconciliation_canceled, create_reconciliation_expired,
54 create_reconciliation_rejected, create_reconciliation_triggered, create_reconciliation_updated,
55 generate_external_order_status_events, generate_reconciliation_order_events,
56 reconcile_fill_report, reconcile_order_report, should_reconciliation_update,
57};
58pub use positions::{
59 adjust_fills_for_partial_window, calculate_reconciliation_price, check_position_match,
60 check_position_reconciliation, create_synthetic_fill_report, create_synthetic_order_report,
61 detect_zero_crossings, is_within_single_unit_tolerance, process_mass_status_for_reconciliation,
62 simulate_position,
63};
64pub use types::{FillAdjustmentResult, FillSnapshot, ReconciliationResult, VenuePositionSnapshot};