Skip to main content

Cache

Struct Cache 

Source
pub struct Cache { /* private fields */ }
Expand description

A common in-memory Cache for market and execution related data.

Implementations§

Source§

impl Cache

Source

pub fn new( config: Option<CacheConfig>, database: Option<Box<dyn CacheDatabaseAdapter>>, ) -> Self

Creates a new Cache instance with optional configuration and database adapter.

§Note

Uses provided CacheConfig or defaults, and optional CacheDatabaseAdapter for persistence.

Source

pub fn memory_address(&self) -> String

Returns the cache instances memory address.

Source

pub fn set_database(&mut self, database: Box<dyn CacheDatabaseAdapter>)

Sets the cache database adapter for persistence.

This allows setting or replacing the database adapter after cache construction.

Source

pub fn cache_general(&mut self) -> Result<()>

Clears and reloads general entries from the database into the cache.

§Errors

Returns an error if loading general cache data fails.

Source

pub async fn cache_all(&mut self) -> Result<()>

Loads all core caches (currencies, instruments, accounts, orders, positions) from the database.

§Errors

Returns an error if loading all cache data fails.

Source

pub async fn cache_currencies(&mut self) -> Result<()>

Clears and reloads the currency cache from the database.

§Errors

Returns an error if loading currencies cache fails.

Source

pub async fn cache_instruments(&mut self) -> Result<()>

Clears and reloads the instrument cache from the database.

§Errors

Returns an error if loading instruments cache fails.

Source

pub async fn cache_synthetics(&mut self) -> Result<()>

Clears and reloads the synthetic instrument cache from the database.

§Errors

Returns an error if loading synthetic instruments cache fails.

Source

pub async fn cache_accounts(&mut self) -> Result<()>

Clears and reloads the account cache from the database.

§Errors

Returns an error if loading accounts cache fails.

Source

pub async fn cache_orders(&mut self) -> Result<()>

Clears and reloads the order cache from the database.

§Errors

Returns an error if loading orders cache fails.

Source

pub async fn cache_positions(&mut self) -> Result<()>

Clears and reloads the position cache from the database.

§Errors

Returns an error if loading positions cache fails.

Source

pub fn build_index(&mut self)

Clears the current cache index and re-build.

Source

pub const fn has_backing(&self) -> bool

Returns whether the cache has a backing database.

Source

pub fn calculate_unrealized_pnl(&self, position: &Position) -> Option<Money>

Source

pub fn check_integrity(&mut self) -> bool

Checks integrity of data within the cache.

All data should be loaded from the database prior to this call. If an error is found then a log error message will also be produced.

§Panics

Panics if failure calling system clock.

Source

pub fn check_residuals(&self) -> bool

Checks for any residual open state and log warnings if any are found.

‘Open state’ is considered to be open orders and open positions.

Source

pub fn purge_closed_orders(&mut self, ts_now: UnixNanos, buffer_secs: u64)

Purges all closed orders from the cache that are older than buffer_secs.

Only orders that have been closed for at least this amount of time will be purged. A value of 0 means purge all closed orders regardless of when they were closed.

Source

pub fn purge_closed_positions(&mut self, ts_now: UnixNanos, buffer_secs: u64)

Purges all closed positions from the cache that are older than buffer_secs.

Source

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

Purges the order with the client_order_id from the cache (if found).

For safety, an order is prevented from being purged if it’s open.

Source

pub fn purge_position(&mut self, position_id: PositionId)

Purges the position with the position_id from the cache (if found).

For safety, a position is prevented from being purged if it’s open.

Source

pub fn purge_instrument(&mut self, instrument_id: InstrumentId)

Purges the instrument with the instrument_id from the cache (if found).

All cache-owned data keyed by the instrument is removed: the instrument record, any synthetic with the same id, order book and own-order-book state, quote/trade histories, mark/index/funding price histories, instrument status, bars for any BarType referencing the instrument, and the instrument_orders / instrument_positions index entries.

For safety, an instrument is prevented from being purged while any associated order is non-terminal (anything not in orders_closed, including initialized, submitted, accepted, emulated, released, or inflight states) or any associated position is non-closed.

Active subscriptions and other live data-engine state are not touched here; those belong to the data and execution engines.

§Warning

Intended for actors and strategies that have their own lifecycle logic for deciding when an instrument is no longer needed. Purging an instrument that any other actor, strategy, or engine still relies on may cause incorrect behavior (missing instrument lookups, lost market-data history). The caller is responsible for ensuring the instrument is no longer in use before purging.

Source

pub fn purge_account_events(&mut self, ts_now: UnixNanos, lookback_secs: u64)

Purges all account state events which are outside the lookback window.

Only events which are outside the lookback window will be purged. A value of 0 means purge all account state events.

Source

pub fn clear_index(&mut self)

Clears the caches index.

Source

pub fn reset(&mut self)

Resets the cache.

All stateful fields are reset to their initial value. Instruments, currencies and synthetics are retained when drop_instruments_on_reset is false so that repeated backtest runs can reuse the same dataset.

Source

pub fn dispose(&mut self)

Dispose of the cache which will close any underlying database adapter.

If closing the database connection fails, an error is logged.

Source

pub fn flush_db(&mut self)

Flushes the caches database which permanently removes all persisted data.

If flushing the database connection fails, an error is logged.

Source

pub fn add(&mut self, key: &str, value: Bytes) -> Result<()>

Adds a raw bytes value to the cache under the key.

The cache stores only raw bytes; interpretation is the caller’s responsibility.

§Errors

Returns an error if persisting the entry to the backing database fails.

Source

pub fn add_order_book(&mut self, book: OrderBook) -> Result<()>

Adds an OrderBook to the cache.

§Errors

Returns an error if persisting the order book to the backing database fails.

Source

pub fn add_own_order_book(&mut self, own_book: OwnOrderBook) -> Result<()>

Adds an OwnOrderBook to the cache.

§Errors

Returns an error if persisting the own order book fails.

Source

pub fn add_mark_price(&mut self, mark_price: MarkPriceUpdate) -> Result<()>

Adds the mark_price update to the cache.

§Errors

Returns an error if persisting the mark price to the backing database fails.

Source

pub fn add_index_price(&mut self, index_price: IndexPriceUpdate) -> Result<()>

Adds the index_price update to the cache.

§Errors

Returns an error if persisting the index price to the backing database fails.

Source

pub fn add_funding_rate( &mut self, funding_rate: FundingRateUpdate, ) -> Result<()>

Adds the funding_rate update to the cache.

§Errors

Returns an error if persisting the funding rate update to the backing database fails.

Source

pub fn add_funding_rates( &mut self, funding_rates: &[FundingRateUpdate], ) -> Result<()>

Adds the given funding rates to the cache.

§Errors

Returns an error if persisting the trade ticks to the backing database fails.

Source

pub fn add_instrument_status(&mut self, status: InstrumentStatus) -> Result<()>

Adds the instrument_status update to the cache.

§Errors

Returns an error if persisting the instrument status to the backing database fails.

Source

pub fn add_quote(&mut self, quote: QuoteTick) -> Result<()>

Adds the quote tick to the cache.

§Errors

Returns an error if persisting the quote tick to the backing database fails.

Source

pub fn add_quotes(&mut self, quotes: &[QuoteTick]) -> Result<()>

Adds the quotes to the cache.

§Errors

Returns an error if persisting the quote ticks to the backing database fails.

Source

pub fn add_trade(&mut self, trade: TradeTick) -> Result<()>

Adds the trade tick to the cache.

§Errors

Returns an error if persisting the trade tick to the backing database fails.

Source

pub fn add_trades(&mut self, trades: &[TradeTick]) -> Result<()>

Adds the give trades to the cache.

§Errors

Returns an error if persisting the trade ticks to the backing database fails.

Source

pub fn add_bar(&mut self, bar: Bar) -> Result<()>

Adds the bar to the cache.

§Errors

Returns an error if persisting the bar to the backing database fails.

Source

pub fn add_bars(&mut self, bars: &[Bar]) -> Result<()>

Adds the bars to the cache.

§Errors

Returns an error if persisting the bars to the backing database fails.

Source

pub fn add_greeks(&mut self, greeks: GreeksData) -> Result<()>

Adds the greeks data to the cache.

§Errors

Returns an error if persisting the greeks data to the backing database fails.

Source

pub fn greeks(&self, instrument_id: &InstrumentId) -> Option<GreeksData>

Gets the greeks data for the instrument_id.

Source

pub fn add_option_greeks(&mut self, greeks: OptionGreeks)

Adds exchange-provided option greeks to the cache.

Source

pub fn option_greeks( &self, instrument_id: &InstrumentId, ) -> Option<&OptionGreeks>

Gets a reference to the exchange-provided option greeks for the instrument_id.

Source

pub fn add_yield_curve(&mut self, yield_curve: YieldCurveData) -> Result<()>

Adds the yield_curve data to the cache.

§Errors

Returns an error if persisting the yield curve data to the backing database fails.

Source

pub fn yield_curve(&self, key: &str) -> Option<Box<dyn Fn(f64) -> f64>>

Gets the yield curve for the key.

Source

pub fn add_currency(&mut self, currency: Currency) -> Result<()>

Adds the currency to the cache.

§Errors

Returns an error if persisting the currency to the backing database fails.

Source

pub fn add_instrument(&mut self, instrument: InstrumentAny) -> Result<()>

Adds the instrument to the cache.

§Errors

Returns an error if persisting the instrument to the backing database fails.

Source

pub fn add_synthetic(&mut self, synthetic: SyntheticInstrument) -> Result<()>

Adds the synthetic instrument to the cache.

§Errors

Returns an error if persisting the synthetic instrument to the backing database fails.

Source

pub fn add_account(&mut self, account: AccountAny) -> Result<()>

Adds the account to the cache.

§Errors

Returns an error if persisting the account to the backing database fails.

Source

pub fn add_venue_order_id( &mut self, client_order_id: &ClientOrderId, venue_order_id: &VenueOrderId, overwrite: bool, ) -> Result<()>

Indexes the client_order_id with the venue_order_id.

The overwrite parameter determines whether to overwrite any existing cached identifier.

§Errors

Returns an error if the existing venue order ID conflicts and overwrite is false.

Source

pub fn add_order( &mut self, order: OrderAny, position_id: Option<PositionId>, client_id: Option<ClientId>, replace_existing: bool, ) -> Result<()>

Adds the order to the cache indexed with any given identifiers.

§Parameters

override_existing: If the added order should ‘override’ any existing order and replace it in the cache. This is currently used for emulated orders which are being released and transformed into another type.

§Errors

Returns an error if not replace_existing and the order.client_order_id is already contained in the cache.

Source

pub fn add_order_list(&mut self, order_list: OrderList) -> Result<()>

Adds the order_list to the cache.

§Errors

Returns an error if the order list ID is already contained in the cache.

Source

pub fn add_position_id( &mut self, position_id: &PositionId, venue: &Venue, client_order_id: &ClientOrderId, strategy_id: &StrategyId, ) -> Result<()>

Indexes the position_id with the other given IDs.

§Errors

Returns an error if indexing position ID in the backing database fails.

Source

pub fn add_position( &mut self, position: &Position, _oms_type: OmsType, ) -> Result<()>

Adds the position to the cache.

§Errors

Returns an error if persisting the position to the backing database fails.

Source

pub fn update_account(&mut self, account: &AccountAny) -> Result<()>

Updates the account in the cache.

Reuses the existing cell when present so any held AccountRef handles continue to point at the canonical entry; only inserts a new cell when the account is unknown.

§Errors

Returns an error if updating the account in the database fails.

Source

pub fn take_account(&mut self, account_id: &AccountId) -> Option<AccountAny>

Removes the account from the cache and returns it.

This supports hot paths which need owned account mutation without cloning the account event history. The cache is the sole owner of the account cell (the field is private and accessors only hand out lifetime-scoped AccountRef borrows), so the value is moved out of its cell rather than cloned.

§Panics

Panics if the cache no longer holds the only strong handle to the account cell. This indicates an internal invariant violation: some component cloned the underlying SharedCell and held it past the scope of a single cache method.

Source

pub fn cache_account_owned(&mut self, account: AccountAny)

Caches the account in memory without updating the database.

Source

pub fn update_account_owned(&mut self, account: AccountAny) -> Result<()>

Updates the account in the cache, taking ownership of the updated account.

§Errors

Returns an error if updating the account in the database fails.

Source

pub fn update_account_state(&mut self, event: &AccountState) -> Result<()>

Applies an account state event to the cached account.

Mutates the cached account in place to avoid cloning the account event history on the hot path; long-running sessions accumulate many events per account, so a snapshot-clone here would be O(history) per update.

§Errors

Returns an error if applying or persisting the account state fails.

Source

pub fn replace_order(&mut self, order: &OrderAny) -> Result<()>

Replaces the cached order from a non-event snapshot.

Prefer Self::update_order for lifecycle state changes. Use this only for order state that is not represented by OrderEventAny.

§Errors

Returns an error if updating the order indexes or database fails.

Source

pub fn update_order(&mut self, event: &OrderEventAny) -> Result<OrderAny>

Updates the cached order by applying an event and refreshing derived cache state.

§Errors

Returns an error if the order is not found or rejects the event.

Source

pub fn update_order_pending_cancel_local(&mut self, order: &OrderAny)

Updates the order as pending cancel locally.

Source

pub fn update_position(&mut self, position: &Position) -> Result<()>

Updates the position in the cache.

Reuses the existing cell when present so any held PositionRef handles continue to point at the canonical entry; only inserts a new cell when the position is unknown.

§Errors

Returns an error if updating the position in the database fails.

Source

pub fn snapshot_position( &mut self, position: &Position, ) -> Result<CacheSnapshotRef>

Creates a snapshot of the position by cloning it, assigning a new ID, serializing it, and storing it in the position snapshots.

§Errors

Returns an error if serializing or storing the position snapshot fails.

Source

pub fn load_snapshot_blob(&mut self, blob_ref: &str) -> Result<Option<Bytes>>

Loads the cache-owned snapshot blob stored under blob_ref.

The cache first checks in-memory snapshot state. When the blob is not present and a database adapter exists, the generic cache entries are loaded and checked for the same opaque reference.

§Errors

Returns an error if loading generic cache entries from the backing database fails.

Source

pub fn restore_snapshot_blob( &mut self, blob_ref: &str, blob: Bytes, ) -> Result<()>

Restores the cache-owned snapshot blob stored under blob_ref.

Only cache-owned cache://position-snapshots/... blobs are currently supported.

§Errors

Returns an error if the blob reference is unsupported, malformed, skips earlier snapshot frames, conflicts with an existing frame, or does not decode to the expected position snapshot.

Source

pub fn snapshot_position_state( &mut self, position: &Position, open_only: Option<bool>, ) -> Result<()>

Creates a snapshot of the position state in the database.

§Errors

Returns an error if snapshotting the position state fails.

Source

pub fn oms_type(&self, position_id: &PositionId) -> Option<OmsType>

Gets the OMS type for the position_id.

Source

pub fn position_snapshot_bytes( &self, position_id: &PositionId, ) -> Option<Vec<Vec<u8>>>

Gets the serialized position snapshot frames for the position_id.

Each element in the returned vector is one JSON-encoded Position snapshot, in the order they were taken.

Source

pub fn position_snapshot_count(&self, position_id: &PositionId) -> usize

Returns the number of stored snapshot frames for the position_id.

Returns 0 when no frames are stored. Does not allocate or copy frame bytes.

Source

pub fn position_snapshots( &self, position_id: Option<&PositionId>, account_id: Option<&AccountId>, ) -> Vec<Position>

Returns all position snapshots with the given optional filters.

When position_id is Some, only snapshots for that position are returned. When account_id is Some, snapshots are filtered to that account. Frames that fail to deserialize are skipped with a warning.

Source

pub fn position_snapshots_from( &self, position_id: &PositionId, skip: usize, ) -> Vec<Position>

Returns position snapshots for position_id starting from the skipth frame.

Use this to deserialize only newly appended snapshots when the caller already processed earlier frames. Returns an empty vector when no frames or fewer than skip frames are stored. Frames that fail to deserialize are skipped with a warning.

Source

pub fn position_snapshot_ids( &self, instrument_id: &InstrumentId, ) -> AHashSet<PositionId>

Gets position snapshot IDs for the instrument_id.

Source

pub fn snapshot_order_state(&self, order: &OrderAny) -> Result<()>

Snapshots the order state in the database.

§Errors

Returns an error if snapshotting the order state fails.

Source

pub fn client_order_ids( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> AHashSet<ClientOrderId>

Returns the ClientOrderIds of all orders.

Source

pub fn client_order_ids_open( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> AHashSet<ClientOrderId>

Returns the ClientOrderIds of all open orders.

Source

pub fn client_order_ids_closed( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> AHashSet<ClientOrderId>

Returns the ClientOrderIds of all closed orders.

Source

pub fn client_order_ids_active_local( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> AHashSet<ClientOrderId>

Returns the ClientOrderIds of all locally active orders.

Locally active orders are in the INITIALIZED, EMULATED, or RELEASED state (a superset of emulated orders).

Source

pub fn client_order_ids_emulated( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> AHashSet<ClientOrderId>

Returns the ClientOrderIds of all emulated orders.

Source

pub fn client_order_ids_inflight( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> AHashSet<ClientOrderId>

Returns the ClientOrderIds of all in-flight orders.

Source

pub fn position_ids( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> AHashSet<PositionId>

Returns PositionIds of all positions.

Source

pub fn position_open_ids( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> AHashSet<PositionId>

Returns the PositionIds of all open positions.

Source

pub fn position_closed_ids( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> AHashSet<PositionId>

Returns the PositionIds of all closed positions.

Source

pub fn client_order_ids_view( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Cow<'_, AHashSet<ClientOrderId>>

Returns a borrowed view over the ClientOrderIds of all orders matching the optional filter parameters.

The returned Cow borrows the underlying index when no filter is provided and only allocates an owned AHashSet when an intersection is required. Prefer this over Self::client_order_ids when the caller only needs to iterate or read membership.

Source

pub fn client_order_ids_open_view( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Cow<'_, AHashSet<ClientOrderId>>

Returns a borrowed view over the ClientOrderIds of all open orders.

Source

pub fn client_order_ids_closed_view( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Cow<'_, AHashSet<ClientOrderId>>

Returns a borrowed view over the ClientOrderIds of all closed orders.

Source

pub fn client_order_ids_active_local_view( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Cow<'_, AHashSet<ClientOrderId>>

Returns a borrowed view over the ClientOrderIds of all locally active orders.

Source

pub fn client_order_ids_emulated_view( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Cow<'_, AHashSet<ClientOrderId>>

Returns a borrowed view over the ClientOrderIds of all emulated orders.

Source

pub fn client_order_ids_inflight_view( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Cow<'_, AHashSet<ClientOrderId>>

Returns a borrowed view over the ClientOrderIds of all in-flight orders.

Source

pub fn position_ids_view( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Cow<'_, AHashSet<PositionId>>

Returns a borrowed view over the PositionIds of all positions.

Source

pub fn position_open_ids_view( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Cow<'_, AHashSet<PositionId>>

Returns a borrowed view over the PositionIds of all open positions.

Source

pub fn position_closed_ids_view( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Cow<'_, AHashSet<PositionId>>

Returns a borrowed view over the PositionIds of all closed positions.

Source

pub fn iter_client_order_ids( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Box<dyn Iterator<Item = ClientOrderId> + '_>

Returns a lazy iterator yielding ClientOrderIds of all orders matching the optional filter parameters.

Avoids the AHashSet allocation performed by Self::client_order_ids. Useful when the caller iterates the result once and discards it.

Source

pub fn iter_client_order_ids_open( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Box<dyn Iterator<Item = ClientOrderId> + '_>

Returns a lazy iterator yielding ClientOrderIds of all open orders.

Source

pub fn iter_client_order_ids_closed( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Box<dyn Iterator<Item = ClientOrderId> + '_>

Returns a lazy iterator yielding ClientOrderIds of all closed orders.

Source

pub fn iter_client_order_ids_active_local( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Box<dyn Iterator<Item = ClientOrderId> + '_>

Returns a lazy iterator yielding ClientOrderIds of all locally active orders.

Source

pub fn iter_client_order_ids_emulated( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Box<dyn Iterator<Item = ClientOrderId> + '_>

Returns a lazy iterator yielding ClientOrderIds of all emulated orders.

Source

pub fn iter_client_order_ids_inflight( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Box<dyn Iterator<Item = ClientOrderId> + '_>

Returns a lazy iterator yielding ClientOrderIds of all in-flight orders.

Source

pub fn iter_position_ids( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Box<dyn Iterator<Item = PositionId> + '_>

Returns a lazy iterator yielding PositionIds of all positions matching the filters.

Source

pub fn iter_position_open_ids( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Box<dyn Iterator<Item = PositionId> + '_>

Returns a lazy iterator yielding PositionIds of all open positions.

Source

pub fn iter_position_closed_ids( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Box<dyn Iterator<Item = PositionId> + '_>

Returns a lazy iterator yielding PositionIds of all closed positions.

Source

pub fn actor_ids(&self) -> AHashSet<ComponentId>

Returns the ComponentIds of all actors.

Source

pub fn strategy_ids(&self) -> AHashSet<StrategyId>

Returns the StrategyIds of all strategies.

Source

pub fn exec_algorithm_ids(&self) -> AHashSet<ExecAlgorithmId>

Returns the ExecAlgorithmIds of all execution algorithms.

Source

pub fn order(&self, client_order_id: &ClientOrderId) -> Option<OrderRef<'_>>

Gets a borrow of the order with the client_order_id (if found).

The returned OrderRef is tied to the cache borrow’s scope and panics at runtime if held across a mutation of the same order. Drop the borrow before dispatching events; if post-event state is required, perform a fresh lookup. Use Self::order_owned when an owned snapshot is needed for a boundary handover.

Source

pub fn order_mut( &mut self, client_order_id: &ClientOrderId, ) -> Option<OrderRefMut<'_>>

Gets an exclusive write borrow of the order with the client_order_id (if found).

Requires &mut Cache so cache writes are reachable only by privileged crates that hold Rc<RefCell<Cache>> directly. Adapter-facing code receives CacheView, which only exposes immutable cache borrows and therefore cannot reach this method.

While the returned OrderRefMut is alive, no other read or write of the same order is permitted. Drop the borrow before dispatching events or taking any other cache borrow that may re-enter the same order.

Source

pub fn order_owned(&self, client_order_id: &ClientOrderId) -> Option<OrderAny>

Gets an owned snapshot of the order with the client_order_id (if found).

Use when downstream needs an owned OrderAny that crosses a boundary (for example, an adapter get_order API). The snapshot will not reflect later cache mutations.

Source

pub fn orders_for_ids( &self, client_order_ids: &[ClientOrderId], context: &dyn Display, ) -> Vec<OrderAny>

Gets cloned orders for the given client_order_ids, logging an error for any missing.

Source

pub fn client_order_id( &self, venue_order_id: &VenueOrderId, ) -> Option<&ClientOrderId>

Gets a reference to the client order ID for the venue_order_id (if found).

Source

pub fn venue_order_id( &self, client_order_id: &ClientOrderId, ) -> Option<&VenueOrderId>

Gets a reference to the venue order ID for the client_order_id (if found).

Source

pub fn client_id(&self, client_order_id: &ClientOrderId) -> Option<&ClientId>

Gets a reference to the client ID indexed for then client_order_id (if found).

Source

pub fn orders( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> Vec<OrderRef<'_>>

Returns borrows of all orders matching the optional filter parameters.

Each Ref in the returned vector borrows its underlying cell; mutating any of those orders while the vector is alive will panic at runtime. Drop the vector before issuing writes.

Source

pub fn orders_open( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> Vec<OrderRef<'_>>

Returns borrows of all open orders matching the optional filter parameters.

Source

pub fn orders_closed( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> Vec<OrderRef<'_>>

Returns borrows of all closed orders matching the optional filter parameters.

Source

pub fn orders_active_local( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> Vec<OrderRef<'_>>

Returns borrows of all locally active orders matching the optional filter parameters.

Locally active orders are in the INITIALIZED, EMULATED, or RELEASED state (a superset of emulated orders).

Source

pub fn orders_emulated( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> Vec<OrderRef<'_>>

Returns borrows of all emulated orders matching the optional filter parameters.

Source

pub fn orders_inflight( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> Vec<OrderRef<'_>>

Returns borrows of all in-flight orders matching the optional filter parameters.

Source

pub fn orders_for_position(&self, position_id: &PositionId) -> Vec<OrderRef<'_>>

Returns borrows of all orders for the position_id.

Source

pub fn order_exists(&self, client_order_id: &ClientOrderId) -> bool

Returns whether an order with the client_order_id exists.

Source

pub fn is_order_open(&self, client_order_id: &ClientOrderId) -> bool

Returns whether an order with the client_order_id is open.

Source

pub fn is_order_closed(&self, client_order_id: &ClientOrderId) -> bool

Returns whether an order with the client_order_id is closed.

Source

pub fn is_order_active_local(&self, client_order_id: &ClientOrderId) -> bool

Returns whether an order with the client_order_id is locally active.

Locally active orders are in the INITIALIZED, EMULATED, or RELEASED state (a superset of emulated orders).

Source

pub fn is_order_emulated(&self, client_order_id: &ClientOrderId) -> bool

Returns whether an order with the client_order_id is emulated.

Source

pub fn is_order_inflight(&self, client_order_id: &ClientOrderId) -> bool

Returns whether an order with the client_order_id is in-flight.

Source

pub fn is_order_pending_cancel_local( &self, client_order_id: &ClientOrderId, ) -> bool

Returns whether an order with the client_order_id is PENDING_CANCEL locally.

Source

pub fn orders_open_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> usize

Returns the count of all open orders.

Source

pub fn orders_closed_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> usize

Returns the count of all closed orders.

Source

pub fn orders_active_local_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> usize

Returns the count of all locally active orders.

Locally active orders are in the INITIALIZED, EMULATED, or RELEASED state (a superset of emulated orders).

Source

pub fn orders_emulated_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> usize

Returns the count of all emulated orders.

Source

pub fn orders_inflight_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> usize

Returns the count of all in-flight orders.

Source

pub fn orders_total_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> usize

Returns the count of all orders.

Source

pub fn has_orders_open( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> bool

Returns whether any open order matches the optional filter parameters.

Short-circuits on the first match, avoiding the full intersection walk performed by Self::orders_open_count. Prefer this over orders_open_count(...) > 0 when only existence matters.

Source

pub fn has_orders_closed( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> bool

Returns whether any closed order matches the optional filter parameters.

Source

pub fn has_orders_active_local( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> bool

Returns whether any locally active order matches the optional filter parameters.

Locally active orders are in the INITIALIZED, EMULATED, or RELEASED state.

Source

pub fn has_orders_emulated( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> bool

Returns whether any emulated order matches the optional filter parameters.

Source

pub fn has_orders_inflight( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> bool

Returns whether any in-flight order matches the optional filter parameters.

Source

pub fn has_orders( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> bool

Returns whether any order (in any state) matches the optional filter parameters.

Source

pub fn order_list(&self, order_list_id: &OrderListId) -> Option<&OrderList>

Returns the order list for the order_list_id.

Source

pub fn order_lists( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, ) -> Vec<&OrderList>

Returns all order lists matching the optional filter parameters.

Source

pub fn order_list_exists(&self, order_list_id: &OrderListId) -> bool

Returns whether an order list with the order_list_id exists.

Source

pub fn orders_for_exec_algorithm( &self, exec_algorithm_id: &ExecAlgorithmId, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<OrderSide>, ) -> Vec<OrderRef<'_>>

Returns references to all orders associated with the exec_algorithm_id matching the optional filter parameters.

Source

pub fn orders_for_exec_spawn( &self, exec_spawn_id: &ClientOrderId, ) -> Vec<OrderRef<'_>>

Returns references to all orders with the exec_spawn_id.

Source

pub fn exec_spawn_total_quantity( &self, exec_spawn_id: &ClientOrderId, active_only: bool, ) -> Option<Quantity>

Returns the total order quantity for the exec_spawn_id.

Source

pub fn exec_spawn_total_filled_qty( &self, exec_spawn_id: &ClientOrderId, active_only: bool, ) -> Option<Quantity>

Returns the total filled quantity for all orders with the exec_spawn_id.

Source

pub fn exec_spawn_total_leaves_qty( &self, exec_spawn_id: &ClientOrderId, active_only: bool, ) -> Option<Quantity>

Returns the total leaves quantity for all orders with the exec_spawn_id.

Source

pub fn position(&self, position_id: &PositionId) -> Option<PositionRef<'_>>

Returns a borrow of the position with the position_id (if found).

Source

pub fn position_mut( &mut self, position_id: &PositionId, ) -> Option<PositionRefMut<'_>>

Gets an exclusive write borrow of the position with the position_id (if found).

Requires &mut Cache so cache writes are reachable only by privileged crates that hold Rc<RefCell<Cache>> directly. Adapter-facing code receives CacheView, which only exposes immutable cache borrows and therefore cannot reach this method.

While the returned PositionRefMut is alive, no other read or write of the same position is permitted. Drop the borrow before dispatching events or taking any other cache borrow that may re-enter the same position.

Source

pub fn position_owned(&self, position_id: &PositionId) -> Option<Position>

Gets an owned snapshot of the position with the position_id (if found).

Use when downstream needs an owned Position that crosses a boundary. The snapshot will not reflect later cache mutations.

Source

pub fn position_for_order( &self, client_order_id: &ClientOrderId, ) -> Option<PositionRef<'_>>

Returns a borrow of the position for the client_order_id (if found).

Source

pub fn position_id( &self, client_order_id: &ClientOrderId, ) -> Option<&PositionId>

Returns a reference to the position ID for the client_order_id (if found).

Source

pub fn positions( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<PositionSide>, ) -> Vec<PositionRef<'_>>

Returns borrows of all positions matching the optional filter parameters.

Each PositionRef in the returned vector borrows its underlying cell; mutating any of those positions while the vector is alive will panic at runtime. Drop the vector before issuing writes.

Source

pub fn positions_open( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<PositionSide>, ) -> Vec<PositionRef<'_>>

Returns borrows of all open positions matching the optional filter parameters.

Source

pub fn positions_closed( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<PositionSide>, ) -> Vec<PositionRef<'_>>

Returns borrows of all closed positions matching the optional filter parameters.

Source

pub fn position_exists(&self, position_id: &PositionId) -> bool

Returns whether a position with the position_id exists.

Source

pub fn is_position_open(&self, position_id: &PositionId) -> bool

Returns whether a position with the position_id is open.

Source

pub fn is_position_closed(&self, position_id: &PositionId) -> bool

Returns whether a position with the position_id is closed.

Source

pub fn positions_open_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<PositionSide>, ) -> usize

Returns the count of all open positions.

Source

pub fn positions_closed_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<PositionSide>, ) -> usize

Returns the count of all closed positions.

Source

pub fn positions_total_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<PositionSide>, ) -> usize

Returns the count of all positions.

Source

pub fn has_positions_open( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<PositionSide>, ) -> bool

Returns whether any open position matches the optional filter parameters.

Short-circuits on the first match, avoiding the full intersection walk performed by Self::positions_open_count. Prefer this over positions_open_count(...) > 0 when only existence matters.

Source

pub fn has_positions_closed( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<PositionSide>, ) -> bool

Returns whether any closed position matches the optional filter parameters.

Source

pub fn has_positions( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, account_id: Option<&AccountId>, side: Option<PositionSide>, ) -> bool

Returns whether any position (open or closed) matches the optional filter parameters.

Source

pub fn strategy_id_for_order( &self, client_order_id: &ClientOrderId, ) -> Option<&StrategyId>

Gets a reference to the strategy ID for the client_order_id (if found).

Source

pub fn strategy_id_for_position( &self, position_id: &PositionId, ) -> Option<&StrategyId>

Gets a reference to the strategy ID for the position_id (if found).

Source

pub fn get(&self, key: &str) -> Result<Option<&Bytes>>

Gets a reference to the general value for the key (if found).

§Errors

Returns an error if the key is invalid.

Source

pub fn price( &self, instrument_id: &InstrumentId, price_type: PriceType, ) -> Option<Price>

Returns the price for the instrument_id and price_type (if found).

Source

pub fn quotes(&self, instrument_id: &InstrumentId) -> Option<Vec<QuoteTick>>

Gets all quotes for the instrument_id.

Source

pub fn trades(&self, instrument_id: &InstrumentId) -> Option<Vec<TradeTick>>

Gets all trades for the instrument_id.

Source

pub fn mark_prices( &self, instrument_id: &InstrumentId, ) -> Option<Vec<MarkPriceUpdate>>

Gets all mark price updates for the instrument_id.

Source

pub fn index_prices( &self, instrument_id: &InstrumentId, ) -> Option<Vec<IndexPriceUpdate>>

Gets all index price updates for the instrument_id.

Source

pub fn funding_rates( &self, instrument_id: &InstrumentId, ) -> Option<Vec<FundingRateUpdate>>

Gets all funding rate updates for the instrument_id.

Source

pub fn instrument_statuses( &self, instrument_id: &InstrumentId, ) -> Option<Vec<InstrumentStatus>>

Gets all instrument status updates for the instrument_id.

Source

pub fn bars(&self, bar_type: &BarType) -> Option<Vec<Bar>>

Gets all bars for the bar_type.

Source

pub fn order_book(&self, instrument_id: &InstrumentId) -> Option<&OrderBook>

Gets a reference to the order book for the instrument_id.

Source

pub fn order_book_mut( &mut self, instrument_id: &InstrumentId, ) -> Option<&mut OrderBook>

Gets a reference to the order book for the instrument_id.

Source

pub fn own_order_book( &self, instrument_id: &InstrumentId, ) -> Option<&OwnOrderBook>

Gets a reference to the own order book for the instrument_id.

Source

pub fn own_order_book_mut( &mut self, instrument_id: &InstrumentId, ) -> Option<&mut OwnOrderBook>

Gets a reference to the own order book for the instrument_id.

Source

pub fn quote(&self, instrument_id: &InstrumentId) -> Option<&QuoteTick>

Gets a reference to the latest quote for the instrument_id.

Source

pub fn quote_at_index( &self, instrument_id: &InstrumentId, index: usize, ) -> Option<&QuoteTick>

Gets a reference to the quote at index for the instrument_id.

Index 0 is the most recent.

Source

pub fn trade(&self, instrument_id: &InstrumentId) -> Option<&TradeTick>

Gets a reference to the latest trade for the instrument_id.

Source

pub fn trade_at_index( &self, instrument_id: &InstrumentId, index: usize, ) -> Option<&TradeTick>

Gets a reference to the trade at index for the instrument_id.

Index 0 is the most recent.

Source

pub fn mark_price( &self, instrument_id: &InstrumentId, ) -> Option<&MarkPriceUpdate>

Gets a reference to the latest mark price update for the instrument_id.

Source

pub fn index_price( &self, instrument_id: &InstrumentId, ) -> Option<&IndexPriceUpdate>

Gets a reference to the latest index price update for the instrument_id.

Source

pub fn funding_rate( &self, instrument_id: &InstrumentId, ) -> Option<&FundingRateUpdate>

Gets a reference to the latest funding rate update for the instrument_id.

Source

pub fn instrument_status( &self, instrument_id: &InstrumentId, ) -> Option<&InstrumentStatus>

Gets a reference to the latest instrument status update for the instrument_id.

Source

pub fn bar(&self, bar_type: &BarType) -> Option<&Bar>

Gets a reference to the latest bar for the bar_type.

Source

pub fn bar_at_index(&self, bar_type: &BarType, index: usize) -> Option<&Bar>

Gets a reference to the bar at index for the bar_type.

Index 0 is the most recent.

Source

pub fn book_update_count(&self, instrument_id: &InstrumentId) -> usize

Gets the order book update count for the instrument_id.

Source

pub fn quote_count(&self, instrument_id: &InstrumentId) -> usize

Gets the quote tick count for the instrument_id.

Source

pub fn trade_count(&self, instrument_id: &InstrumentId) -> usize

Gets the trade tick count for the instrument_id.

Source

pub fn bar_count(&self, bar_type: &BarType) -> usize

Gets the bar count for the instrument_id.

Source

pub fn has_order_book(&self, instrument_id: &InstrumentId) -> bool

Returns whether the cache contains an order book for the instrument_id.

Source

pub fn has_quote_ticks(&self, instrument_id: &InstrumentId) -> bool

Returns whether the cache contains quotes for the instrument_id.

Source

pub fn has_trade_ticks(&self, instrument_id: &InstrumentId) -> bool

Returns whether the cache contains trades for the instrument_id.

Source

pub fn has_bars(&self, bar_type: &BarType) -> bool

Returns whether the cache contains bars for the bar_type.

Source

pub fn get_xrate( &self, venue: Venue, from_currency: Currency, to_currency: Currency, price_type: PriceType, ) -> Option<f64>

Source

pub fn get_mark_xrate( &self, from_currency: Currency, to_currency: Currency, ) -> Option<f64>

Returns the mark exchange rate for the given currency pair, or None if not set.

Source

pub fn set_mark_xrate( &mut self, from_currency: Currency, to_currency: Currency, xrate: f64, )

Sets the mark exchange rate for the given currency pair and automatically sets the inverse rate.

§Panics

Panics if xrate is not positive.

Source

pub fn clear_mark_xrate( &mut self, from_currency: Currency, to_currency: Currency, )

Clears the mark exchange rate for the given currency pair.

Source

pub fn clear_mark_xrates(&mut self)

Clears all mark exchange rates.

Source

pub fn instrument(&self, instrument_id: &InstrumentId) -> Option<&InstrumentAny>

Returns a reference to the instrument for the instrument_id (if found).

Source

pub fn instrument_ids(&self, venue: Option<&Venue>) -> Vec<&InstrumentId>

Returns references to all instrument IDs for the venue.

Source

pub fn instruments( &self, venue: &Venue, underlying: Option<&Ustr>, ) -> Vec<&InstrumentAny>

Returns references to all instruments for the venue.

Source

pub fn instruments_by_parent( &self, venue: &Venue, root: &Ustr, class: InstrumentClass, ) -> Vec<&InstrumentAny>

Returns references to all instruments for the venue whose underlying equals root and whose InstrumentClass equals class.

Use when expanding a parent-symbol subscription: filtering by class as well as root prevents leaves of a different class (e.g. options when the user asked for futures, or vice versa) from being pulled in.

Source

pub fn bar_types( &self, instrument_id: Option<&InstrumentId>, price_type: Option<&PriceType>, aggregation_source: AggregationSource, ) -> Vec<&BarType>

Returns references to all bar types contained in the cache.

Source

pub fn synthetic( &self, instrument_id: &InstrumentId, ) -> Option<&SyntheticInstrument>

Returns a reference to the synthetic instrument for the instrument_id (if found).

Source

pub fn synthetic_ids(&self) -> Vec<&InstrumentId>

Returns references to instrument IDs for all synthetic instruments contained in the cache.

Source

pub fn synthetics(&self) -> Vec<&SyntheticInstrument>

Returns references to all synthetic instruments contained in the cache.

Source

pub fn account(&self, account_id: &AccountId) -> Option<AccountRef<'_>>

Returns a borrow of the account for the account_id (if found).

Source

pub fn account_mut( &mut self, account_id: &AccountId, ) -> Option<AccountRefMut<'_>>

Gets an exclusive write borrow of the account with the account_id (if found).

Requires &mut Cache so cache writes are reachable only by privileged crates that hold Rc<RefCell<Cache>> directly. Adapter-facing code receives CacheView, which only exposes immutable cache borrows and therefore cannot reach this method.

While the returned AccountRefMut is alive, no other read or write of the same account is permitted. Drop the borrow before dispatching events or taking any other cache borrow that may re-enter the same account.

Source

pub fn account_owned(&self, account_id: &AccountId) -> Option<AccountAny>

Gets an owned snapshot of the account with the account_id (if found).

Use when downstream needs an owned AccountAny that crosses a boundary. The snapshot will not reflect later cache mutations.

Source

pub fn account_for_venue(&self, venue: &Venue) -> Option<AccountRef<'_>>

Returns a borrow of the account for the venue (if found).

Source

pub fn account_for_venue_owned(&self, venue: &Venue) -> Option<AccountAny>

Returns an owned snapshot of the account for the venue (if found).

Use when downstream needs an owned AccountAny that crosses a boundary. The snapshot will not reflect later cache mutations.

Source

pub fn account_id(&self, venue: &Venue) -> Option<&AccountId>

Returns a reference to the account ID for the venue (if found).

Source

pub fn accounts(&self, account_id: &AccountId) -> Vec<AccountRef<'_>>

Returns borrows of all accounts for the account_id.

Each AccountRef in the returned vector borrows its underlying cell; mutating any of those accounts while the vector is alive will panic at runtime. Drop the vector before issuing writes.

Source

pub fn update_own_order_book(&mut self, order: &OrderAny)

Updates the own order book with an order.

This method adds, updates, or removes an order from the own order book based on the order’s current state.

Orders without prices (MARKET, etc.) are skipped as they cannot be represented in own books.

Source

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

Force removal of an order from own order books and clean up all indexes.

This method is used when order event application fails and we need to ensure terminal orders are properly cleaned up from own books and all relevant indexes. Replicates the index cleanup that update_order performs for closed orders.

Source

pub fn audit_own_order_books(&mut self)

Audit all own order books against open and inflight order indexes.

Ensures closed orders are removed from own order books. This includes both orders tracked in orders_open (ACCEPTED, TRIGGERED, PENDING_*, PARTIALLY_FILLED) and orders_inflight (INITIALIZED, SUBMITTED) to prevent false positives during venue latency windows.

Source§

impl Cache

Source

pub fn add_pool(&mut self, pool: Pool) -> Result<()>

Adds a Pool to the cache.

§Errors

This function currently does not return errors but follows the same pattern as other add methods for consistency.

Source

pub fn add_pool_profiler(&mut self, pool_profiler: PoolProfiler) -> Result<()>

Adds a PoolProfiler to the cache.

§Errors

This function currently does not return errors but follows the same pattern as other add methods for consistency.

Source

pub fn pool(&self, instrument_id: &InstrumentId) -> Option<&Pool>

Gets a reference to the pool for the instrument_id.

Source

pub fn pool_mut(&mut self, instrument_id: &InstrumentId) -> Option<&mut Pool>

Gets a mutable reference to the pool for the instrument_id.

Source

pub fn pool_ids(&self, venue: Option<&Venue>) -> Vec<InstrumentId>

Returns the instrument IDs of all pools in the cache, optionally filtered by venue.

Source

pub fn pools(&self, venue: Option<&Venue>) -> Vec<&Pool>

Returns references to all pools in the cache, optionally filtered by venue.

Source

pub fn pool_profiler( &self, instrument_id: &InstrumentId, ) -> Option<&PoolProfiler>

Gets a reference to the pool profiler for the instrument_id.

Source

pub fn pool_profiler_mut( &mut self, instrument_id: &InstrumentId, ) -> Option<&mut PoolProfiler>

Gets a mutable reference to the pool profiler for the instrument_id.

Source

pub fn pool_profiler_ids(&self, venue: Option<&Venue>) -> Vec<InstrumentId>

Returns the instrument IDs of all pool profilers in the cache, optionally filtered by venue.

Source

pub fn pool_profilers(&self, venue: Option<&Venue>) -> Vec<&PoolProfiler>

Returns references to all pool profilers in the cache, optionally filtered by venue.

Trait Implementations§

Source§

impl Debug for Cache

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Cache

Source§

fn default() -> Self

Creates a new default Cache instance.

Source§

impl<'py> IntoPyObject<'py> for Cache

Source§

type Target = Cache

The Python output type
Source§

type Output = Bound<'py, <Cache as IntoPyObject<'py>>::Target>

The smart pointer type to use. Read more
Source§

type Error = PyErr

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

fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>

Performs the conversion.
Source§

impl PyClass for Cache

Source§

const NAME: &str = "Cache"

Name of the class. Read more
Source§

type Frozen = False

Whether the pyclass is frozen. Read more
Source§

impl PyClassImpl for Cache

Source§

const MODULE: Option<&str>

Module which the class will be associated with. Read more
Source§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
Source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
Source§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
Source§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
Source§

const IS_IMMUTABLE_TYPE: bool = false

#[pyclass(immutable_type)]
Source§

const RAW_DOC: &'static CStr = /// A common in-memory `Cache` for market and execution related data.

Docstring for the class provided on the struct or enum. Read more
Source§

const DOC: &'static CStr

Fully rendered class doc, including the text_signature if a constructor is defined. Read more
Source§

type Layout = <<Cache as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<Cache>

Description of how this class is laid out in memory
Source§

type BaseType = PyAny

Base class
Source§

type ThreadChecker = ThreadCheckerImpl

This handles following two situations: Read more
Source§

type Inventory = Pyo3MethodsInventoryForCache

Source§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild

Immutable or mutable
Source§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
Source§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
Source§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
Source§

fn items_iter() -> PyClassItemsIter

Source§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

Source§

fn dict_offset() -> Option<PyObjectOffset>

Used to provide the dictoffset slot (equivalent to tp_dictoffset)
Source§

fn weaklist_offset() -> Option<PyObjectOffset>

Used to provide the weaklistoffset slot (equivalent to tp_weaklistoffset
Source§

impl PyClassNewTextSignature for Cache

Source§

const TEXT_SIGNATURE: &'static str = "(config)"

Source§

impl PyTypeInfo for Cache

Source§

const NAME: &str = <Self as ::pyo3::PyClass>::NAME

👎Deprecated since 0.28.0:

prefer using ::type_object(py).name() to get the correct runtime value

Class name.
Source§

const MODULE: Option<&str> = <Self as ::pyo3::impl_::pyclass::PyClassImpl>::MODULE

👎Deprecated since 0.28.0:

prefer using ::type_object(py).module() to get the correct runtime value

Module name, if any.
Source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
Source§

fn type_object(py: Python<'_>) -> Bound<'_, PyType>

Returns the safe abstraction over the type object.
Source§

fn is_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type or a subclass of this type.
Source§

fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type.
Source§

impl DerefToPyAny for Cache

Source§

impl ExtractPyClassWithClone for Cache

Auto Trait Implementations§

§

impl Freeze for Cache

§

impl !RefUnwindSafe for Cache

§

impl !Send for Cache

§

impl !Sync for Cache

§

impl Unpin for Cache

§

impl UnsafeUnpin for Cache

§

impl !UnwindSafe for Cache

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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

impl<'py, T> IntoPyObjectExt<'py> for T
where T: IntoPyObject<'py>,

Source§

fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>

Converts self into an owned Python object, dropping type information.
Source§

fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>

Converts self into an owned Python object, dropping type information and unbinding it from the 'py lifetime.
Source§

fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>

Converts self into a Python object. Read more
Source§

impl<'py, T> IntoPyObjectNautilusExt<'py> for T
where T: IntoPyObjectExt<'py>,

Source§

fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>

Convert self into a Py<PyAny> while panicking if the conversion fails. Read more
Source§

impl<T> PyTypeCheck for T
where T: PyTypeInfo,

Source§

const NAME: &'static str = T::NAME

👎Deprecated since 0.27.0:

Use ::classinfo_object() instead and format the type name at runtime. Note that using built-in cast features is often better than manual PyTypeCheck usage.

Name of self. This is used in error messages, for example.
Source§

fn type_check(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of Self, which may include a subtype. Read more
Source§

fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>

Returns the expected type as a possible argument for the isinstance and issubclass function. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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