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