Skip to main content

ExecutionManager

Struct ExecutionManager 

Source
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

Source

pub fn new( clock: Rc<RefCell<dyn Clock>>, cache: Rc<RefCell<Cache>>, config: ExecutionManagerConfig, ) -> ConfigResult<Self>

Creates a new ExecutionManager instance.

§Errors

Returns a ConfigError if config fails validation.

Source

pub fn register_inflight(&mut self, client_order_id: ClientOrderId)

Registers an order as inflight for tracking.

Source

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.

Source

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.

Source

pub fn clear_recon_tracking( &mut self, client_order_id: &ClientOrderId, drop_last_query: bool, )

Clears reconciliation tracking state for an order.

Source

pub fn prune_order_local_activity(&mut self)

Prunes order activity outside the continuous reconciliation settling window.

Source

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).

Source

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.

Source

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.

Source

pub fn prune_recent_fills_cache(&mut self, ttl_secs: f64)

Prunes expired fills from the recent fills cache.

Default TTL is 60 seconds.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn check_open_order_queries(&mut self) -> Vec<TradingCommand>

Builds per-order venue queries for fallback open-order reconciliation.

Source

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.

Source

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.

Source

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.

Source

pub fn position_report_check_is_current( &self, check: &PositionReportCheck, key: &InstrumentAccountKey, ) -> bool

Checks whether position activity is unchanged since the check was prepared.

Source

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.

Source

pub fn position_contains_fill_report(&self, report: &FillReport) -> bool

Checks whether cached position fills match the report, including quantity and commission.

Source

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.

Source

pub fn get_external_order_claim( &self, instrument_id: &InstrumentId, ) -> Option<StrategyId>

Returns any external order claim for the given instrument ID.

Source

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.

Source

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.

Source

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 status
  • Fill: records order activity and advances the position revision once, without marking the fill as processed; continuous fill recovery checks this increment after dispatch
  • OrderWithFills: updates order tracking and records position activity per fill
  • Position: records position activity
  • MassStatus: no-op (handled separately via startup reconciliation)
Source

pub fn purge_closed_orders(&mut self)

Purges closed orders from the cache that are older than the configured buffer.

Source

pub fn purge_closed_positions(&mut self)

Purges closed positions from the cache that are older than the configured buffer.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExecutionManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more