Skip to main content

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//! - [`generate_reconciliation_order_events`] - venue-temporal event sequence for a report
25//! - [`reconcile_order_report`] - core order-state reconciliation
26//! - [`reconcile_fill_report`] - apply a venue fill to a cached order, with dedup
27//! - [`generate_external_order_status_events`] - synthesize events for an external order
28//! - [`check_position_reconciliation`] - final qty and avg-px tolerance check
29//!
30//! Invariants maintained across all paths:
31//! 1. Final position quantity matches the venue within instrument precision.
32//! 2. Position average price matches within tolerance (default 0.01%).
33//! 3. All generated fills preserve correct unrealized PnL.
34//! 4. Synthetic `trade_id` and `venue_order_id` values are deterministic
35//!    functions of the logical event, so restart replays dedupe.
36//!
37//! See `docs/concepts/live.md` for the operator-facing description.
38
39mod ids;
40mod orders;
41mod positions;
42mod types;
43
44#[cfg(test)]
45mod proptests;
46#[cfg(test)]
47mod tests;
48
49pub use ids::{
50    create_inferred_reconciliation_trade_id, create_position_reconciliation_venue_order_id,
51};
52pub use orders::{
53    create_incremental_inferred_fill, create_inferred_fill_for_qty, create_reconciliation_rejected,
54    create_reconciliation_triggered, generate_external_order_status_events,
55    generate_reconciliation_order_events, reconcile_fill_report, reconcile_order_report,
56    should_reconciliation_update,
57};
58pub use positions::{
59    calculate_reconciliation_price, check_position_reconciliation,
60    process_mass_status_for_reconciliation,
61};
62pub use types::ReconciliationResult;