pub struct Cache { /* private fields */ }
Expand description
A common in-memory Cache
for market and execution related data.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn new(
config: Option<CacheConfig>,
database: Option<Box<dyn CacheDatabaseAdapter>>,
) -> Self
pub fn new( config: Option<CacheConfig>, database: Option<Box<dyn CacheDatabaseAdapter>>, ) -> Self
Sourcepub fn memory_address(&self) -> String
pub fn memory_address(&self) -> String
Returns the cache instances memory address.
Sourcepub fn cache_general(&mut self) -> Result<()>
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.
Sourcepub async fn cache_all(&mut self) -> Result<()>
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.
Sourcepub async fn cache_currencies(&mut self) -> Result<()>
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.
Sourcepub async fn cache_instruments(&mut self) -> Result<()>
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.
Sourcepub async fn cache_synthetics(&mut self) -> Result<()>
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.
Sourcepub async fn cache_accounts(&mut self) -> Result<()>
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.
Sourcepub async fn cache_orders(&mut self) -> Result<()>
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.
Sourcepub async fn cache_positions(&mut self) -> Result<()>
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.
Sourcepub fn build_index(&mut self)
pub fn build_index(&mut self)
Clears the current cache index and re-build.
Sourcepub const fn has_backing(&self) -> bool
pub const fn has_backing(&self) -> bool
Returns whether the cache has a backing database.
pub fn calculate_unrealized_pnl(&self, position: &Position) -> Option<Money>
Sourcepub fn check_integrity(&mut self) -> bool
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.
Sourcepub fn check_residuals(&self) -> bool
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.
Sourcepub fn purge_closed_orders(&mut self, ts_now: UnixNanos, buffer_secs: u64)
pub fn purge_closed_orders(&mut self, ts_now: UnixNanos, buffer_secs: u64)
Purges all closed orders from the cache that are older than the given buffer time.
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.
Sourcepub fn purge_closed_positions(&mut self, ts_now: UnixNanos, buffer_secs: u64)
pub fn purge_closed_positions(&mut self, ts_now: UnixNanos, buffer_secs: u64)
Purges all closed positions from the cache that are older than the given buffer time.
Sourcepub fn purge_order(&mut self, client_order_id: ClientOrderId)
pub fn purge_order(&mut self, client_order_id: ClientOrderId)
Purges the order with the given client order ID from the cache (if found).
All OrderFilled
events for the order will also be purged from any associated position.
Sourcepub fn purge_position(&mut self, position_id: PositionId)
pub fn purge_position(&mut self, position_id: PositionId)
Purges the position with the given position ID from the cache (if found).
Sourcepub fn purge_account_events(&mut self, ts_now: UnixNanos, lookback_secs: u64)
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.
Sourcepub fn clear_index(&mut self)
pub fn clear_index(&mut self)
Clears the caches index.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the cache.
All stateful fields are reset to their initial value.
Sourcepub fn dispose(&mut self)
pub fn dispose(&mut self)
Dispose of the cache which will close any underlying database adapter.
§Panics
Panics if closing the database connection fails.
Sourcepub fn flush_db(&mut self)
pub fn flush_db(&mut self)
Flushes the caches database which permanently removes all persisted data.
§Panics
Panics if flushing the database connection fails.
Sourcepub fn add(&mut self, key: &str, value: Bytes) -> Result<()>
pub fn add(&mut self, key: &str, value: Bytes) -> Result<()>
Adds a raw bytes entry to the cache under the given 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.
Sourcepub fn add_order_book(&mut self, book: OrderBook) -> Result<()>
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.
Sourcepub fn add_own_order_book(&mut self, own_book: OwnOrderBook) -> Result<()>
pub fn add_own_order_book(&mut self, own_book: OwnOrderBook) -> Result<()>
Sourcepub fn add_mark_price(&mut self, mark_price: MarkPriceUpdate) -> Result<()>
pub fn add_mark_price(&mut self, mark_price: MarkPriceUpdate) -> Result<()>
Adds the given mark_price
update for the given instrument_id
to the cache.
§Errors
Returns an error if persisting the mark price to the backing database fails.
Sourcepub fn add_index_price(&mut self, index_price: IndexPriceUpdate) -> Result<()>
pub fn add_index_price(&mut self, index_price: IndexPriceUpdate) -> Result<()>
Adds the given index_price
update for the given instrument_id
to the cache.
§Errors
Returns an error if persisting the index price to the backing database fails.
Sourcepub fn add_quote(&mut self, quote: QuoteTick) -> Result<()>
pub fn add_quote(&mut self, quote: QuoteTick) -> Result<()>
Adds the given quote
tick to the cache.
§Errors
Returns an error if persisting the quote tick to the backing database fails.
Sourcepub fn add_quotes(&mut self, quotes: &[QuoteTick]) -> Result<()>
pub fn add_quotes(&mut self, quotes: &[QuoteTick]) -> Result<()>
Adds the given quotes
to the cache.
§Errors
Returns an error if persisting the quote ticks to the backing database fails.
Sourcepub fn add_trade(&mut self, trade: TradeTick) -> Result<()>
pub fn add_trade(&mut self, trade: TradeTick) -> Result<()>
Adds the given trade
tick to the cache.
§Errors
Returns an error if persisting the trade tick to the backing database fails.
Sourcepub fn add_trades(&mut self, trades: &[TradeTick]) -> Result<()>
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.
Sourcepub fn add_bar(&mut self, bar: Bar) -> Result<()>
pub fn add_bar(&mut self, bar: Bar) -> Result<()>
Adds the given bar
to the cache.
§Errors
Returns an error if persisting the bar to the backing database fails.
Sourcepub fn add_bars(&mut self, bars: &[Bar]) -> Result<()>
pub fn add_bars(&mut self, bars: &[Bar]) -> Result<()>
Adds the given bars
to the cache.
§Errors
Returns an error if persisting the bars to the backing database fails.
Sourcepub fn add_greeks(&mut self, greeks: GreeksData) -> Result<()>
pub fn add_greeks(&mut self, greeks: GreeksData) -> Result<()>
Adds the given greeks
data to the cache.
§Errors
Returns an error if persisting the greeks data to the backing database fails.
Sourcepub fn greeks(&self, instrument_id: &InstrumentId) -> Option<GreeksData>
pub fn greeks(&self, instrument_id: &InstrumentId) -> Option<GreeksData>
Gets the greeks data for the given instrument ID.
Sourcepub fn add_yield_curve(&mut self, yield_curve: YieldCurveData) -> Result<()>
pub fn add_yield_curve(&mut self, yield_curve: YieldCurveData) -> Result<()>
Adds the given yield_curve
data to the cache.
§Errors
Returns an error if persisting the yield curve data to the backing database fails.
Sourcepub fn yield_curve(&self, key: &str) -> Option<Box<dyn Fn(f64) -> f64>>
pub fn yield_curve(&self, key: &str) -> Option<Box<dyn Fn(f64) -> f64>>
Gets the yield curve for the given key.
Sourcepub fn add_currency(&mut self, currency: Currency) -> Result<()>
pub fn add_currency(&mut self, currency: Currency) -> Result<()>
Adds the given currency
to the cache.
§Errors
Returns an error if persisting the currency to the backing database fails.
Sourcepub fn add_instrument(&mut self, instrument: InstrumentAny) -> Result<()>
pub fn add_instrument(&mut self, instrument: InstrumentAny) -> Result<()>
Adds the given instrument
to the cache.
§Errors
Returns an error if persisting the instrument to the backing database fails.
Sourcepub fn add_synthetic(&mut self, synthetic: SyntheticInstrument) -> Result<()>
pub fn add_synthetic(&mut self, synthetic: SyntheticInstrument) -> Result<()>
Adds the given synthetic
instrument to the cache.
§Errors
Returns an error if persisting the synthetic instrument to the backing database fails.
Sourcepub fn add_account(&mut self, account: AccountAny) -> Result<()>
pub fn add_account(&mut self, account: AccountAny) -> Result<()>
Adds the given account
to the cache.
§Errors
Returns an error if persisting the account to the backing database fails.
Sourcepub fn add_venue_order_id(
&mut self,
client_order_id: &ClientOrderId,
venue_order_id: &VenueOrderId,
overwrite: bool,
) -> Result<()>
pub fn add_venue_order_id( &mut self, client_order_id: &ClientOrderId, venue_order_id: &VenueOrderId, overwrite: bool, ) -> Result<()>
Indexes the given client_order_id
with the given 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.
Sourcepub fn add_order(
&mut self,
order: OrderAny,
position_id: Option<PositionId>,
client_id: Option<ClientId>,
replace_existing: bool,
) -> Result<()>
pub fn add_order( &mut self, order: OrderAny, position_id: Option<PositionId>, client_id: Option<ClientId>, replace_existing: bool, ) -> Result<()>
Adds the given 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.
Sourcepub fn add_position_id(
&mut self,
position_id: &PositionId,
venue: &Venue,
client_order_id: &ClientOrderId,
strategy_id: &StrategyId,
) -> Result<()>
pub fn add_position_id( &mut self, position_id: &PositionId, venue: &Venue, client_order_id: &ClientOrderId, strategy_id: &StrategyId, ) -> Result<()>
Indexes the given position_id
with the other given IDs.
§Errors
Returns an error if indexing position ID in the backing database fails.
Sourcepub fn add_position(
&mut self,
position: Position,
_oms_type: OmsType,
) -> Result<()>
pub fn add_position( &mut self, position: Position, _oms_type: OmsType, ) -> Result<()>
Adds the given position
to the cache.
§Errors
Returns an error if persisting the position to the backing database fails.
Sourcepub fn update_account(&mut self, account: AccountAny) -> Result<()>
pub fn update_account(&mut self, account: AccountAny) -> Result<()>
Updates the given account
in the cache.
§Errors
Returns an error if updating the account in the database fails.
Sourcepub fn update_order(&mut self, order: &OrderAny) -> Result<()>
pub fn update_order(&mut self, order: &OrderAny) -> Result<()>
Updates the given order
in the cache.
§Errors
Returns an error if updating the order in the database fails.
Sourcepub fn update_order_pending_cancel_local(&mut self, order: &OrderAny)
pub fn update_order_pending_cancel_local(&mut self, order: &OrderAny)
Updates the given order
as pending cancel locally.
Sourcepub fn update_position(&mut self, position: &Position) -> Result<()>
pub fn update_position(&mut self, position: &Position) -> Result<()>
Updates the given position
in the cache.
§Errors
Returns an error if updating the position in the database fails.
Sourcepub fn snapshot_position(&mut self, position: &Position) -> Result<()>
pub fn snapshot_position(&mut self, position: &Position) -> Result<()>
Creates a snapshot of the given 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.
Sourcepub fn snapshot_position_state(
&mut self,
position: &Position,
open_only: Option<bool>,
) -> Result<()>
pub fn snapshot_position_state( &mut self, position: &Position, open_only: Option<bool>, ) -> Result<()>
Creates a snapshot of the given position state in the database.
§Errors
Returns an error if snapshotting the position state fails.
Sourcepub fn snapshot_order_state(&self, order: &OrderAny) -> Result<()>
pub fn snapshot_order_state(&self, order: &OrderAny) -> Result<()>
Snapshots the given order state in the database.
§Errors
Returns an error if snapshotting the order state fails.
Sourcepub fn client_order_ids(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
) -> HashSet<ClientOrderId>
pub fn client_order_ids( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, ) -> HashSet<ClientOrderId>
Returns the ClientOrderId
s of all orders.
Sourcepub fn client_order_ids_open(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
) -> HashSet<ClientOrderId>
pub fn client_order_ids_open( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, ) -> HashSet<ClientOrderId>
Returns the ClientOrderId
s of all open orders.
Sourcepub fn client_order_ids_closed(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
) -> HashSet<ClientOrderId>
pub fn client_order_ids_closed( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, ) -> HashSet<ClientOrderId>
Returns the ClientOrderId
s of all closed orders.
Sourcepub fn client_order_ids_emulated(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
) -> HashSet<ClientOrderId>
pub fn client_order_ids_emulated( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, ) -> HashSet<ClientOrderId>
Returns the ClientOrderId
s of all emulated orders.
Sourcepub fn client_order_ids_inflight(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
) -> HashSet<ClientOrderId>
pub fn client_order_ids_inflight( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, ) -> HashSet<ClientOrderId>
Returns the ClientOrderId
s of all in-flight orders.
Sourcepub fn position_ids(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
) -> HashSet<PositionId>
pub fn position_ids( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, ) -> HashSet<PositionId>
Returns PositionId
s of all positions.
Sourcepub fn position_open_ids(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
) -> HashSet<PositionId>
pub fn position_open_ids( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, ) -> HashSet<PositionId>
Returns the PositionId
s of all open positions.
Sourcepub fn position_closed_ids(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
) -> HashSet<PositionId>
pub fn position_closed_ids( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, ) -> HashSet<PositionId>
Returns the PositionId
s of all closed positions.
Sourcepub fn strategy_ids(&self) -> HashSet<StrategyId>
pub fn strategy_ids(&self) -> HashSet<StrategyId>
Returns the StrategyId
s of all strategies.
Sourcepub fn exec_algorithm_ids(&self) -> HashSet<ExecAlgorithmId>
pub fn exec_algorithm_ids(&self) -> HashSet<ExecAlgorithmId>
Returns the ExecAlgorithmId
s of all execution algorithms.
Sourcepub fn order(&self, client_order_id: &ClientOrderId) -> Option<&OrderAny>
pub fn order(&self, client_order_id: &ClientOrderId) -> Option<&OrderAny>
Gets a reference to the order with the given client_order_id
(if found).
Sourcepub fn mut_order(
&mut self,
client_order_id: &ClientOrderId,
) -> Option<&mut OrderAny>
pub fn mut_order( &mut self, client_order_id: &ClientOrderId, ) -> Option<&mut OrderAny>
Gets a reference to the order with the given client_order_id
(if found).
Sourcepub fn client_order_id(
&self,
venue_order_id: &VenueOrderId,
) -> Option<&ClientOrderId>
pub fn client_order_id( &self, venue_order_id: &VenueOrderId, ) -> Option<&ClientOrderId>
Gets a reference to the client order ID for given venue_order_id
(if found).
Sourcepub fn venue_order_id(
&self,
client_order_id: &ClientOrderId,
) -> Option<&VenueOrderId>
pub fn venue_order_id( &self, client_order_id: &ClientOrderId, ) -> Option<&VenueOrderId>
Gets a reference to the venue order ID for given client_order_id
(if found).
Sourcepub fn client_id(&self, client_order_id: &ClientOrderId) -> Option<&ClientId>
pub fn client_id(&self, client_order_id: &ClientOrderId) -> Option<&ClientId>
Gets a reference to the client ID indexed for given client_order_id
(if found).
Sourcepub fn orders(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<OrderSide>,
) -> Vec<&OrderAny>
pub fn orders( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<OrderSide>, ) -> Vec<&OrderAny>
Returns references to all orders matching the given optional filter parameters.
Sourcepub fn orders_open(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<OrderSide>,
) -> Vec<&OrderAny>
pub fn orders_open( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<OrderSide>, ) -> Vec<&OrderAny>
Returns references to all open orders matching the given optional filter parameters.
Sourcepub fn orders_closed(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<OrderSide>,
) -> Vec<&OrderAny>
pub fn orders_closed( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<OrderSide>, ) -> Vec<&OrderAny>
Returns references to all closed orders matching the given optional filter parameters.
Sourcepub fn orders_emulated(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<OrderSide>,
) -> Vec<&OrderAny>
pub fn orders_emulated( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<OrderSide>, ) -> Vec<&OrderAny>
Returns references to all emulated orders matching the given optional filter parameters.
Sourcepub fn orders_inflight(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<OrderSide>,
) -> Vec<&OrderAny>
pub fn orders_inflight( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<OrderSide>, ) -> Vec<&OrderAny>
Returns references to all in-flight orders matching the given optional filter parameters.
Sourcepub fn orders_for_position(&self, position_id: &PositionId) -> Vec<&OrderAny>
pub fn orders_for_position(&self, position_id: &PositionId) -> Vec<&OrderAny>
Returns references to all orders for the given position_id
.
Sourcepub fn order_exists(&self, client_order_id: &ClientOrderId) -> bool
pub fn order_exists(&self, client_order_id: &ClientOrderId) -> bool
Returns whether an order with the given client_order_id
exists.
Sourcepub fn is_order_open(&self, client_order_id: &ClientOrderId) -> bool
pub fn is_order_open(&self, client_order_id: &ClientOrderId) -> bool
Returns whether an order with the given client_order_id
is open.
Sourcepub fn is_order_closed(&self, client_order_id: &ClientOrderId) -> bool
pub fn is_order_closed(&self, client_order_id: &ClientOrderId) -> bool
Returns whether an order with the given client_order_id
is closed.
Sourcepub fn is_order_emulated(&self, client_order_id: &ClientOrderId) -> bool
pub fn is_order_emulated(&self, client_order_id: &ClientOrderId) -> bool
Returns whether an order with the given client_order_id
is emulated.
Sourcepub fn is_order_inflight(&self, client_order_id: &ClientOrderId) -> bool
pub fn is_order_inflight(&self, client_order_id: &ClientOrderId) -> bool
Returns whether an order with the given client_order_id
is in-flight.
Sourcepub fn is_order_pending_cancel_local(
&self,
client_order_id: &ClientOrderId,
) -> bool
pub fn is_order_pending_cancel_local( &self, client_order_id: &ClientOrderId, ) -> bool
Returns whether an order with the given client_order_id
is PENDING_CANCEL
locally.
Sourcepub fn orders_open_count(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<OrderSide>,
) -> usize
pub fn orders_open_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<OrderSide>, ) -> usize
Returns the count of all open orders.
Sourcepub fn orders_closed_count(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<OrderSide>,
) -> usize
pub fn orders_closed_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<OrderSide>, ) -> usize
Returns the count of all closed orders.
Sourcepub fn orders_emulated_count(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<OrderSide>,
) -> usize
pub fn orders_emulated_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<OrderSide>, ) -> usize
Returns the count of all emulated orders.
Sourcepub fn orders_inflight_count(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<OrderSide>,
) -> usize
pub fn orders_inflight_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<OrderSide>, ) -> usize
Returns the count of all in-flight orders.
Sourcepub fn orders_total_count(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<OrderSide>,
) -> usize
pub fn orders_total_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<OrderSide>, ) -> usize
Returns the count of all orders.
Sourcepub fn order_list(&self, order_list_id: &OrderListId) -> Option<&OrderList>
pub fn order_list(&self, order_list_id: &OrderListId) -> Option<&OrderList>
Returns the order list for the given order_list_id
.
Sourcepub fn order_lists(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
) -> Vec<&OrderList>
pub fn order_lists( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, ) -> Vec<&OrderList>
Returns all order lists matching the given optional filter parameters.
Sourcepub fn order_list_exists(&self, order_list_id: &OrderListId) -> bool
pub fn order_list_exists(&self, order_list_id: &OrderListId) -> bool
Returns whether an order list with the given order_list_id
exists.
Sourcepub fn orders_for_exec_algorithm(
&self,
exec_algorithm_id: &ExecAlgorithmId,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<OrderSide>,
) -> Vec<&OrderAny>
pub fn orders_for_exec_algorithm( &self, exec_algorithm_id: &ExecAlgorithmId, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<OrderSide>, ) -> Vec<&OrderAny>
Returns references to all orders associated with the given exec_algorithm_id
matching the given
optional filter parameters.
Sourcepub fn orders_for_exec_spawn(
&self,
exec_spawn_id: &ClientOrderId,
) -> Vec<&OrderAny>
pub fn orders_for_exec_spawn( &self, exec_spawn_id: &ClientOrderId, ) -> Vec<&OrderAny>
Returns references to all orders with the given exec_spawn_id
.
Sourcepub fn exec_spawn_total_quantity(
&self,
exec_spawn_id: &ClientOrderId,
active_only: bool,
) -> Option<Quantity>
pub fn exec_spawn_total_quantity( &self, exec_spawn_id: &ClientOrderId, active_only: bool, ) -> Option<Quantity>
Returns the total order quantity for the given exec_spawn_id
.
Sourcepub fn exec_spawn_total_filled_qty(
&self,
exec_spawn_id: &ClientOrderId,
active_only: bool,
) -> Option<Quantity>
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 given exec_spawn_id
.
Sourcepub fn exec_spawn_total_leaves_qty(
&self,
exec_spawn_id: &ClientOrderId,
active_only: bool,
) -> Option<Quantity>
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 given exec_spawn_id
.
Sourcepub fn position(&self, position_id: &PositionId) -> Option<&Position>
pub fn position(&self, position_id: &PositionId) -> Option<&Position>
Returns a reference to the position with the given position_id
(if found).
Sourcepub fn position_for_order(
&self,
client_order_id: &ClientOrderId,
) -> Option<&Position>
pub fn position_for_order( &self, client_order_id: &ClientOrderId, ) -> Option<&Position>
Returns a reference to the position for the given client_order_id
(if found).
Sourcepub fn position_id(
&self,
client_order_id: &ClientOrderId,
) -> Option<&PositionId>
pub fn position_id( &self, client_order_id: &ClientOrderId, ) -> Option<&PositionId>
Returns a reference to the position ID for the given client_order_id
(if found).
Sourcepub fn positions(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<PositionSide>,
) -> Vec<&Position>
pub fn positions( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<PositionSide>, ) -> Vec<&Position>
Returns a reference to all positions matching the given optional filter parameters.
Sourcepub fn positions_open(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<PositionSide>,
) -> Vec<&Position>
pub fn positions_open( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<PositionSide>, ) -> Vec<&Position>
Returns a reference to all open positions matching the given optional filter parameters.
Sourcepub fn positions_closed(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<PositionSide>,
) -> Vec<&Position>
pub fn positions_closed( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<PositionSide>, ) -> Vec<&Position>
Returns a reference to all closed positions matching the given optional filter parameters.
Sourcepub fn position_exists(&self, position_id: &PositionId) -> bool
pub fn position_exists(&self, position_id: &PositionId) -> bool
Returns whether a position with the given position_id
exists.
Sourcepub fn is_position_open(&self, position_id: &PositionId) -> bool
pub fn is_position_open(&self, position_id: &PositionId) -> bool
Returns whether a position with the given position_id
is open.
Sourcepub fn is_position_closed(&self, position_id: &PositionId) -> bool
pub fn is_position_closed(&self, position_id: &PositionId) -> bool
Returns whether a position with the given position_id
is closed.
Sourcepub fn positions_open_count(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<PositionSide>,
) -> usize
pub fn positions_open_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<PositionSide>, ) -> usize
Returns the count of all open positions.
Sourcepub fn positions_closed_count(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<PositionSide>,
) -> usize
pub fn positions_closed_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<PositionSide>, ) -> usize
Returns the count of all closed positions.
Sourcepub fn positions_total_count(
&self,
venue: Option<&Venue>,
instrument_id: Option<&InstrumentId>,
strategy_id: Option<&StrategyId>,
side: Option<PositionSide>,
) -> usize
pub fn positions_total_count( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, side: Option<PositionSide>, ) -> usize
Returns the count of all positions.
Sourcepub fn strategy_id_for_order(
&self,
client_order_id: &ClientOrderId,
) -> Option<&StrategyId>
pub fn strategy_id_for_order( &self, client_order_id: &ClientOrderId, ) -> Option<&StrategyId>
Gets a reference to the strategy ID for the given client_order_id
(if found).
Sourcepub fn strategy_id_for_position(
&self,
position_id: &PositionId,
) -> Option<&StrategyId>
pub fn strategy_id_for_position( &self, position_id: &PositionId, ) -> Option<&StrategyId>
Gets a reference to the strategy ID for the given position_id
(if found).
Sourcepub fn get(&self, key: &str) -> Result<Option<&Bytes>>
pub fn get(&self, key: &str) -> Result<Option<&Bytes>>
Gets a reference to the general object value for the given key
(if found).
§Errors
Returns an error if the key
is invalid.
Sourcepub fn price(
&self,
instrument_id: &InstrumentId,
price_type: PriceType,
) -> Option<Price>
pub fn price( &self, instrument_id: &InstrumentId, price_type: PriceType, ) -> Option<Price>
Returns the price for the given instrument_id
and price_type
(if found).
Sourcepub fn quotes(&self, instrument_id: &InstrumentId) -> Option<Vec<QuoteTick>>
pub fn quotes(&self, instrument_id: &InstrumentId) -> Option<Vec<QuoteTick>>
Gets all quotes for the given instrument_id
.
Sourcepub fn trades(&self, instrument_id: &InstrumentId) -> Option<Vec<TradeTick>>
pub fn trades(&self, instrument_id: &InstrumentId) -> Option<Vec<TradeTick>>
Gets all trades for the given instrument_id
.
Sourcepub fn mark_prices(
&self,
instrument_id: &InstrumentId,
) -> Option<Vec<MarkPriceUpdate>>
pub fn mark_prices( &self, instrument_id: &InstrumentId, ) -> Option<Vec<MarkPriceUpdate>>
Gets all mark price updates for the given instrument_id
.
Sourcepub fn index_prices(
&self,
instrument_id: &InstrumentId,
) -> Option<Vec<IndexPriceUpdate>>
pub fn index_prices( &self, instrument_id: &InstrumentId, ) -> Option<Vec<IndexPriceUpdate>>
Gets all index price updates for the given instrument_id
.
Sourcepub fn bars(&self, bar_type: &BarType) -> Option<Vec<Bar>>
pub fn bars(&self, bar_type: &BarType) -> Option<Vec<Bar>>
Gets all bars for the given bar_type
.
Sourcepub fn order_book(&self, instrument_id: &InstrumentId) -> Option<&OrderBook>
pub fn order_book(&self, instrument_id: &InstrumentId) -> Option<&OrderBook>
Gets a reference to the order book for the given instrument_id
.
Sourcepub fn order_book_mut(
&mut self,
instrument_id: &InstrumentId,
) -> Option<&mut OrderBook>
pub fn order_book_mut( &mut self, instrument_id: &InstrumentId, ) -> Option<&mut OrderBook>
Gets a reference to the order book for the given instrument_id
.
Sourcepub fn own_order_book(
&self,
instrument_id: &InstrumentId,
) -> Option<&OwnOrderBook>
pub fn own_order_book( &self, instrument_id: &InstrumentId, ) -> Option<&OwnOrderBook>
Gets a reference to the own order book for the given instrument_id
.
Sourcepub fn own_order_book_mut(
&mut self,
instrument_id: &InstrumentId,
) -> Option<&mut OwnOrderBook>
pub fn own_order_book_mut( &mut self, instrument_id: &InstrumentId, ) -> Option<&mut OwnOrderBook>
Gets a reference to the own order book for the given instrument_id
.
Sourcepub fn quote(&self, instrument_id: &InstrumentId) -> Option<&QuoteTick>
pub fn quote(&self, instrument_id: &InstrumentId) -> Option<&QuoteTick>
Gets a reference to the latest quote tick for the given instrument_id
.
Sourcepub fn trade(&self, instrument_id: &InstrumentId) -> Option<&TradeTick>
pub fn trade(&self, instrument_id: &InstrumentId) -> Option<&TradeTick>
Gets a reference to the latest trade tick for the given instrument_id
.
Sourcepub fn mark_price(
&self,
instrument_id: &InstrumentId,
) -> Option<&MarkPriceUpdate>
pub fn mark_price( &self, instrument_id: &InstrumentId, ) -> Option<&MarkPriceUpdate>
Gets a referenece to the latest mark price update for the given instrument_id
.
Sourcepub fn index_price(
&self,
instrument_id: &InstrumentId,
) -> Option<&IndexPriceUpdate>
pub fn index_price( &self, instrument_id: &InstrumentId, ) -> Option<&IndexPriceUpdate>
Gets a referenece to the latest index price update for the given instrument_id
.
Sourcepub fn bar(&self, bar_type: &BarType) -> Option<&Bar>
pub fn bar(&self, bar_type: &BarType) -> Option<&Bar>
Gets a reference to the latest bar for the given bar_type
.
Sourcepub fn book_update_count(&self, instrument_id: &InstrumentId) -> usize
pub fn book_update_count(&self, instrument_id: &InstrumentId) -> usize
Gets the order book update count for the given instrument_id
.
Sourcepub fn quote_count(&self, instrument_id: &InstrumentId) -> usize
pub fn quote_count(&self, instrument_id: &InstrumentId) -> usize
Gets the quote tick count for the given instrument_id
.
Sourcepub fn trade_count(&self, instrument_id: &InstrumentId) -> usize
pub fn trade_count(&self, instrument_id: &InstrumentId) -> usize
Gets the trade tick count for the given instrument_id
.
Sourcepub fn bar_count(&self, bar_type: &BarType) -> usize
pub fn bar_count(&self, bar_type: &BarType) -> usize
Gets the bar count for the given instrument_id
.
Sourcepub fn has_order_book(&self, instrument_id: &InstrumentId) -> bool
pub fn has_order_book(&self, instrument_id: &InstrumentId) -> bool
Returns whether the cache contains an order book for the given instrument_id
.
Sourcepub fn has_quote_ticks(&self, instrument_id: &InstrumentId) -> bool
pub fn has_quote_ticks(&self, instrument_id: &InstrumentId) -> bool
Returns whether the cache contains quotes for the given instrument_id
.
Sourcepub fn has_trade_ticks(&self, instrument_id: &InstrumentId) -> bool
pub fn has_trade_ticks(&self, instrument_id: &InstrumentId) -> bool
Returns whether the cache contains trades for the given instrument_id
.
Sourcepub fn has_bars(&self, bar_type: &BarType) -> bool
pub fn has_bars(&self, bar_type: &BarType) -> bool
Returns whether the cache contains bars for the given bar_type
.
pub fn get_xrate( &self, venue: Venue, from_currency: Currency, to_currency: Currency, price_type: PriceType, ) -> Option<f64>
Sourcepub fn get_mark_xrate(
&self,
from_currency: Currency,
to_currency: Currency,
) -> Option<f64>
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.
Sourcepub fn set_mark_xrate(
&mut self,
from_currency: Currency,
to_currency: Currency,
xrate: f64,
)
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.
Sourcepub fn clear_mark_xrate(
&mut self,
from_currency: Currency,
to_currency: Currency,
)
pub fn clear_mark_xrate( &mut self, from_currency: Currency, to_currency: Currency, )
Clears the mark exchange rate for the given currency pair.
Sourcepub fn clear_mark_xrates(&mut self)
pub fn clear_mark_xrates(&mut self)
Clears all mark exchange rates.
Sourcepub fn instrument(&self, instrument_id: &InstrumentId) -> Option<&InstrumentAny>
pub fn instrument(&self, instrument_id: &InstrumentId) -> Option<&InstrumentAny>
Returns a reference to the instrument for the given instrument_id
(if found).
Sourcepub fn instrument_ids(&self, venue: Option<&Venue>) -> Vec<&InstrumentId>
pub fn instrument_ids(&self, venue: Option<&Venue>) -> Vec<&InstrumentId>
Returns references to all instrument IDs for the given venue
.
Sourcepub fn instruments(
&self,
venue: &Venue,
underlying: Option<&Ustr>,
) -> Vec<&InstrumentAny>
pub fn instruments( &self, venue: &Venue, underlying: Option<&Ustr>, ) -> Vec<&InstrumentAny>
Returns references to all instruments for the given venue
.
Sourcepub fn bar_types(
&self,
instrument_id: Option<&InstrumentId>,
price_type: Option<&PriceType>,
aggregation_source: AggregationSource,
) -> Vec<&BarType>
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.
Sourcepub fn synthetic(
&self,
instrument_id: &InstrumentId,
) -> Option<&SyntheticInstrument>
pub fn synthetic( &self, instrument_id: &InstrumentId, ) -> Option<&SyntheticInstrument>
Returns a reference to the synthetic instrument for the given instrument_id
(if found).
Sourcepub fn synthetic_ids(&self) -> Vec<&InstrumentId>
pub fn synthetic_ids(&self) -> Vec<&InstrumentId>
Returns references to instrument IDs for all synthetic instruments contained in the cache.
Sourcepub fn synthetics(&self) -> Vec<&SyntheticInstrument>
pub fn synthetics(&self) -> Vec<&SyntheticInstrument>
Returns references to all synthetic instruments contained in the cache.
Sourcepub fn account(&self, account_id: &AccountId) -> Option<&AccountAny>
pub fn account(&self, account_id: &AccountId) -> Option<&AccountAny>
Returns a reference to the account for the given account_id
(if found).
Sourcepub fn account_for_venue(&self, venue: &Venue) -> Option<&AccountAny>
pub fn account_for_venue(&self, venue: &Venue) -> Option<&AccountAny>
Returns a reference to the account for the given venue
(if found).
Sourcepub fn account_id(&self, venue: &Venue) -> Option<&AccountId>
pub fn account_id(&self, venue: &Venue) -> Option<&AccountId>
Returns a reference to the account ID for the given venue
(if found).