pub struct ExecutionManager { /* private fields */ }Expand description
Manager for execution state.
The ExecutionManager handles:
- Startup reconciliation to align state on system start.
- Continuous reconciliation of inflight orders.
- External order discovery and claiming.
- Fill report processing and validation.
- Purging of old orders, positions, and account events.
§Thread safety
The manager shares its clock and cache through Rc<RefCell<_>> and stays on one thread.
Hosts must release cache and engine borrows before dispatching callbacks that may reenter them.
Implementations§
Source§impl ExecutionManager
impl ExecutionManager
Sourcepub fn new(
clock: Rc<RefCell<dyn Clock>>,
cache: Rc<RefCell<Cache>>,
config: ExecutionManagerConfig,
) -> ConfigResult<Self>
pub fn new( clock: Rc<RefCell<dyn Clock>>, cache: Rc<RefCell<Cache>>, config: ExecutionManagerConfig, ) -> ConfigResult<Self>
Sourcepub fn register_inflight(&mut self, client_order_id: ClientOrderId)
pub fn register_inflight(&mut self, client_order_id: ClientOrderId)
Registers an order as inflight for tracking.
Sourcepub fn record_local_activity(&mut self, client_order_id: ClientOrderId)
pub fn record_local_activity(&mut self, client_order_id: ClientOrderId)
Records local activity for the specified order.
Uses a monotonic receipt instant, not venue or domain time, to accurately track when we last processed activity for this order. This avoids race conditions where network/queue latency makes events appear “old” even though they just arrived.
Sourcepub fn recon_check_retry_count(&self, client_order_id: &ClientOrderId) -> u32
pub fn recon_check_retry_count(&self, client_order_id: &ClientOrderId) -> u32
Returns the current missing-order reconciliation retry count for the given client order ID, or zero if no entry exists.
Sourcepub fn clear_recon_tracking(
&mut self,
client_order_id: &ClientOrderId,
drop_last_query: bool,
)
pub fn clear_recon_tracking( &mut self, client_order_id: &ClientOrderId, drop_last_query: bool, )
Clears reconciliation tracking state for an order.
Sourcepub fn prune_order_local_activity(&mut self)
pub fn prune_order_local_activity(&mut self)
Prunes order activity outside the continuous reconciliation settling window.
Sourcepub fn is_fill_recently_processed(
&self,
account_id: AccountId,
instrument_id: InstrumentId,
trade_id: TradeId,
) -> bool
pub fn is_fill_recently_processed( &self, account_id: AccountId, instrument_id: InstrumentId, trade_id: TradeId, ) -> bool
Checks if a fill has been recently processed (for deduplication).
Sourcepub fn commit_recent_fill_if_applied(&mut self, fill: &OrderFilled)
pub fn commit_recent_fill_if_applied(&mut self, fill: &OrderFilled)
Marks a fill as recently processed when it is present on its canonical order.
Sourcepub fn mark_fill_processed(
&mut self,
account_id: AccountId,
instrument_id: InstrumentId,
trade_id: TradeId,
)
pub fn mark_fill_processed( &mut self, account_id: AccountId, instrument_id: InstrumentId, trade_id: TradeId, )
Marks a fill as recently processed with the current monotonic instant.
Sourcepub fn prune_recent_fills_cache(&mut self, ttl_secs: f64)
pub fn prune_recent_fills_cache(&mut self, ttl_secs: f64)
Prunes expired fills from the recent fills cache.
Default TTL is 60 seconds.
Sourcepub fn prune_processed_fills(&mut self)
pub fn prune_processed_fills(&mut self)
Prunes committed mass-reconciliation fills outside the startup report window.
An unbounded startup lookback requires indefinite retention because no finite horizon can safely exclude a replayed fill report.
Sourcepub fn record_position_activity(
&mut self,
instrument_id: InstrumentId,
account_id: AccountId,
)
pub fn record_position_activity( &mut self, instrument_id: InstrumentId, account_id: AccountId, )
Uses monotonic dst::time so the reconciliation grace window is unaffected
by trading-clock acceleration or venue timestamps.
Sourcepub fn position_recon_retry_count(&self, key: &InstrumentAccountKey) -> u32
pub fn position_recon_retry_count(&self, key: &InstrumentAccountKey) -> u32
Returns the current position-reconciliation retry count for the given
(instrument, account) key, or zero if no entry exists.
Sourcepub fn reconcile_execution_mass_status(
&mut self,
mass_status: &ExecutionMassStatus,
exec_engine: &RefCell<ExecutionEngine>,
) -> ReconciliationResult
pub fn reconcile_execution_mass_status( &mut self, mass_status: &ExecutionMassStatus, exec_engine: &RefCell<ExecutionEngine>, ) -> ReconciliationResult
Reconciles a mass snapshot, applying order events before evaluating positions.
Publishes raw reports before cache mutation and verifies each historical fill after dispatch. Returns processed events, external orders for client registration, and diagnostics for in-scope nonzero venue positions that remain inconsistent with the cache.
Sourcepub fn check_inflight_orders(&mut self) -> InflightCheckResult
pub fn check_inflight_orders(&mut self) -> InflightCheckResult
Checks inflight orders and returns terminal events and intermediate venue queries.
For retries below inflight_max_retries, generates QueryOrder commands to poll
the venue for the order’s current status. At max retries, generates terminal events
(rejection or cancellation) based on the order’s status.
Sourcepub async fn check_open_orders(
&mut self,
clients: &[&dyn ExecutionClient],
) -> Vec<OrderEventAny>
pub async fn check_open_orders( &mut self, clients: &[&dyn ExecutionClient], ) -> Vec<OrderEventAny>
Collects open-order reports and targeted follow-ups, returning reconciliation events.
The caller applies the returned events to its execution engine.
Sourcepub fn check_open_order_queries(&mut self) -> Vec<TradingCommand>
pub fn check_open_order_queries(&mut self) -> Vec<TradingCommand>
Builds per-order venue queries for fallback open-order reconciliation.
Sourcepub async fn check_positions_consistency(
&mut self,
clients: &[&dyn ExecutionClient],
) -> Vec<OrderEventAny>
pub async fn check_positions_consistency( &mut self, clients: &[&dyn ExecutionClient], ) -> Vec<OrderEventAny>
Collects position reports and returns synthetic discrepancy events.
Registers each client’s tolerance before evaluating its reports. The caller applies the returned events; the live node separately queries authoritative fills before synthetic fallback.
Sourcepub fn prepare_position_report_check(
&self,
command_id: UUID4,
clients: &[&dyn ExecutionClient],
) -> PositionReportCheck
pub fn prepare_position_report_check( &self, command_id: UUID4, clients: &[&dyn ExecutionClient], ) -> PositionReportCheck
Prepares a bulk position report request and records client coverage.
Snapshots all activity revisions, including keys without open cached positions, so venue-only positions can be checked against activity that predates the request.
Sourcepub fn plan_position_fill_reports(
&mut self,
check: &mut PositionReportCheck,
reports: &[PositionStatusReport],
queried_clients: &IndexSet<ClientId>,
failed_clients: &IndexSet<ClientId>,
clients: &[&dyn ExecutionClient],
) -> PositionFillReportPlan
pub fn plan_position_fill_reports( &mut self, check: &mut PositionReportCheck, reports: &[PositionStatusReport], queried_clients: &IndexSet<ClientId>, failed_clients: &IndexSet<ClientId>, clients: &[&dyn ExecutionClient], ) -> PositionFillReportPlan
Plans fill queries for settled position discrepancies with complete client coverage.
Requires an unfiltered check and report snapshot for pruning. Coverage keys and nonflat venue reports retain retry state.
Sourcepub fn position_report_check_is_current(
&self,
check: &PositionReportCheck,
key: &InstrumentAccountKey,
) -> bool
pub fn position_report_check_is_current( &self, check: &PositionReportCheck, key: &InstrumentAccountKey, ) -> bool
Checks whether position activity is unchanged since the check was prepared.
Sourcepub fn prepare_position_fill_report(
&self,
report: &mut FillReport,
venue_reports: &[PositionStatusReport],
) -> Result<PositionFillReportPreparation>
pub fn prepare_position_fill_report( &self, report: &mut FillReport, venue_reports: &[PositionStatusReport], ) -> Result<PositionFillReportPreparation>
Validates fill attribution and supplies a cached position ID when unambiguous.
§Errors
Returns an error if cached order or position state conflicts with the fill, or inferred-fill history cannot be evaluated.
Sourcepub fn position_contains_fill_report(&self, report: &FillReport) -> bool
pub fn position_contains_fill_report(&self, report: &FillReport) -> bool
Checks whether cached position fills match the report, including quantity and commission.
Sourcepub fn reconcile_position_reports(
&mut self,
check: &PositionReportCheck,
reports: Vec<PositionStatusReport>,
queried_clients: &IndexSet<ClientId>,
failed_clients: &IndexSet<ClientId>,
) -> Vec<OrderEventAny>
pub fn reconcile_position_reports( &mut self, check: &PositionReportCheck, reports: Vec<PositionStatusReport>, queried_clients: &IndexSet<ClientId>, failed_clients: &IndexSet<ClientId>, ) -> Vec<OrderEventAny>
Reconciles cached positions against venue position reports.
Callers may supply a filtered check and reports without pruning retry state for other positions.
Global pruning is handled by Self::plan_position_fill_reports and
Self::check_positions_consistency.
Sourcepub fn get_external_order_claim(
&self,
instrument_id: &InstrumentId,
) -> Option<StrategyId>
pub fn get_external_order_claim( &self, instrument_id: &InstrumentId, ) -> Option<StrategyId>
Returns any external order claim for the given instrument ID.
Sourcepub fn claim_external_orders(
&mut self,
instrument_id: InstrumentId,
strategy_id: StrategyId,
) -> Result<()>
pub fn claim_external_orders( &mut self, instrument_id: InstrumentId, strategy_id: StrategyId, ) -> Result<()>
Claims external orders for a specific strategy and instrument.
§Errors
Returns an error if the instrument already has a registered claim.
Sourcepub fn observe_order_event(&mut self, event: &OrderEventAny)
pub fn observe_order_event(&mut self, event: &OrderEventAny)
Observes a local order event and updates tracking state.
This is the LiveNode dispatch path for order events: acknowledgement
events clear reconciliation tracking, fills record position
activity, and every event stamps local activity. The stamp must come
AFTER any Self::clear_recon_tracking call - that call drops the
local-activity mark, which is the sole grace gate protecting a
just-acknowledged order from missing-order reconciliation while the
venue report lags.
Sourcepub fn observe_execution_report(&mut self, report: &ExecutionReport)
pub fn observe_execution_report(&mut self, report: &ExecutionReport)
Observes an incoming execution report and updates tracking state.
This should be called before the report is dispatched to the execution engine, so that the manager’s state is current when periodic checks run.
Updates performed per report variant:
Order: updates reconciliation tracking based on order statusFill: records order activity and advances the position revision once, without marking the fill as processed; continuous fill recovery checks this increment after dispatchOrderWithFills: updates order tracking and records position activity per fillPosition: records position activityMassStatus: no-op (handled separately via startup reconciliation)
Sourcepub fn purge_closed_orders(&mut self)
pub fn purge_closed_orders(&mut self)
Purges closed orders from the cache that are older than the configured buffer.
Sourcepub fn purge_closed_positions(&mut self)
pub fn purge_closed_positions(&mut self)
Purges closed positions from the cache that are older than the configured buffer.
Sourcepub fn purge_account_events(&mut self)
pub fn purge_account_events(&mut self)
Purges old account events from the cache based on the configured lookback.
Trait Implementations§
Source§impl Clone for ExecutionManager
impl Clone for ExecutionManager
Auto Trait Implementations§
impl !RefUnwindSafe for ExecutionManager
impl !Send for ExecutionManager
impl !Sync for ExecutionManager
impl !UnwindSafe for ExecutionManager
impl Freeze for ExecutionManager
impl Unpin for ExecutionManager
impl UnsafeUnpin for ExecutionManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more