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

This struct is not thread-safe and is designed for single-threaded use within an async runtime. Internal state is managed using IndexMap without synchronization, and the clock and cache use Rc<RefCell<>> which provide runtime borrow checking but no thread-safety guarantees.

If concurrent access is required, this struct must be wrapped in Arc<Mutex<>> or similar synchronization primitives. Alternatively, ensure that all methods are called from the same thread/task in the async runtime.

Warning: Concurrent mutable access to internal IndexMaps or concurrent borrows of RefCell contents will cause runtime panics.

Implementations§

Source§

impl ExecutionManager

Source

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

Creates a new ExecutionManager instance.

Source

pub async fn reconcile_execution_mass_status( &mut self, mass_status: ExecutionMassStatus, exec_engine: Rc<RefCell<ExecutionEngine>>, ) -> ReconciliationResult

Reconciles orders and fills from a mass status report.

Order events are collected, sorted globally by ts_event, then processed through the execution engine to ensure chronological ordering across all orders. Position events are processed after all order events to ensure fills are applied first.

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 fn check_open_order_queries(&mut self) -> Vec<TradingCommand>

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

Source

pub async fn check_open_orders( &mut self, clients: &[&dyn ExecutionClient], ) -> Vec<OrderEventAny>

Checks open orders consistency between cache and venue.

This method validates that open orders in the cache match the venue’s state, comparing order status and filled quantities, and generating reconciliation events for any discrepancies detected.

§Returns

A vector of order events generated to reconcile discrepancies.

Source

pub async fn check_positions_consistency( &mut self, clients: &[&dyn ExecutionClient], ) -> Vec<OrderEventAny>

Checks position consistency between cache and venue.

This method validates that positions in the cache match the venue’s state, detecting position drift and querying for missing fills when discrepancies are found.

§Returns

A vector of fill events generated to reconcile position discrepancies.

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 clear_recon_tracking( &mut self, client_order_id: &ClientOrderId, drop_last_query: bool, )

Clears reconciliation tracking state for an order.

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 record_position_activity( &mut self, instrument_id: InstrumentId, account_id: AccountId, )

Records position activity for reconciliation tracking, scoped per (instrument, account).

The activity is stamped from the monotonic dst::time clock (real elapsed time), not from self.clock and not from the venue event’s ts_event. The position-discrepancy grace is a real-time settling window: give the local pipeline a moment to catch up before flagging a cache-vs-venue gap. That is inherently wall/monotonic time; you want N real seconds of cover regardless of the trading clock’s epoch or speed. self.clock can be driven off wall time (e.g. an accelerated simulated venue), which would shrink the window by the clock’s speed; the venue ts_event lives on yet another axis. Measuring against the same monotonic clock the reconciliation loop already schedules on keeps the grace honest. See check_position_discrepancy.

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 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 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 and position activity without marking the fill as processed
  • 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 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 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 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 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 prune_order_local_activity(&mut self)

Prunes order activity outside the continuous reconciliation settling window.

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

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

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

Source§

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.

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.