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).
If unique_venue is set, it will be used instead of the provided venue.
- 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_funding_rate(self, FundingRateUpdate funding_rate) → void
Add the given funding rate update to the cache.
- Parameters: funding_rate (FundingRateUpdate) – The funding rate update to add.