Cache
The cache subpackage provides common caching infrastructure.
A running Nautilus system generally uses a single centralized cache which can be accessed by many components.
class Cache
Bases: CacheFacade
Cache(CacheDatabaseFacade database: CacheDatabaseFacade | None = None, config: CacheConfig | None = None) -> None Provides a common object cache for market and execution related data.
- Parameters:
- database (CacheDatabaseFacade , optional) – The database adapter for the cache. If
None
then will bypass persistence. - config (CacheConfig , optional) – The cache configuration.
- database (CacheDatabaseFacade , optional) – The database adapter for the cache. If
- Raises: TypeError – If config is not of type CacheConfig.
account(self, AccountId account_id) → Account
Return the account matching the given ID (if found).
- Parameters: account_id (AccountId) – The account ID.
- Return type:
Account or
None
account_for_venue(self, Venue venue) → Account
Return the account matching the given client ID (if found).
- Parameters: venue (Venue) – The venue for the account.
- Return type:
Account or
None
account_id(self, Venue venue) → AccountId
Return the account ID for the given venue (if found).
- Parameters: venue (Venue) – The venue for the account ID.
- Return type:
AccountId or
None
accounts(self) → list
Return all accounts in the cache.
- Return type: list[Account]
actor_ids(self) → set
Return all actor IDs.
- Return type: set[ComponentId]
add(self, str key, bytes value) → void
Add the given general object value to the cache.
The cache is agnostic to what the object actually is (and how it may be serialized), offering maximum flexibility.
- Parameters:
- key (str) – The cache key for the object.
- value (bytes) – The object value to write.
add_account(self, Account account) → void
Add the given account to the cache.
- Parameters: account (Account) – The account to add.
- Raises: ValueError – If account_id is already contained in the cache.
add_bar(self, Bar bar) → void
Add the given bar to the cache.
- Parameters: bar (Bar) – The bar to add.
add_bars(self, list bars) → void
Add the given bars to the cache.
- Parameters: bars (list [Bar ]) – The bars to add.
add_currency(self, Currency currency) → void
Add the given currency to the cache.
- Parameters: currency (Currency) – The currency to add.
add_greeks(self, greeks) → void
Add greeks to the cache.
- Parameters: greeks (GreeksData) – The greeks to add.
add_index_price(self, IndexPriceUpdate index_price) → void
Add the given index price update to the cache.
- Parameters: index_price (IndexPriceUpdate) – The index price update to add.
add_instrument(self, Instrument instrument) → void
Add the given instrument to the cache.
- Parameters: instrument (Instrument) – The instrument to add.
add_mark_price(self, MarkPriceUpdate mark_price) → void
Add the given mark price update to the cache.
- Parameters: mark_price (MarkPriceUpdate) – The mark price update to add.
add_order(self, Order order, PositionId position_id=None, ClientId client_id=None, bool overwrite=False) → void
Add the given order to the cache indexed with the given position ID.
- Parameters:
- order (Order) – The order to add.
- position_id (PositionId , optional) – The position ID to index for the order.
- client_id (ClientId , optional) – The execution client ID for order routing.
- overwrite (bool , default False) – If the added order should ‘overwrite’ 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.
- Raises: ValueError – If order.client_order_id is already contained in the cache.