nautilus_common::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.

source

pub fn memory_address(&self) -> String

Returns the cache instances memory address.

source

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

Clears the current general cache and loads the general objects from the cache database.

source

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

Clears the current currencies cache and loads currencies from the cache database.

source

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

Clears the current instruments cache and loads instruments from the cache database.

source

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

Clears the current synthetic instruments cache and loads synthetic instruments from the cache database.

source

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

Clears the current accounts cache and loads accounts from the cache database.

source

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

Clears the current orders cache and loads orders from the cache database.

source

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

Clears the current positions cache and loads positions from the cache database.

source

pub fn build_index(&mut self)

Clears the current cache index and re-build.

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

source

pub fn dispose(&mut self)

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

source

pub fn flush_db(&mut self)

Flushes the caches database which permanently removes all persisted data.

source

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

Adds a general object value (as bytes) to the cache at the given key.

The cache is agnostic to what the bytes actually represent (and how it may be serialized), which provides maximum flexibility.

source

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

Adds the given order book to the cache.

source

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

Adds the given quote tick to the cache.

source

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

Adds the given quotes to the cache.

source

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

Adds the given trade tick to the cache.

source

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

Adds the give trades to the cache.

source

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

Adds the given bar to the cache.

source

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

Adds the given bars to the cache.

source

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

Adds the given currency to the cache.

source

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

Adds the given instrument to the cache.

source

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

Adds the given synthetic instrument to the cache.

source

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

Adds the given account to the cache.

source

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.

source

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

This function returns an error: If not replace_existing and the order.client_order_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 given position_id with the other given IDs.

source

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

Adds the given position to the cache.

source

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

Updates the given account in the cache.

source

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

Updates the given order in the cache.

source

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

Updates the given order as pending cancel locally.

source

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

Updates the given position in the cache.

source

pub fn client_order_ids( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, ) -> HashSet<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>, ) -> HashSet<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>, ) -> HashSet<ClientOrderId>

Returns the ClientOrderIds of all closed orders.

source

pub fn client_order_ids_emulated( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, ) -> HashSet<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>, ) -> HashSet<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>, ) -> HashSet<PositionId>

Returns PositionIds of all positions.

source

pub fn position_open_ids( &self, venue: Option<&Venue>, instrument_id: Option<&InstrumentId>, strategy_id: Option<&StrategyId>, ) -> HashSet<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>, ) -> HashSet<PositionId>

Returns the PositionIds of all closed positions.

source

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

Returns the ComponentIds of all actors.

source

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

Returns the StrategyIds of all strategies.

source

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

Returns the ExecAlgorithmIds of all execution algorithms.

source

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

Gets a reference to the order with the given client_order_id (if found).

source

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

source

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

source

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

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn orders_for_position(&self, position_id: &PositionId) -> Vec<&OrderAny>

Returns references to all orders for the given position_id.

source

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

Returns whether an order with the given client_order_id exists.

source

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

Returns whether an order with the given client_order_id is open.

source

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

Returns whether an order with the given client_order_id is closed.

source

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

Returns whether an order with the given client_order_id is emulated.

source

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

Returns whether an order with the given 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 given 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>, 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>, side: Option<OrderSide>, ) -> usize

Returns the count of all closed orders.

source

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.

source

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.

source

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.

source

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

Returns the order list for the given order_list_id.

source

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.

source

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

Returns whether an order list with the given 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>, side: Option<OrderSide>, ) -> Vec<&OrderAny>

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

source

pub fn orders_for_exec_spawn( &self, exec_spawn_id: &ClientOrderId, ) -> Vec<&OrderAny>

Returns references to all orders with the given 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 given 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 given 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 given exec_spawn_id.

source

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

Returns a reference to the position with the given position_id (if found).

source

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

source

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

source

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.

source

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.

source

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.

source

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

Returns whether a position with the given position_id exists.

source

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

Returns whether a position with the given position_id is open.

source

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

Returns whether a position with the given position_id is closed.

source

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.

source

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.

source

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.

source

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

source

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

source

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

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

source

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

source

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

Gets all quote ticks for the given instrument_id.

source

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

Gets all trade ticks for the given instrument_id.

source

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

Gets all bars for the given bar_type.

source

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

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

source

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

Gets a reference to the latest quote tick for the given instrument_id.

source

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

Gets a refernece to the latest trade tick for the given instrument_id.

source

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

Gets a reference to the latest bar for the given bar_type.

source

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

Gets the order book update count for the given instrument_id.

source

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

Gets the quote tick count for the given instrument_id.

source

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

Gets the trade tick count for the given instrument_id.

source

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

Gets the bar count for the given instrument_id.

source

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

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

source

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

Returns whether the cache contains quote ticks for the given instrument_id.

source

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

Returns whether the cache contains trade ticks for the given instrument_id.

source

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

Returns whether the cache contains bars for the given bar_type.

source

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

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

source

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

Returns references to all instrument IDs for the given venue.

source

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

Returns references to all instruments for the given venue.

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 given 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<&AccountAny>

Returns a reference to the account for the given account_id (if found).

source

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

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

source

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

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

source

pub fn accounts(&self, account_id: &AccountId) -> Vec<&AccountAny>

Returns references to all accounts for the given account_id.

Trait Implementations§

source§

impl Default for Cache

source§

fn default() -> Self

Creates a new default Cache instance.

source§

impl Send for Cache

source§

impl Sync for Cache

Auto Trait Implementations§

§

impl Freeze for Cache

§

impl !RefUnwindSafe for Cache

§

impl Unpin 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.

§

impl<T> Instrument for T

§

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

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

fn in_current_span(self) -> Instrumented<Self>

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

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> IntoEither for T

source§

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

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

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

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

source§

type Error = Infallible

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

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

Performs the conversion.
source§

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

source§

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

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

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

Performs the conversion.
§

impl<T> WithSubscriber for T

§

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

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> Ungil for T
where T: Send,