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:
CacheFacadeCache(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
Nonethen will bypass persistence.config (CacheConfig, optional) – The cache configuration.
- 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=None, AccountId account_id=None) Account¶
Return the account matching the given venue or account ID (if found).
- 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.
- 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.
Will also add the instrument’s currencies (base, quote, settlement) 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.
- add_order_book(self, OrderBook order_book) void¶
Add the given order book to the cache.
- Parameters:
order_book (OrderBook) – The order book to add.
- add_order_list(self, OrderList order_list) void¶
Add the given order list to the cache.
- Parameters:
order_list (OrderList) – The order_list to add.
- Raises:
ValueError – If order_list.id is already contained in the cache.
- add_own_order_book(self, own_order_book) void¶
Add the given own order book to the cache.
- Parameters:
own_order_book (nautilus_pyo3.OwnOrderBook) – The own order book to add.
- add_position(self, Position position, OmsType oms_type) void¶
Add the given position to the cache.
- Parameters:
position (Position) – The position to add.
oms_type (OmsType) – The order management system type for the position.
- Raises:
ValueError – If oms_type is
HEDGINGand a virtual position.id is already contained in the cache.
- add_position_id(self, PositionId position_id, Venue venue, ClientOrderId client_order_id, StrategyId strategy_id) void¶
Index the given position ID with the other given IDs.
- Parameters:
position_id (PositionId) – The position ID to index.
venue (Venue) – The venue ID to index with the position ID.
client_order_id (ClientOrderId) – The client order ID to index with the position ID.
strategy_id (StrategyId) – The strategy ID to index with the position ID.
- add_quote_tick(self, QuoteTick tick) void¶
Add the given quote tick to the cache.
- Parameters:
tick (QuoteTick) – The tick to add.
- add_quote_ticks(self, list ticks) void¶
Add the given quotes to the cache.
- Parameters:
ticks (list[QuoteTick]) – The ticks to add.
- add_synthetic(self, SyntheticInstrument synthetic) void¶
Add the given synthetic instrument to the cache.
- Parameters:
synthetic (SyntheticInstrument) – The synthetic instrument to add.
- add_trade_tick(self, TradeTick tick) void¶
Add the given trade tick to the cache.
- Parameters:
tick (TradeTick) – The tick to add.
- add_trade_ticks(self, list ticks) void¶
Add the given trades to the cache.
- Parameters:
ticks (list[TradeTick]) – The ticks to add.
- add_venue_order_id(self, ClientOrderId client_order_id, VenueOrderId venue_order_id, bool overwrite=False) void¶
Index the given client order ID with the given venue order ID.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to index.
venue_order_id (VenueOrderId) – The venue order ID to index.
overwrite (bool, default False) – If the venue order ID will ‘overwrite’ any existing indexing and replace it in the cache. This is currently used for updated orders where the venue order ID may change.
- Raises:
ValueError – If overwrite is False and the client_order_id is already indexed with a different venue_order_id.
- add_yield_curve(self, yield_curve) void¶
Add a yield curve to the cache.
- Parameters:
yield_curve (YieldCurveData) – The yield curve to add.
- audit_own_order_books(self) void¶
Audit all own order books against open and inflight order indexes.
Ensures closed orders are removed from own order books. This includes both orders tracked in _index_orders_open (ACCEPTED, TRIGGERED, PENDING_*, PARTIALLY_FILLED) and _index_orders_inflight (INITIALIZED, SUBMITTED) to prevent false positives during venue latency windows.
Logs all failures as errors.
- bar(self, BarType bar_type, int index=0) Bar¶
Return the bar for the given bar type at the given index (if found).
Last bar if no index specified.
- Parameters:
bar_type (BarType) – The bar type to get.
index (int, optional) – The index for the bar to get.
- Returns:
If no bars or no bar at index then returns
None.- Return type:
Bar or
None
Notes
Reverse indexed (most recent bar at index 0).
- bar_capacity¶
The caches bar capacity.
- Returns:
int
- bar_count(self, BarType bar_type) int¶
The count of bars for the given bar type.
- Parameters:
bar_type (BarType) – The bar type to count.
- Return type:
int
- bar_types(self, InstrumentId instrument_id=None, price_type=None, aggregation_source=None) list¶
Return all bar types with the given query filters.
If a filter parameter is
None, then no filtering occurs for that parameter.- Parameters:
instrument_id (InstrumentId, optional) – The instrument ID query filter.
price_type (PriceType, optional) – The price type query filter.
aggregation_source (AggregationSource, optional) – The aggregation source query filter.
- Return type:
list[BarType]
- bars(self, BarType bar_type) list¶
Return bars for the given bar type.
- book_update_count(self, InstrumentId instrument_id) int¶
The count of order book updates for the given instrument ID.
Will return zero if there is no book for the instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the book.
- Return type:
int
- build_index(self) void¶
Build the cache index from objects currently held in memory.
- cache_accounts(self) void¶
Clear the current accounts cache and load accounts from the cache database.
- cache_all(self) void¶
Clears and loads the currencies, instruments, synthetics, accounts, orders, and positions. from the cache database.
- cache_currencies(self) void¶
Clear the current currencies cache and load currencies from the cache database.
- cache_general(self) void¶
Clear the current general cache and load the general objects from the cache database.
- cache_instruments(self) void¶
Clear the current instruments cache and load instruments from the cache database.
- cache_order_lists(self) void¶
Clear the current order lists cache and load order lists using cached orders.
- cache_orders(self) void¶
Clear the current orders cache and load orders from the cache database.
- cache_positions(self) void¶
Clear the current positions cache and load positions from the cache database.
- cache_synthetics(self) void¶
Clear the current synthetic instruments cache and load synthetic instruments from the cache database.
- check_integrity(self) bool¶
Check 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.
- Returns:
True if checks pass, else False.
- Return type:
bool
- check_residuals(self) bool¶
Check for any residual open state and log warnings if any are found.
‘Open state’ is considered to be open orders and open positions.
- Returns:
True if residuals exist, else False.
- Return type:
bool
- clear_index(self) void¶
- clear_mark_xrate(self, Currency from_currency, Currency to_currency) void¶
Clear the exchange rate based on mark price.
- clear_mark_xrates(self) void¶
Clear the exchange rates based on mark price.
- client_id(self, ClientOrderId client_order_id) ClientId¶
Return the specific execution client ID matching the given client order ID (if found).
- Return type:
ClientId or
None
- client_order_id(self, VenueOrderId venue_order_id) ClientOrderId¶
Return the client order ID matching the given venue order ID (if found).
- Parameters:
venue_order_id (VenueOrderId) – The venue assigned order ID.
- Return type:
ClientOrderId or
None
- client_order_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all client order IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[ClientOrderId]
- client_order_ids_closed(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all closed client order IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[ClientOrderId]
- client_order_ids_emulated(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all emulated client order IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[ClientOrderId]
- client_order_ids_inflight(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all in-flight client order IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[ClientOrderId]
- client_order_ids_open(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all open client order IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[ClientOrderId]
- delete_actor(self, Actor actor) void¶
Delete the given actor from the cache.
- Parameters:
actor (Actor) – The actor to deregister.
- Raises:
ValueError – If actor is not contained in the actors index.
- delete_strategy(self, Strategy strategy) void¶
Delete the given strategy from the cache.
- Parameters:
strategy (Strategy) – The strategy to deregister.
- Raises:
ValueError – If strategy is not contained in the strategies index.
- dispose(self) void¶
Dispose of the cache which will close any underlying database adapter.
- exec_algorithm_ids(self) set¶
Return all execution algorithm IDs.
- Return type:
set[ExecAlgorithmId]
- exec_spawn_total_filled_qty(self, ClientOrderId exec_spawn_id, bool active_only=False) Quantity¶
Return the total filled quantity for the given execution spawn ID (if found).
If no execution spawn ID matches then returns
None.- Parameters:
exec_spawn_id (ClientOrderId) – The execution algorithm spawning primary (original) client order ID.
active_only (bool, default False) – The flag to filter for active execution spawn orders only.
- Return type:
Quantity or
None
Notes
An “active” order is defined as one which is not closed.
- exec_spawn_total_leaves_qty(self, ClientOrderId exec_spawn_id, bool active_only=False) Quantity¶
Return the total leaves quantity for the given execution spawn ID (if found).
If no execution spawn ID matches then returns
None.- Parameters:
exec_spawn_id (ClientOrderId) – The execution algorithm spawning primary (original) client order ID.
active_only (bool, default False) – The flag to filter for active execution spawn orders only.
- Return type:
Quantity or
None
Notes
An “active” order is defined as one which is not closed.
- exec_spawn_total_quantity(self, ClientOrderId exec_spawn_id, bool active_only=False) Quantity¶
Return the total quantity for the given execution spawn ID (if found).
If no execution spawn ID matches then returns
None.- Parameters:
exec_spawn_id (ClientOrderId) – The execution algorithm spawning primary (original) client order ID.
active_only (bool, default False) – The flag to filter for active execution spawn orders only.
- Return type:
Quantity or
None
Notes
An “active” order is defined as one which is not closed.
- flush_db(self) void¶
Flush the caches database which permanently removes all persisted data.
Warning
Permanent data loss.
- force_remove_from_own_order_book(self, ClientOrderId client_order_id) void¶
Force removal of an order from own order books and clean up all indexes.
This method is used when order.apply() fails and we need to ensure terminal orders are properly cleaned up from own books and all relevant indexes. Replicates the index cleanup that update_order performs for closed orders.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to remove.
- funding_rate(self, InstrumentId instrument_id, int index=0) FundingRateUpdate¶
Return the funding rate for the given instrument ID at the given index (if found).
Last funding rate if no index specified.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the funding rate to get.
- Returns:
If no funding rates or no funding rate at the index then returns
None.- Return type:
FundingRateUpdate or
None
Notes
Reverse indexed (most recent index price at index 0).
- funding_rate_count(self, InstrumentId instrument_id) int¶
The count of funding rates for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the index prices.
- Return type:
int
- funding_rates(self, InstrumentId instrument_id) list¶
Return funding rates for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the mark prices to get.
- Return type:
list[FundingRateUpdate]
- get(self, str key) bytes¶
Return the general object for the given key.
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.
- Return type:
bytes or
None
- get_mark_xrate(self, Currency from_currency, Currency to_currency)¶
Return the exchange rate based on mark price.
Will return
Noneif an exchange rate has not been set.
- get_xrate(self, Venue venue, Currency from_currency, Currency to_currency, PriceType price_type=PriceType.MID)¶
Return the calculated exchange rate.
If the exchange rate cannot be calculated then returns
None.- Parameters:
- Return type:
float or
None- Raises:
ValueError – If price_type is
LAST.
- greeks(self, InstrumentId instrument_id)¶
Return the latest cached greeks for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID to get the greeks for.
- Returns:
The greeks for the given instrument ID.
- Return type:
GreeksData
- has_backing¶
If the cache has a database backing.
- Returns:
bool
- has_bars(self, BarType bar_type) bool¶
Return a value indicating whether the cache has bars for the given bar type.
- Parameters:
bar_type (BarType) – The bar type for the bars.
- Return type:
bool
- has_funding_rates(self, InstrumentId instrument_id) bool¶
Return a value indicating whether the cache has funding rates for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the funding rates.
- Return type:
bool
- has_index_prices(self, InstrumentId instrument_id) bool¶
Return a value indicating whether the cache has index prices for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the index prices.
- Return type:
bool
- has_mark_prices(self, InstrumentId instrument_id) bool¶
Return a value indicating whether the cache has mark prices for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the mark prices.
- Return type:
bool
- has_order_book(self, InstrumentId instrument_id) bool¶
Return a value indicating whether the cache has an order book snapshot for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the order book snapshot.
- Return type:
bool
- has_quote_ticks(self, InstrumentId instrument_id) bool¶
Return a value indicating whether the cache has quotes for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the ticks.
- Return type:
bool
- has_trade_ticks(self, InstrumentId instrument_id) bool¶
Return a value indicating whether the cache has trades for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the ticks.
- Return type:
bool
- heartbeat(self, datetime timestamp) void¶
Add a heartbeat at the given timestamp.
- Parameters:
timestamp (datetime) – The timestamp for the heartbeat.
- index_price(self, InstrumentId instrument_id, int index=0) IndexPriceUpdate¶
Return the index price for the given instrument ID at the given index (if found).
Last index price if no index specified.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the index price to get.
index (int, optional) – The index for the index price to get.
- Returns:
If no index prices or no index price at index then returns
None.- Return type:
IndexPriceUpdate or
None
Notes
Reverse indexed (most recent index price at index 0).
- index_price_count(self, InstrumentId instrument_id) int¶
The count of index prices for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the index prices.
- Return type:
int
- index_prices(self, InstrumentId instrument_id) list¶
Return index prices for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the mark prices to get.
- Return type:
list[IndexPriceUpdate]
- instrument(self, InstrumentId instrument_id) Instrument¶
Return the instrument corresponding to the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID of the instrument to return.
- Return type:
Instrument or
None
- instrument_ids(self, Venue venue=None) list¶
Return all instrument IDs held by the cache.
- Parameters:
venue (Venue, optional) – The venue filter for the query.
- Return type:
list[InstrumentId]
- instruments(self, Venue venue=None, str underlying=None) list¶
Return all instruments held by the cache.
- Parameters:
venue (Venue, optional) – The venue filter for the query.
underlying (str, optional) – The underlying root symbol for the query.
- Return type:
list[Instrument]
- is_order_closed(self, ClientOrderId client_order_id) bool¶
Return a value indicating whether an order with the given ID is closed.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to check.
- Return type:
bool
- is_order_emulated(self, ClientOrderId client_order_id) bool¶
Return a value indicating whether an order with the given ID is emulated.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to check.
- Return type:
bool
- is_order_inflight(self, ClientOrderId client_order_id) bool¶
Return a value indicating whether an order with the given ID is in-flight.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to check.
- Return type:
bool
- is_order_open(self, ClientOrderId client_order_id) bool¶
Return a value indicating whether an order with the given ID is open.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to check.
- Return type:
bool
- is_order_pending_cancel_local(self, ClientOrderId client_order_id) bool¶
Return a value indicating whether an order with the given ID is pending cancel locally.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to check.
- Return type:
bool
- is_position_closed(self, PositionId position_id) bool¶
Return a value indicating whether a position with the given ID exists and is closed.
- Parameters:
position_id (PositionId) – The position ID.
- Return type:
bool
- is_position_open(self, PositionId position_id) bool¶
Return a value indicating whether a position with the given ID exists and is open.
- Parameters:
position_id (PositionId) – The position ID.
- Return type:
bool
- load_account(self, AccountId account_id) Account¶
Load the account associated with the given account_id (if found).
- Parameters:
account_id (AccountId) – The account ID to load.
- Return type:
Account or
None
- load_actor(self, Actor actor) void¶
Load the state dictionary into the given actor.
- Parameters:
actor (Actor) – The actor to load.
- load_instrument(self, InstrumentId instrument_id) Instrument¶
Load the instrument associated with the given instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The instrument ID to load.
- Return type:
Instrument or
None
- load_order(self, ClientOrderId client_order_id) Order¶
Load the order associated with the given ID (if found).
- Parameters:
client_order_id (ClientOrderId) – The client order ID to load.
- Return type:
Order or
None
- load_position(self, PositionId position_id) Position¶
Load the position associated with the given ID (if found).
- Parameters:
position_id (PositionId) – The position ID to load.
- Return type:
Position or
None
- load_strategy(self, Strategy strategy) void¶
Load the state dictionary into the given strategy.
- Parameters:
strategy (Strategy) – The strategy to load.
- load_synthetic(self, InstrumentId instrument_id) SyntheticInstrument¶
Load the synthetic instrument associated with the given instrument_id (if found).
- Parameters:
instrument_id (InstrumentId) – The synthetic instrument ID to load.
- Return type:
SyntheticInstrument or
None- Raises:
ValueError – If instrument_id is not a synthetic instrument ID.
- mark_price(self, InstrumentId instrument_id, int index=0) MarkPriceUpdate¶
Return the mark price for the given instrument ID at the given index (if found).
Last mark price if no index specified.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the mark price to get.
index (int, optional) – The index for the mark price to get.
- Returns:
If no mark prices or no mark price at index then returns
None.- Return type:
MarkPriceUpdate or
None
Notes
Reverse indexed (most recent mark price at index 0).
- mark_price_count(self, InstrumentId instrument_id) int¶
The count of mark prices for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the mark prices.
- Return type:
int
- mark_prices(self, InstrumentId instrument_id) list¶
Return mark prices for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the mark prices to get.
- Return type:
list[MarkPriceUpdate]
- order(self, ClientOrderId client_order_id) Order¶
Return the order matching the given client order ID (if found).
- Return type:
Order or
None
- order_book(self, InstrumentId instrument_id) OrderBook¶
Return the order book for the given instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the order book to get.
- Returns:
If book not found for the instrument ID then returns
None.- Return type:
OrderBook or
None
- order_exists(self, ClientOrderId client_order_id) bool¶
Return a value indicating whether an order with the given ID exists.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to check.
- Return type:
bool
- order_list(self, OrderListId order_list_id) OrderList¶
Return the order list matching the given order list ID (if found).
- Return type:
OrderList or
None
- order_list_exists(self, OrderListId order_list_id) bool¶
Return a value indicating whether an order list with the given ID exists.
- Parameters:
order_list_id (OrderListId) – The order list ID to check.
- Return type:
bool
- order_list_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all order list IDs.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[OrderListId]
- order_lists(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) list¶
Return all order lists matching the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[OrderList]
- orders(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Return all orders matching the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Order]
- orders_closed(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Return all closed orders with the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Order]
- orders_closed_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Return the count of closed orders with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- orders_emulated(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Return all emulated orders with the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Order]
- orders_emulated_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Return the count of emulated orders with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- orders_for_exec_algorithm(self, ExecAlgorithmId exec_algorithm_id, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Return all execution algorithm orders for the given query filters.
- Parameters:
exec_algorithm_id (ExecAlgorithmId) – The execution algorithm ID.
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Order]
- orders_for_exec_spawn(self, ClientOrderId exec_spawn_id) list¶
Return all orders for the given execution spawn ID (if found).
Will also include the primary (original) order.
- Parameters:
exec_spawn_id (ClientOrderId) – The execution algorithm spawning primary (original) client order ID.
- Return type:
list[Order]
- orders_for_position(self, PositionId position_id) list¶
Return all orders for the given position ID.
- Parameters:
position_id (PositionId) – The position ID for the orders.
- Return type:
list[Order]
- orders_inflight(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Return all in-flight orders with the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Order]
- orders_inflight_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Return the count of in-flight orders with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- orders_open(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Return all open orders with the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Order]
- orders_open_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Return the count of open orders with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- orders_total_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Return the total count of orders with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- own_ask_orders(self, InstrumentId instrument_id, set status=None, uint64_t accepted_buffer_ns=0, uint64_t ts_now=0) dict¶
Return own ask orders for the given instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the own orders to get. Note this is the standard Cython InstrumentId.
status (set[OrderStatus], optional) – The order status to filter for. Empty price levels after filtering are excluded from the result.
accepted_buffer_ns (uint64_t, optional) – The minimum time in nanoseconds that must have elapsed since the order was accepted. Orders accepted less than this time ago will be filtered out.
ts_now (uint64_t, optional) – The current time in nanoseconds. Required if accepted_buffer_ns > 0.
- Returns:
If own book not found for the instrument ID then returns
None.- Return type:
dict[Decimal, list[Order]] or
None- Raises:
ValueError – If accepted_buffer_ns > 0 and ts_now == 0.
- own_bid_orders(self, InstrumentId instrument_id, set status=None, uint64_t accepted_buffer_ns=0, uint64_t ts_now=0) dict¶
Return own bid orders for the given instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the own orders to get. Note this is the standard Cython InstrumentId.
status (set[OrderStatus], optional) – The order status to filter for. Empty price levels after filtering are excluded from the result.
accepted_buffer_ns (uint64_t, optional) – The minimum time in nanoseconds that must have elapsed since the order was accepted. Orders accepted less than this time ago will be filtered out.
ts_now (uint64_t, optional) – The current time in nanoseconds. Required if accepted_buffer_ns > 0.
- Returns:
If own book not found for the instrument ID then returns
None.- Return type:
dict[Decimal, list[Order]] or
None- Raises:
ValueError – If accepted_buffer_ns > 0 and ts_now == 0.
- own_order_book(self, InstrumentId instrument_id)¶
Return the own order book for the given instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the own order book to get. Note this is the standard Cython InstrumentId.
- Returns:
If own book not found for the instrument ID then returns
None.- Return type:
nautilus_pyo3.OwnOrderBook or
None
- persist_account_events¶
If account state events are written to the backing database.
- Returns:
bool
- position(self, PositionId position_id) Position¶
Return the position associated with the given ID (if found).
- Parameters:
position_id (PositionId) – The position ID.
- Return type:
Position or
None
- position_closed_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all closed position IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[PositionId]
- position_exists(self, PositionId position_id) bool¶
Return a value indicating whether a position with the given ID exists.
- Parameters:
position_id (PositionId) – The position ID.
- Return type:
int
- position_for_order(self, ClientOrderId client_order_id) Position¶
Return the position associated with the given client order ID (if found).
- Parameters:
client_order_id (ClientOrderId) – The client order ID.
- Return type:
Position or
None
- position_id(self, ClientOrderId client_order_id) PositionId¶
Return the position ID associated with the given client order ID (if found).
- Parameters:
client_order_id (ClientOrderId) – The client order ID associated with the position.
- Return type:
PositionId or
None
- position_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all position IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[PositionId]
- position_open_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all open position IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[PositionId]
- position_snapshot_bytes(self, PositionId position_id) list¶
Return the raw pickled snapshot bytes for the given position ID.
- Parameters:
position_id (PositionId) – The position ID to get snapshot bytes for.
- Returns:
The list of pickled snapshot bytes, or empty list if no snapshots exist.
- Return type:
list[bytes]
- position_snapshot_ids(self, InstrumentId instrument_id=None, AccountId account_id=None) set¶
Return all position IDs for position snapshots with the given instrument filter.
- Parameters:
instrument_id (InstrumentId, optional) – The instrument ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[PositionId]
- position_snapshots(self, PositionId position_id=None, AccountId account_id=None) list¶
Return all position snapshots with the given optional identifier filter.
- Parameters:
position_id (PositionId, optional) – The position ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Position]
- positions(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, PositionSide side=PositionSide.NO_POSITION_SIDE, AccountId account_id=None) list¶
Return all positions with the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (PositionSide, default
NO_POSITION_SIDE(no filter)) – The position side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Position]
- positions_closed(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) list¶
Return all closed positions with the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Position]
- positions_closed_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) int¶
Return the count of closed positions with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- positions_open(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, PositionSide side=PositionSide.NO_POSITION_SIDE, AccountId account_id=None) list¶
Return all open positions with the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (PositionSide, default
NO_POSITION_SIDE(no filter)) – The position side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Position]
- positions_open_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, PositionSide side=PositionSide.NO_POSITION_SIDE, AccountId account_id=None) int¶
Return the count of open positions with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (PositionSide, default
NO_POSITION_SIDE(no filter)) – The position side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- positions_total_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, PositionSide side=PositionSide.NO_POSITION_SIDE, AccountId account_id=None) int¶
Return the total count of positions with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (PositionSide, default
NO_POSITION_SIDE(no filter)) – The position side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- price(self, InstrumentId instrument_id, PriceType price_type) Price¶
Return the price for the given instrument ID and price type.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the price.
price_type (PriceType) – The price type for the query.
- Return type:
Price or
None
- prices(self, PriceType price_type) dict¶
Return a map of latest prices per instrument ID for the given price type.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the price.
price_type (PriceType) – The price type for the query.
- Returns:
Includes key value pairs for prices which exist.
- Return type:
dict[InstrumentId, Price]
- purge_account_events(self, uint64_t ts_now, uint64_t lookback_secs=0, bool purge_from_database=False) void¶
Purge all account state events which are outside the lookback window.
- Parameters:
ts_now (uint64_t) – The current UNIX timestamp (nanoseconds).
lookback_secs (uint64_t, default 0) – The purge lookback window (seconds) from when the account state event occurred. Only events which are outside the lookback window will be purged. A value of 0 means purge all account state events.
purge_from_database (bool, default False) – If purging operations will also delete from the backing database, in addition to the cache.
- purge_closed_orders(self, uint64_t ts_now, uint64_t buffer_secs=0, bool purge_from_database=False) void¶
Purge all closed orders from the cache.
- Parameters:
ts_now (uint64_t) – The current UNIX timestamp (nanoseconds).
buffer_secs (uint64_t, default 0) – The purge buffer (seconds) from when the order was closed. 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.
purge_from_database (bool, default False) – If purging operations will also delete from the backing database, in addition to the cache.
- purge_closed_positions(self, uint64_t ts_now, uint64_t buffer_secs=0, bool purge_from_database=False) void¶
Purge all closed positions from the cache.
- Parameters:
ts_now (uint64_t) – The current UNIX timestamp (nanoseconds).
buffer_secs (uint64_t, default 0) – The purge buffer (seconds) from when the position was closed. Only positions that have been closed for at least this amount of time will be purged. A value of 0 means purge all closed positions regardless of when they were closed.
purge_from_database (bool, default False) – If purging operations will also delete from the backing database, in addition to the cache.
- purge_order(self, ClientOrderId client_order_id, bool purge_from_database=False) void¶
Purge the order for the given client order ID from the cache (if found).
For safety, an order is prevented from being purged if it’s open.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to purge.
purge_from_database (bool, default False) – If purging operations will also delete from the backing database, in addition to the cache.
- purge_position(self, PositionId position_id, bool purge_from_database=False) void¶
Purge the position for the given position ID from the cache (if found).
For safety, a position is prevented from being purged if it’s open.
- Parameters:
position_id (PositionId) – The position ID to purge.
purge_from_database (bool, default False) – If purging operations will also delete from the backing database, in addition to the cache.
- quote_tick(self, InstrumentId instrument_id, int index=0) QuoteTick¶
Return the quote tick for the given instrument ID at the given index (if found).
Last quote tick if no index specified.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the tick to get.
index (int, optional) – The index for the tick to get.
- Returns:
If no ticks or no tick at index then returns
None.- Return type:
QuoteTick or
None
Notes
Reverse indexed (most recent tick at index 0).
- quote_tick_count(self, InstrumentId instrument_id) int¶
The count of quotes for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the ticks.
- Return type:
int
- quote_ticks(self, InstrumentId instrument_id) list¶
Return the quotes for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the ticks to get.
- Return type:
list[QuoteTick]
- reset(self) void¶
Reset the cache.
All stateful fields are reset to their initial value.
- set_account_id_for_venue(self, Venue venue, AccountId account_id) void¶
Set the account_id for a venue in the cache index.
This allows explicitly setting the mapping between a venue and account_id, which may differ from the account_id’s issuer.
- set_mark_xrate(self, Currency from_currency, Currency to_currency, double xrate) void¶
Set the exchange rate based on mark price.
Will also set the inverse xrate automatically.
- set_specific_venue(self, Venue venue) void¶
Set a specific venue for the cache to use for account lookups.
Primarily for Interactive Brokers, a multi-venue brokerage where account updates are not tied to a single venue.
- Parameters:
venue (Venue) – The specific venue to set.
- snapshot_order_state(self, Order order) void¶
Snapshot the state dictionary for the given order.
This method will persist to the backing cache database.
- Parameters:
order (Order) – The order to snapshot the state for.
- snapshot_position(self, Position position) void¶
Snapshot the given position in its current state.
The position ID will be appended with a UUID v4 string.
- Parameters:
position (Position) – The position to snapshot.
- snapshot_position_state(self, Position position, uint64_t ts_snapshot, Money unrealized_pnl=None, bool open_only=True) void¶
Snapshot the state dictionary for the given position.
This method will persist to the backing cache database.
- Parameters:
position (Position) – The position to snapshot the state for.
ts_snapshot (uint64_t) – UNIX timestamp (nanoseconds) when the snapshot was taken.
unrealized_pnl (Money, optional) – The current unrealized PnL for the position.
open_only (bool, default True) – If only open positions should be snapshot, this flag helps to avoid race conditions where a position is snapshot when no longer open.
- strategy_id_for_order(self, ClientOrderId client_order_id) StrategyId¶
Return the strategy ID associated with the given ID (if found).
- Parameters:
client_order_id (ClientOrderId) – The client order ID associated with the strategy.
- Return type:
StrategyId or
None
- strategy_id_for_position(self, PositionId position_id) StrategyId¶
Return the strategy ID associated with the given ID (if found).
- Parameters:
position_id (PositionId) – The position ID associated with the strategy.
- Return type:
StrategyId or
None
- strategy_ids(self) set¶
Return all strategy IDs.
- Return type:
set[StrategyId]
- synthetic(self, InstrumentId instrument_id) SyntheticInstrument¶
Return the synthetic instrument corresponding to the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID of the synthetic instrument to return.
- Return type:
SyntheticInstrument or
None- Raises:
ValueError – If instrument_id is not a synthetic instrument ID.
- synthetic_ids(self) list¶
Return all synthetic instrument IDs held by the cache.
- Return type:
list[InstrumentId]
- synthetics(self) list¶
Return all synthetic instruments held by the cache.
- Return type:
list[SyntheticInstrument]
- tick_capacity¶
The caches tick capacity.
- Returns:
int
- trade_tick(self, InstrumentId instrument_id, int index=0) TradeTick¶
Return the trade tick for the given instrument ID at the given index (if found).
Last trade tick if no index specified.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the tick to get.
index (int, optional) – The index for the tick to get.
- Returns:
If no ticks or no tick at index then returns
None.- Return type:
TradeTick or
None
Notes
Reverse indexed (most recent tick at index 0).
- trade_tick_count(self, InstrumentId instrument_id) int¶
The count of trades for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the ticks.
- Return type:
int
- trade_ticks(self, InstrumentId instrument_id) list¶
Return trades for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the ticks to get.
- Return type:
list[TradeTick]
- update_account(self, Account account) void¶
Update the given account in the cache.
- Parameters:
account (The account to update (from last event).)
- update_actor(self, Actor actor) void¶
Update the given actor state in the cache.
- Parameters:
actor (Actor) – The actor to update.
- update_order(self, Order order) void¶
Update the given order in the cache.
- Parameters:
order (Order) – The order to update (from last event).
- update_order_pending_cancel_local(self, Order order) void¶
Update the given order as pending cancel locally.
- Parameters:
order (Order) – The order to update.
- update_own_order_book(self, Order order) void¶
Update the own order book for the given order.
Orders without prices (MARKET, etc.) are skipped as they cannot be represented in own books.
- Parameters:
order (Order) – The order to update.
- update_position(self, Position position) void¶
Update the given position in the cache.
- Parameters:
position (Position) – The position to update (from last event).
- update_strategy(self, Strategy strategy) void¶
Update the given strategy state in the cache.
- Parameters:
strategy (Strategy) – The strategy to update.
- venue_order_id(self, ClientOrderId client_order_id) VenueOrderId¶
Return the order ID matching the given client order ID (if found).
- Return type:
VenueOrderId or
None
- yield_curve(self, str curve_name)¶
Return the latest cached yield curve for the given curve name.
- Parameters:
curve_name (str) – The name of the yield curve to get.
- Returns:
The interest rate curve for the given currency.
- Return type:
YieldCurveData
- class CacheDatabaseAdapter¶
Bases:
CacheDatabaseFacadeCacheDatabaseAdapter(TraderId trader_id, UUID4 instance_id, Serializer serializer, config: CacheConfig | None = None) -> None
Provides a generic cache database adapter.
- Parameters:
trader_id (TraderId) – The trader ID for the adapter.
instance_id (UUID4) – The instance ID for the adapter.
serializer (Serializer) – The serializer for database operations.
config (CacheConfig, optional) – The configuration for the instance.
- Raises:
TypeError – If config is not of type CacheConfig.
Warning
Redis can only accurately store int64 types to 17 digits of precision. Therefore nanosecond timestamp int64’s with 19 digits will lose 2 digits of precision when persisted. One way to solve this is to ensure the serializer converts timestamp int64’s to strings on the way into Redis, and converts timestamp strings back to int64’s on the way out. One way to achieve this is to set the timestamps_as_str flag to true for the MsgSpecSerializer, as per the default implementations for both TradingNode and BacktestEngine.
- add(self, str key, bytes value) void¶
Add the given general object value to the database.
- Parameters:
key (str) – The key to write to.
value (bytes) – The object value.
- add_account(self, Account account) void¶
Add the given account to the database.
- Parameters:
account (Account) – The account to add.
- add_currency(self, Currency currency) void¶
Add the given currency to the database.
- Parameters:
currency (Currency) – The currency to add.
- add_instrument(self, Instrument instrument) void¶
Add the given instrument to the database.
- Parameters:
instrument (Instrument) – The instrument to add.
- add_order(self, Order order, PositionId position_id=None, ClientId client_id=None) void¶
Add the given order to the database.
- Parameters:
order (Order) – The order to add.
position_id (PositionId, optional) – The position ID to associate with this order.
client_id (ClientId, optional) – The execution client ID to associate with this order.
- add_position(self, Position position) void¶
Add the given position to the database.
- Parameters:
position (Position) – The position to add.
- add_synthetic(self, SyntheticInstrument synthetic) void¶
Add the given synthetic instrument to the database.
- Parameters:
synthetic (SyntheticInstrument) – The synthetic instrument to add.
- close(self) void¶
Close the backing database adapter.
- delete_account_event(self, AccountId account_id, str event_id) void¶
Delete the given account event from the database.
- Parameters:
account_id (AccountId) – The account ID to delete events for.
event_id (str) – The event ID to delete.
- delete_actor(self, ComponentId component_id) void¶
Delete the given actor from the database.
- Parameters:
component_id (ComponentId) – The ID of the actor state dictionary to delete.
- delete_order(self, ClientOrderId client_order_id) void¶
Delete the given order from the database.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to delete.
- delete_position(self, PositionId position_id) void¶
Delete the given position from the database.
- Parameters:
position_id (PositionId) – The position ID to delete.
- delete_strategy(self, StrategyId strategy_id) void¶
Delete the given strategy from the database.
- Parameters:
strategy_id (StrategyId) – The ID of the strategy state dictionary to delete.
- flush(self) void¶
Flush the database which clears all data.
- heartbeat(self, datetime timestamp) void¶
Add a heartbeat at the given timestamp.
- Parameters:
timestamp (datetime) – The timestamp for the heartbeat.
- index_order_position(self, ClientOrderId client_order_id, PositionId position_id) void¶
Add an index entry for the given client_order_id to position_id.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to index.
position_id (PositionId) – The position ID to index.
- index_venue_order_id(self, ClientOrderId client_order_id, VenueOrderId venue_order_id) void¶
Add an index entry for the given venue_order_id to client_order_id.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to index.
venue_order_id (VenueOrderId) – The venue order ID to index.
- keys(self, str pattern='*') list¶
Return all keys in the database matching the given pattern.
- Parameters:
pattern (str, default '*') – The glob-style pattern to match against the keys in the database.
- Return type:
list[str]
- Raises:
ValueError – If pattern is not a valid string.
Warning
Using the default ‘*’ pattern string can have serious performance implications and can take a long time to execute if many keys exist in the database. This operation can lead to high memory and CPU usage, and should be used with caution, especially in production environments.
- load(self) dict¶
Load all general objects from the database using bulk loading for efficiency.
- Return type:
dict[str, bytes]
- load_account(self, AccountId account_id) Account¶
Load the account associated with the given account ID (if found).
- Parameters:
account_id (AccountId) – The account ID to load.
- Return type:
Account or
None
- load_accounts(self) dict¶
Load all accounts from the database.
- Return type:
dict[AccountId, Account]
- load_actor(self, ComponentId component_id) dict¶
Load the state for the given actor.
- Parameters:
component_id (ComponentId) – The ID of the actor state dictionary to load.
- Return type:
dict[str, Any]
- load_all(self) dict¶
Load all cache data from the database.
- Returns:
A dictionary containing all cache data organized by category.
- Return type:
dict[str, dict]
- load_currencies(self) dict¶
Load all currencies from the database using bulk loading for efficiency.
- Return type:
dict[str, Currency]
- load_currency(self, str code) Currency¶
Load the currency associated with the given currency code (if found).
- Parameters:
code (str) – The currency code to load.
- Return type:
Currency or
None
- load_index_order_client(self) dict¶
Load the order to execution client index from the database.
- Return type:
dict[ClientOrderId, ClientId]
- load_index_order_position(self) dict¶
Load the order to position index from the database.
- Return type:
dict[ClientOrderId, PositionId]
- load_instrument(self, InstrumentId instrument_id) Instrument¶
Load the instrument associated with the given instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The instrument ID to load.
- Return type:
Instrument or
None
- load_instruments(self) dict¶
Load all instruments from the database using bulk loading for efficiency.
- Return type:
dict[InstrumentId, Instrument]
- load_order(self, ClientOrderId client_order_id) Order¶
Load the order associated with the given client order ID (if found).
- Parameters:
client_order_id (ClientOrderId) – The client order ID to load.
- Return type:
Order or
None
- load_orders(self) dict¶
Load all orders from the database.
- Return type:
dict[ClientOrderId, Order]
- load_position(self, PositionId position_id) Position¶
Load the position associated with the given ID (if found).
- Parameters:
position_id (PositionId) – The position ID to load.
- Return type:
Position or
None
- load_positions(self) dict¶
Load all positions from the database.
- Return type:
dict[PositionId, Position]
- load_strategy(self, StrategyId strategy_id) dict¶
Load the state for the given strategy.
- Parameters:
strategy_id (StrategyId) – The ID of the strategy state dictionary to load.
- Return type:
dict[str, bytes]
- load_synthetic(self, InstrumentId instrument_id) SyntheticInstrument¶
Load the synthetic instrument associated with the given synthetic instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The synthetic instrument ID to load.
- Return type:
SyntheticInstrument or
None- Raises:
ValueError – If instrument_id is not for a synthetic instrument.
- load_synthetics(self) dict¶
Load all synthetic instruments from the database using bulk loading for efficiency.
- Return type:
dict[InstrumentId, SyntheticInstrument]
- snapshot_order_state(self, Order order) void¶
Snapshot the state of the given order.
- Parameters:
order (Order) – The order for the state snapshot.
- snapshot_position_state(self, Position position, uint64_t ts_snapshot, Money unrealized_pnl=None) void¶
Snapshot the state of the given position.
- update_account(self, Account account) void¶
Update the given account in the database.
- Parameters:
account (The account to update (from last event).)
- update_actor(self, Actor actor) void¶
Update the given actor state in the database.
- Parameters:
actor (Actor) – The actor to update.
- update_order(self, Order order) void¶
Update the given order in the database.
- Parameters:
order (Order) – The order to update (from last event).
- class Cache¶
Bases:
CacheFacadeCache(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
Nonethen will bypass persistence.config (CacheConfig, optional) – The cache configuration.
- 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=None, AccountId account_id=None) Account¶
Return the account matching the given venue or account ID (if found).
- 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.
- 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.
Will also add the instrument’s currencies (base, quote, settlement) 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.
- add_order_book(self, OrderBook order_book) void¶
Add the given order book to the cache.
- Parameters:
order_book (OrderBook) – The order book to add.
- add_order_list(self, OrderList order_list) void¶
Add the given order list to the cache.
- Parameters:
order_list (OrderList) – The order_list to add.
- Raises:
ValueError – If order_list.id is already contained in the cache.
- add_own_order_book(self, own_order_book) void¶
Add the given own order book to the cache.
- Parameters:
own_order_book (nautilus_pyo3.OwnOrderBook) – The own order book to add.
- add_position(self, Position position, OmsType oms_type) void¶
Add the given position to the cache.
- Parameters:
position (Position) – The position to add.
oms_type (OmsType) – The order management system type for the position.
- Raises:
ValueError – If oms_type is
HEDGINGand a virtual position.id is already contained in the cache.
- add_position_id(self, PositionId position_id, Venue venue, ClientOrderId client_order_id, StrategyId strategy_id) void¶
Index the given position ID with the other given IDs.
- Parameters:
position_id (PositionId) – The position ID to index.
venue (Venue) – The venue ID to index with the position ID.
client_order_id (ClientOrderId) – The client order ID to index with the position ID.
strategy_id (StrategyId) – The strategy ID to index with the position ID.
- add_quote_tick(self, QuoteTick tick) void¶
Add the given quote tick to the cache.
- Parameters:
tick (QuoteTick) – The tick to add.
- add_quote_ticks(self, list ticks) void¶
Add the given quotes to the cache.
- Parameters:
ticks (list[QuoteTick]) – The ticks to add.
- add_synthetic(self, SyntheticInstrument synthetic) void¶
Add the given synthetic instrument to the cache.
- Parameters:
synthetic (SyntheticInstrument) – The synthetic instrument to add.
- add_trade_tick(self, TradeTick tick) void¶
Add the given trade tick to the cache.
- Parameters:
tick (TradeTick) – The tick to add.
- add_trade_ticks(self, list ticks) void¶
Add the given trades to the cache.
- Parameters:
ticks (list[TradeTick]) – The ticks to add.
- add_venue_order_id(self, ClientOrderId client_order_id, VenueOrderId venue_order_id, bool overwrite=False) void¶
Index the given client order ID with the given venue order ID.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to index.
venue_order_id (VenueOrderId) – The venue order ID to index.
overwrite (bool, default False) – If the venue order ID will ‘overwrite’ any existing indexing and replace it in the cache. This is currently used for updated orders where the venue order ID may change.
- Raises:
ValueError – If overwrite is False and the client_order_id is already indexed with a different venue_order_id.
- add_yield_curve(self, yield_curve) void¶
Add a yield curve to the cache.
- Parameters:
yield_curve (YieldCurveData) – The yield curve to add.
- audit_own_order_books(self) void¶
Audit all own order books against open and inflight order indexes.
Ensures closed orders are removed from own order books. This includes both orders tracked in _index_orders_open (ACCEPTED, TRIGGERED, PENDING_*, PARTIALLY_FILLED) and _index_orders_inflight (INITIALIZED, SUBMITTED) to prevent false positives during venue latency windows.
Logs all failures as errors.
- bar(self, BarType bar_type, int index=0) Bar¶
Return the bar for the given bar type at the given index (if found).
Last bar if no index specified.
- Parameters:
bar_type (BarType) – The bar type to get.
index (int, optional) – The index for the bar to get.
- Returns:
If no bars or no bar at index then returns
None.- Return type:
Bar or
None
Notes
Reverse indexed (most recent bar at index 0).
- bar_capacity¶
The caches bar capacity.
- Returns:
int
- bar_count(self, BarType bar_type) int¶
The count of bars for the given bar type.
- Parameters:
bar_type (BarType) – The bar type to count.
- Return type:
int
- bar_types(self, InstrumentId instrument_id=None, price_type=None, aggregation_source=None) list¶
Return all bar types with the given query filters.
If a filter parameter is
None, then no filtering occurs for that parameter.- Parameters:
instrument_id (InstrumentId, optional) – The instrument ID query filter.
price_type (PriceType, optional) – The price type query filter.
aggregation_source (AggregationSource, optional) – The aggregation source query filter.
- Return type:
list[BarType]
- bars(self, BarType bar_type) list¶
Return bars for the given bar type.
- book_update_count(self, InstrumentId instrument_id) int¶
The count of order book updates for the given instrument ID.
Will return zero if there is no book for the instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the book.
- Return type:
int
- build_index(self) void¶
Build the cache index from objects currently held in memory.
- cache_accounts(self) void¶
Clear the current accounts cache and load accounts from the cache database.
- cache_all(self) void¶
Clears and loads the currencies, instruments, synthetics, accounts, orders, and positions. from the cache database.
- cache_currencies(self) void¶
Clear the current currencies cache and load currencies from the cache database.
- cache_general(self) void¶
Clear the current general cache and load the general objects from the cache database.
- cache_instruments(self) void¶
Clear the current instruments cache and load instruments from the cache database.
- cache_order_lists(self) void¶
Clear the current order lists cache and load order lists using cached orders.
- cache_orders(self) void¶
Clear the current orders cache and load orders from the cache database.
- cache_positions(self) void¶
Clear the current positions cache and load positions from the cache database.
- cache_synthetics(self) void¶
Clear the current synthetic instruments cache and load synthetic instruments from the cache database.
- check_integrity(self) bool¶
Check 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.
- Returns:
True if checks pass, else False.
- Return type:
bool
- check_residuals(self) bool¶
Check for any residual open state and log warnings if any are found.
‘Open state’ is considered to be open orders and open positions.
- Returns:
True if residuals exist, else False.
- Return type:
bool
- clear_index(self) void¶
- clear_mark_xrate(self, Currency from_currency, Currency to_currency) void¶
Clear the exchange rate based on mark price.
- clear_mark_xrates(self) void¶
Clear the exchange rates based on mark price.
- client_id(self, ClientOrderId client_order_id) ClientId¶
Return the specific execution client ID matching the given client order ID (if found).
- Return type:
ClientId or
None
- client_order_id(self, VenueOrderId venue_order_id) ClientOrderId¶
Return the client order ID matching the given venue order ID (if found).
- Parameters:
venue_order_id (VenueOrderId) – The venue assigned order ID.
- Return type:
ClientOrderId or
None
- client_order_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all client order IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[ClientOrderId]
- client_order_ids_closed(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all closed client order IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[ClientOrderId]
- client_order_ids_emulated(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all emulated client order IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[ClientOrderId]
- client_order_ids_inflight(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all in-flight client order IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[ClientOrderId]
- client_order_ids_open(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all open client order IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[ClientOrderId]
- delete_actor(self, Actor actor) void¶
Delete the given actor from the cache.
- Parameters:
actor (Actor) – The actor to deregister.
- Raises:
ValueError – If actor is not contained in the actors index.
- delete_strategy(self, Strategy strategy) void¶
Delete the given strategy from the cache.
- Parameters:
strategy (Strategy) – The strategy to deregister.
- Raises:
ValueError – If strategy is not contained in the strategies index.
- dispose(self) void¶
Dispose of the cache which will close any underlying database adapter.
- exec_algorithm_ids(self) set¶
Return all execution algorithm IDs.
- Return type:
set[ExecAlgorithmId]
- exec_spawn_total_filled_qty(self, ClientOrderId exec_spawn_id, bool active_only=False) Quantity¶
Return the total filled quantity for the given execution spawn ID (if found).
If no execution spawn ID matches then returns
None.- Parameters:
exec_spawn_id (ClientOrderId) – The execution algorithm spawning primary (original) client order ID.
active_only (bool, default False) – The flag to filter for active execution spawn orders only.
- Return type:
Quantity or
None
Notes
An “active” order is defined as one which is not closed.
- exec_spawn_total_leaves_qty(self, ClientOrderId exec_spawn_id, bool active_only=False) Quantity¶
Return the total leaves quantity for the given execution spawn ID (if found).
If no execution spawn ID matches then returns
None.- Parameters:
exec_spawn_id (ClientOrderId) – The execution algorithm spawning primary (original) client order ID.
active_only (bool, default False) – The flag to filter for active execution spawn orders only.
- Return type:
Quantity or
None
Notes
An “active” order is defined as one which is not closed.
- exec_spawn_total_quantity(self, ClientOrderId exec_spawn_id, bool active_only=False) Quantity¶
Return the total quantity for the given execution spawn ID (if found).
If no execution spawn ID matches then returns
None.- Parameters:
exec_spawn_id (ClientOrderId) – The execution algorithm spawning primary (original) client order ID.
active_only (bool, default False) – The flag to filter for active execution spawn orders only.
- Return type:
Quantity or
None
Notes
An “active” order is defined as one which is not closed.
- flush_db(self) void¶
Flush the caches database which permanently removes all persisted data.
Warning
Permanent data loss.
- force_remove_from_own_order_book(self, ClientOrderId client_order_id) void¶
Force removal of an order from own order books and clean up all indexes.
This method is used when order.apply() fails and we need to ensure terminal orders are properly cleaned up from own books and all relevant indexes. Replicates the index cleanup that update_order performs for closed orders.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to remove.
- funding_rate(self, InstrumentId instrument_id, int index=0) FundingRateUpdate¶
Return the funding rate for the given instrument ID at the given index (if found).
Last funding rate if no index specified.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the funding rate to get.
- Returns:
If no funding rates or no funding rate at the index then returns
None.- Return type:
FundingRateUpdate or
None
Notes
Reverse indexed (most recent index price at index 0).
- funding_rate_count(self, InstrumentId instrument_id) int¶
The count of funding rates for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the index prices.
- Return type:
int
- funding_rates(self, InstrumentId instrument_id) list¶
Return funding rates for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the mark prices to get.
- Return type:
list[FundingRateUpdate]
- get(self, str key) bytes¶
Return the general object for the given key.
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.
- Return type:
bytes or
None
- get_mark_xrate(self, Currency from_currency, Currency to_currency)¶
Return the exchange rate based on mark price.
Will return
Noneif an exchange rate has not been set.
- get_xrate(self, Venue venue, Currency from_currency, Currency to_currency, PriceType price_type=PriceType.MID)¶
Return the calculated exchange rate.
If the exchange rate cannot be calculated then returns
None.- Parameters:
- Return type:
float or
None- Raises:
ValueError – If price_type is
LAST.
- greeks(self, InstrumentId instrument_id)¶
Return the latest cached greeks for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID to get the greeks for.
- Returns:
The greeks for the given instrument ID.
- Return type:
GreeksData
- has_backing¶
If the cache has a database backing.
- Returns:
bool
- has_bars(self, BarType bar_type) bool¶
Return a value indicating whether the cache has bars for the given bar type.
- Parameters:
bar_type (BarType) – The bar type for the bars.
- Return type:
bool
- has_funding_rates(self, InstrumentId instrument_id) bool¶
Return a value indicating whether the cache has funding rates for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the funding rates.
- Return type:
bool
- has_index_prices(self, InstrumentId instrument_id) bool¶
Return a value indicating whether the cache has index prices for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the index prices.
- Return type:
bool
- has_mark_prices(self, InstrumentId instrument_id) bool¶
Return a value indicating whether the cache has mark prices for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the mark prices.
- Return type:
bool
- has_order_book(self, InstrumentId instrument_id) bool¶
Return a value indicating whether the cache has an order book snapshot for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the order book snapshot.
- Return type:
bool
- has_quote_ticks(self, InstrumentId instrument_id) bool¶
Return a value indicating whether the cache has quotes for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the ticks.
- Return type:
bool
- has_trade_ticks(self, InstrumentId instrument_id) bool¶
Return a value indicating whether the cache has trades for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the ticks.
- Return type:
bool
- heartbeat(self, datetime timestamp) void¶
Add a heartbeat at the given timestamp.
- Parameters:
timestamp (datetime) – The timestamp for the heartbeat.
- index_price(self, InstrumentId instrument_id, int index=0) IndexPriceUpdate¶
Return the index price for the given instrument ID at the given index (if found).
Last index price if no index specified.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the index price to get.
index (int, optional) – The index for the index price to get.
- Returns:
If no index prices or no index price at index then returns
None.- Return type:
IndexPriceUpdate or
None
Notes
Reverse indexed (most recent index price at index 0).
- index_price_count(self, InstrumentId instrument_id) int¶
The count of index prices for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the index prices.
- Return type:
int
- index_prices(self, InstrumentId instrument_id) list¶
Return index prices for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the mark prices to get.
- Return type:
list[IndexPriceUpdate]
- instrument(self, InstrumentId instrument_id) Instrument¶
Return the instrument corresponding to the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID of the instrument to return.
- Return type:
Instrument or
None
- instrument_ids(self, Venue venue=None) list¶
Return all instrument IDs held by the cache.
- Parameters:
venue (Venue, optional) – The venue filter for the query.
- Return type:
list[InstrumentId]
- instruments(self, Venue venue=None, str underlying=None) list¶
Return all instruments held by the cache.
- Parameters:
venue (Venue, optional) – The venue filter for the query.
underlying (str, optional) – The underlying root symbol for the query.
- Return type:
list[Instrument]
- is_order_closed(self, ClientOrderId client_order_id) bool¶
Return a value indicating whether an order with the given ID is closed.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to check.
- Return type:
bool
- is_order_emulated(self, ClientOrderId client_order_id) bool¶
Return a value indicating whether an order with the given ID is emulated.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to check.
- Return type:
bool
- is_order_inflight(self, ClientOrderId client_order_id) bool¶
Return a value indicating whether an order with the given ID is in-flight.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to check.
- Return type:
bool
- is_order_open(self, ClientOrderId client_order_id) bool¶
Return a value indicating whether an order with the given ID is open.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to check.
- Return type:
bool
- is_order_pending_cancel_local(self, ClientOrderId client_order_id) bool¶
Return a value indicating whether an order with the given ID is pending cancel locally.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to check.
- Return type:
bool
- is_position_closed(self, PositionId position_id) bool¶
Return a value indicating whether a position with the given ID exists and is closed.
- Parameters:
position_id (PositionId) – The position ID.
- Return type:
bool
- is_position_open(self, PositionId position_id) bool¶
Return a value indicating whether a position with the given ID exists and is open.
- Parameters:
position_id (PositionId) – The position ID.
- Return type:
bool
- load_account(self, AccountId account_id) Account¶
Load the account associated with the given account_id (if found).
- Parameters:
account_id (AccountId) – The account ID to load.
- Return type:
Account or
None
- load_actor(self, Actor actor) void¶
Load the state dictionary into the given actor.
- Parameters:
actor (Actor) – The actor to load.
- load_instrument(self, InstrumentId instrument_id) Instrument¶
Load the instrument associated with the given instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The instrument ID to load.
- Return type:
Instrument or
None
- load_order(self, ClientOrderId client_order_id) Order¶
Load the order associated with the given ID (if found).
- Parameters:
client_order_id (ClientOrderId) – The client order ID to load.
- Return type:
Order or
None
- load_position(self, PositionId position_id) Position¶
Load the position associated with the given ID (if found).
- Parameters:
position_id (PositionId) – The position ID to load.
- Return type:
Position or
None
- load_strategy(self, Strategy strategy) void¶
Load the state dictionary into the given strategy.
- Parameters:
strategy (Strategy) – The strategy to load.
- load_synthetic(self, InstrumentId instrument_id) SyntheticInstrument¶
Load the synthetic instrument associated with the given instrument_id (if found).
- Parameters:
instrument_id (InstrumentId) – The synthetic instrument ID to load.
- Return type:
SyntheticInstrument or
None- Raises:
ValueError – If instrument_id is not a synthetic instrument ID.
- mark_price(self, InstrumentId instrument_id, int index=0) MarkPriceUpdate¶
Return the mark price for the given instrument ID at the given index (if found).
Last mark price if no index specified.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the mark price to get.
index (int, optional) – The index for the mark price to get.
- Returns:
If no mark prices or no mark price at index then returns
None.- Return type:
MarkPriceUpdate or
None
Notes
Reverse indexed (most recent mark price at index 0).
- mark_price_count(self, InstrumentId instrument_id) int¶
The count of mark prices for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the mark prices.
- Return type:
int
- mark_prices(self, InstrumentId instrument_id) list¶
Return mark prices for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the mark prices to get.
- Return type:
list[MarkPriceUpdate]
- order(self, ClientOrderId client_order_id) Order¶
Return the order matching the given client order ID (if found).
- Return type:
Order or
None
- order_book(self, InstrumentId instrument_id) OrderBook¶
Return the order book for the given instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the order book to get.
- Returns:
If book not found for the instrument ID then returns
None.- Return type:
OrderBook or
None
- order_exists(self, ClientOrderId client_order_id) bool¶
Return a value indicating whether an order with the given ID exists.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to check.
- Return type:
bool
- order_list(self, OrderListId order_list_id) OrderList¶
Return the order list matching the given order list ID (if found).
- Return type:
OrderList or
None
- order_list_exists(self, OrderListId order_list_id) bool¶
Return a value indicating whether an order list with the given ID exists.
- Parameters:
order_list_id (OrderListId) – The order list ID to check.
- Return type:
bool
- order_list_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all order list IDs.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[OrderListId]
- order_lists(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) list¶
Return all order lists matching the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[OrderList]
- orders(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Return all orders matching the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Order]
- orders_closed(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Return all closed orders with the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Order]
- orders_closed_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Return the count of closed orders with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- orders_emulated(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Return all emulated orders with the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Order]
- orders_emulated_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Return the count of emulated orders with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- orders_for_exec_algorithm(self, ExecAlgorithmId exec_algorithm_id, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Return all execution algorithm orders for the given query filters.
- Parameters:
exec_algorithm_id (ExecAlgorithmId) – The execution algorithm ID.
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Order]
- orders_for_exec_spawn(self, ClientOrderId exec_spawn_id) list¶
Return all orders for the given execution spawn ID (if found).
Will also include the primary (original) order.
- Parameters:
exec_spawn_id (ClientOrderId) – The execution algorithm spawning primary (original) client order ID.
- Return type:
list[Order]
- orders_for_position(self, PositionId position_id) list¶
Return all orders for the given position ID.
- Parameters:
position_id (PositionId) – The position ID for the orders.
- Return type:
list[Order]
- orders_inflight(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Return all in-flight orders with the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Order]
- orders_inflight_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Return the count of in-flight orders with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- orders_open(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Return all open orders with the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Order]
- orders_open_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Return the count of open orders with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- orders_total_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Return the total count of orders with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (OrderSide, default
NO_ORDER_SIDE(no filter)) – The order side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- own_ask_orders(self, InstrumentId instrument_id, set status=None, uint64_t accepted_buffer_ns=0, uint64_t ts_now=0) dict¶
Return own ask orders for the given instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the own orders to get. Note this is the standard Cython InstrumentId.
status (set[OrderStatus], optional) – The order status to filter for. Empty price levels after filtering are excluded from the result.
accepted_buffer_ns (uint64_t, optional) – The minimum time in nanoseconds that must have elapsed since the order was accepted. Orders accepted less than this time ago will be filtered out.
ts_now (uint64_t, optional) – The current time in nanoseconds. Required if accepted_buffer_ns > 0.
- Returns:
If own book not found for the instrument ID then returns
None.- Return type:
dict[Decimal, list[Order]] or
None- Raises:
ValueError – If accepted_buffer_ns > 0 and ts_now == 0.
- own_bid_orders(self, InstrumentId instrument_id, set status=None, uint64_t accepted_buffer_ns=0, uint64_t ts_now=0) dict¶
Return own bid orders for the given instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the own orders to get. Note this is the standard Cython InstrumentId.
status (set[OrderStatus], optional) – The order status to filter for. Empty price levels after filtering are excluded from the result.
accepted_buffer_ns (uint64_t, optional) – The minimum time in nanoseconds that must have elapsed since the order was accepted. Orders accepted less than this time ago will be filtered out.
ts_now (uint64_t, optional) – The current time in nanoseconds. Required if accepted_buffer_ns > 0.
- Returns:
If own book not found for the instrument ID then returns
None.- Return type:
dict[Decimal, list[Order]] or
None- Raises:
ValueError – If accepted_buffer_ns > 0 and ts_now == 0.
- own_order_book(self, InstrumentId instrument_id)¶
Return the own order book for the given instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the own order book to get. Note this is the standard Cython InstrumentId.
- Returns:
If own book not found for the instrument ID then returns
None.- Return type:
nautilus_pyo3.OwnOrderBook or
None
- persist_account_events¶
If account state events are written to the backing database.
- Returns:
bool
- position(self, PositionId position_id) Position¶
Return the position associated with the given ID (if found).
- Parameters:
position_id (PositionId) – The position ID.
- Return type:
Position or
None
- position_closed_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all closed position IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[PositionId]
- position_exists(self, PositionId position_id) bool¶
Return a value indicating whether a position with the given ID exists.
- Parameters:
position_id (PositionId) – The position ID.
- Return type:
int
- position_for_order(self, ClientOrderId client_order_id) Position¶
Return the position associated with the given client order ID (if found).
- Parameters:
client_order_id (ClientOrderId) – The client order ID.
- Return type:
Position or
None
- position_id(self, ClientOrderId client_order_id) PositionId¶
Return the position ID associated with the given client order ID (if found).
- Parameters:
client_order_id (ClientOrderId) – The client order ID associated with the position.
- Return type:
PositionId or
None
- position_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all position IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[PositionId]
- position_open_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Return all open position IDs with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[PositionId]
- position_snapshot_bytes(self, PositionId position_id) list¶
Return the raw pickled snapshot bytes for the given position ID.
- Parameters:
position_id (PositionId) – The position ID to get snapshot bytes for.
- Returns:
The list of pickled snapshot bytes, or empty list if no snapshots exist.
- Return type:
list[bytes]
- position_snapshot_ids(self, InstrumentId instrument_id=None, AccountId account_id=None) set¶
Return all position IDs for position snapshots with the given instrument filter.
- Parameters:
instrument_id (InstrumentId, optional) – The instrument ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
set[PositionId]
- position_snapshots(self, PositionId position_id=None, AccountId account_id=None) list¶
Return all position snapshots with the given optional identifier filter.
- Parameters:
position_id (PositionId, optional) – The position ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Position]
- positions(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, PositionSide side=PositionSide.NO_POSITION_SIDE, AccountId account_id=None) list¶
Return all positions with the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (PositionSide, default
NO_POSITION_SIDE(no filter)) – The position side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Position]
- positions_closed(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) list¶
Return all closed positions with the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Position]
- positions_closed_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) int¶
Return the count of closed positions with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- positions_open(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, PositionSide side=PositionSide.NO_POSITION_SIDE, AccountId account_id=None) list¶
Return all open positions with the given query filters.
No particular order of list elements is guaranteed.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (PositionSide, default
NO_POSITION_SIDE(no filter)) – The position side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
list[Position]
- positions_open_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, PositionSide side=PositionSide.NO_POSITION_SIDE, AccountId account_id=None) int¶
Return the count of open positions with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (PositionSide, default
NO_POSITION_SIDE(no filter)) – The position side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- positions_total_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, PositionSide side=PositionSide.NO_POSITION_SIDE, AccountId account_id=None) int¶
Return the total count of positions with the given query filters.
- Parameters:
venue (Venue, optional) – The venue ID query filter.
instrument_id (InstrumentId, optional) – The instrument ID query filter.
strategy_id (StrategyId, optional) – The strategy ID query filter.
side (PositionSide, default
NO_POSITION_SIDE(no filter)) – The position side query filter.account_id (AccountId, optional) – The account ID query filter.
- Return type:
int
- price(self, InstrumentId instrument_id, PriceType price_type) Price¶
Return the price for the given instrument ID and price type.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the price.
price_type (PriceType) – The price type for the query.
- Return type:
Price or
None
- prices(self, PriceType price_type) dict¶
Return a map of latest prices per instrument ID for the given price type.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the price.
price_type (PriceType) – The price type for the query.
- Returns:
Includes key value pairs for prices which exist.
- Return type:
dict[InstrumentId, Price]
- purge_account_events(self, uint64_t ts_now, uint64_t lookback_secs=0, bool purge_from_database=False) void¶
Purge all account state events which are outside the lookback window.
- Parameters:
ts_now (uint64_t) – The current UNIX timestamp (nanoseconds).
lookback_secs (uint64_t, default 0) – The purge lookback window (seconds) from when the account state event occurred. Only events which are outside the lookback window will be purged. A value of 0 means purge all account state events.
purge_from_database (bool, default False) – If purging operations will also delete from the backing database, in addition to the cache.
- purge_closed_orders(self, uint64_t ts_now, uint64_t buffer_secs=0, bool purge_from_database=False) void¶
Purge all closed orders from the cache.
- Parameters:
ts_now (uint64_t) – The current UNIX timestamp (nanoseconds).
buffer_secs (uint64_t, default 0) – The purge buffer (seconds) from when the order was closed. 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.
purge_from_database (bool, default False) – If purging operations will also delete from the backing database, in addition to the cache.
- purge_closed_positions(self, uint64_t ts_now, uint64_t buffer_secs=0, bool purge_from_database=False) void¶
Purge all closed positions from the cache.
- Parameters:
ts_now (uint64_t) – The current UNIX timestamp (nanoseconds).
buffer_secs (uint64_t, default 0) – The purge buffer (seconds) from when the position was closed. Only positions that have been closed for at least this amount of time will be purged. A value of 0 means purge all closed positions regardless of when they were closed.
purge_from_database (bool, default False) – If purging operations will also delete from the backing database, in addition to the cache.
- purge_order(self, ClientOrderId client_order_id, bool purge_from_database=False) void¶
Purge the order for the given client order ID from the cache (if found).
For safety, an order is prevented from being purged if it’s open.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to purge.
purge_from_database (bool, default False) – If purging operations will also delete from the backing database, in addition to the cache.
- purge_position(self, PositionId position_id, bool purge_from_database=False) void¶
Purge the position for the given position ID from the cache (if found).
For safety, a position is prevented from being purged if it’s open.
- Parameters:
position_id (PositionId) – The position ID to purge.
purge_from_database (bool, default False) – If purging operations will also delete from the backing database, in addition to the cache.
- quote_tick(self, InstrumentId instrument_id, int index=0) QuoteTick¶
Return the quote tick for the given instrument ID at the given index (if found).
Last quote tick if no index specified.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the tick to get.
index (int, optional) – The index for the tick to get.
- Returns:
If no ticks or no tick at index then returns
None.- Return type:
QuoteTick or
None
Notes
Reverse indexed (most recent tick at index 0).
- quote_tick_count(self, InstrumentId instrument_id) int¶
The count of quotes for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the ticks.
- Return type:
int
- quote_ticks(self, InstrumentId instrument_id) list¶
Return the quotes for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the ticks to get.
- Return type:
list[QuoteTick]
- reset(self) void¶
Reset the cache.
All stateful fields are reset to their initial value.
- set_account_id_for_venue(self, Venue venue, AccountId account_id) void¶
Set the account_id for a venue in the cache index.
This allows explicitly setting the mapping between a venue and account_id, which may differ from the account_id’s issuer.
- set_mark_xrate(self, Currency from_currency, Currency to_currency, double xrate) void¶
Set the exchange rate based on mark price.
Will also set the inverse xrate automatically.
- set_specific_venue(self, Venue venue) void¶
Set a specific venue for the cache to use for account lookups.
Primarily for Interactive Brokers, a multi-venue brokerage where account updates are not tied to a single venue.
- Parameters:
venue (Venue) – The specific venue to set.
- snapshot_order_state(self, Order order) void¶
Snapshot the state dictionary for the given order.
This method will persist to the backing cache database.
- Parameters:
order (Order) – The order to snapshot the state for.
- snapshot_position(self, Position position) void¶
Snapshot the given position in its current state.
The position ID will be appended with a UUID v4 string.
- Parameters:
position (Position) – The position to snapshot.
- snapshot_position_state(self, Position position, uint64_t ts_snapshot, Money unrealized_pnl=None, bool open_only=True) void¶
Snapshot the state dictionary for the given position.
This method will persist to the backing cache database.
- Parameters:
position (Position) – The position to snapshot the state for.
ts_snapshot (uint64_t) – UNIX timestamp (nanoseconds) when the snapshot was taken.
unrealized_pnl (Money, optional) – The current unrealized PnL for the position.
open_only (bool, default True) – If only open positions should be snapshot, this flag helps to avoid race conditions where a position is snapshot when no longer open.
- strategy_id_for_order(self, ClientOrderId client_order_id) StrategyId¶
Return the strategy ID associated with the given ID (if found).
- Parameters:
client_order_id (ClientOrderId) – The client order ID associated with the strategy.
- Return type:
StrategyId or
None
- strategy_id_for_position(self, PositionId position_id) StrategyId¶
Return the strategy ID associated with the given ID (if found).
- Parameters:
position_id (PositionId) – The position ID associated with the strategy.
- Return type:
StrategyId or
None
- strategy_ids(self) set¶
Return all strategy IDs.
- Return type:
set[StrategyId]
- synthetic(self, InstrumentId instrument_id) SyntheticInstrument¶
Return the synthetic instrument corresponding to the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID of the synthetic instrument to return.
- Return type:
SyntheticInstrument or
None- Raises:
ValueError – If instrument_id is not a synthetic instrument ID.
- synthetic_ids(self) list¶
Return all synthetic instrument IDs held by the cache.
- Return type:
list[InstrumentId]
- synthetics(self) list¶
Return all synthetic instruments held by the cache.
- Return type:
list[SyntheticInstrument]
- tick_capacity¶
The caches tick capacity.
- Returns:
int
- trade_tick(self, InstrumentId instrument_id, int index=0) TradeTick¶
Return the trade tick for the given instrument ID at the given index (if found).
Last trade tick if no index specified.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the tick to get.
index (int, optional) – The index for the tick to get.
- Returns:
If no ticks or no tick at index then returns
None.- Return type:
TradeTick or
None
Notes
Reverse indexed (most recent tick at index 0).
- trade_tick_count(self, InstrumentId instrument_id) int¶
The count of trades for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the ticks.
- Return type:
int
- trade_ticks(self, InstrumentId instrument_id) list¶
Return trades for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument ID for the ticks to get.
- Return type:
list[TradeTick]
- update_account(self, Account account) void¶
Update the given account in the cache.
- Parameters:
account (The account to update (from last event).)
- update_actor(self, Actor actor) void¶
Update the given actor state in the cache.
- Parameters:
actor (Actor) – The actor to update.
- update_order(self, Order order) void¶
Update the given order in the cache.
- Parameters:
order (Order) – The order to update (from last event).
- update_order_pending_cancel_local(self, Order order) void¶
Update the given order as pending cancel locally.
- Parameters:
order (Order) – The order to update.
- update_own_order_book(self, Order order) void¶
Update the own order book for the given order.
Orders without prices (MARKET, etc.) are skipped as they cannot be represented in own books.
- Parameters:
order (Order) – The order to update.
- update_position(self, Position position) void¶
Update the given position in the cache.
- Parameters:
position (Position) – The position to update (from last event).
- update_strategy(self, Strategy strategy) void¶
Update the given strategy state in the cache.
- Parameters:
strategy (Strategy) – The strategy to update.
- venue_order_id(self, ClientOrderId client_order_id) VenueOrderId¶
Return the order ID matching the given client order ID (if found).
- Return type:
VenueOrderId or
None
- yield_curve(self, str curve_name)¶
Return the latest cached yield curve for the given curve name.
- Parameters:
curve_name (str) – The name of the yield curve to get.
- Returns:
The interest rate curve for the given currency.
- Return type:
YieldCurveData
- class CacheDatabaseAdapter¶
Bases:
CacheDatabaseFacadeCacheDatabaseAdapter(TraderId trader_id, UUID4 instance_id, Serializer serializer, config: CacheConfig | None = None) -> None
Provides a generic cache database adapter.
- Parameters:
trader_id (TraderId) – The trader ID for the adapter.
instance_id (UUID4) – The instance ID for the adapter.
serializer (Serializer) – The serializer for database operations.
config (CacheConfig, optional) – The configuration for the instance.
- Raises:
TypeError – If config is not of type CacheConfig.
Warning
Redis can only accurately store int64 types to 17 digits of precision. Therefore nanosecond timestamp int64’s with 19 digits will lose 2 digits of precision when persisted. One way to solve this is to ensure the serializer converts timestamp int64’s to strings on the way into Redis, and converts timestamp strings back to int64’s on the way out. One way to achieve this is to set the timestamps_as_str flag to true for the MsgSpecSerializer, as per the default implementations for both TradingNode and BacktestEngine.
- add(self, str key, bytes value) void¶
Add the given general object value to the database.
- Parameters:
key (str) – The key to write to.
value (bytes) – The object value.
- add_account(self, Account account) void¶
Add the given account to the database.
- Parameters:
account (Account) – The account to add.
- add_currency(self, Currency currency) void¶
Add the given currency to the database.
- Parameters:
currency (Currency) – The currency to add.
- add_instrument(self, Instrument instrument) void¶
Add the given instrument to the database.
- Parameters:
instrument (Instrument) – The instrument to add.
- add_order(self, Order order, PositionId position_id=None, ClientId client_id=None) void¶
Add the given order to the database.
- Parameters:
order (Order) – The order to add.
position_id (PositionId, optional) – The position ID to associate with this order.
client_id (ClientId, optional) – The execution client ID to associate with this order.
- add_position(self, Position position) void¶
Add the given position to the database.
- Parameters:
position (Position) – The position to add.
- add_synthetic(self, SyntheticInstrument synthetic) void¶
Add the given synthetic instrument to the database.
- Parameters:
synthetic (SyntheticInstrument) – The synthetic instrument to add.
- close(self) void¶
Close the backing database adapter.
- delete_account_event(self, AccountId account_id, str event_id) void¶
Delete the given account event from the database.
- Parameters:
account_id (AccountId) – The account ID to delete events for.
event_id (str) – The event ID to delete.
- delete_actor(self, ComponentId component_id) void¶
Delete the given actor from the database.
- Parameters:
component_id (ComponentId) – The ID of the actor state dictionary to delete.
- delete_order(self, ClientOrderId client_order_id) void¶
Delete the given order from the database.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to delete.
- delete_position(self, PositionId position_id) void¶
Delete the given position from the database.
- Parameters:
position_id (PositionId) – The position ID to delete.
- delete_strategy(self, StrategyId strategy_id) void¶
Delete the given strategy from the database.
- Parameters:
strategy_id (StrategyId) – The ID of the strategy state dictionary to delete.
- flush(self) void¶
Flush the database which clears all data.
- heartbeat(self, datetime timestamp) void¶
Add a heartbeat at the given timestamp.
- Parameters:
timestamp (datetime) – The timestamp for the heartbeat.
- index_order_position(self, ClientOrderId client_order_id, PositionId position_id) void¶
Add an index entry for the given client_order_id to position_id.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to index.
position_id (PositionId) – The position ID to index.
- index_venue_order_id(self, ClientOrderId client_order_id, VenueOrderId venue_order_id) void¶
Add an index entry for the given venue_order_id to client_order_id.
- Parameters:
client_order_id (ClientOrderId) – The client order ID to index.
venue_order_id (VenueOrderId) – The venue order ID to index.
- keys(self, str pattern='*') list¶
Return all keys in the database matching the given pattern.
- Parameters:
pattern (str, default '*') – The glob-style pattern to match against the keys in the database.
- Return type:
list[str]
- Raises:
ValueError – If pattern is not a valid string.
Warning
Using the default ‘*’ pattern string can have serious performance implications and can take a long time to execute if many keys exist in the database. This operation can lead to high memory and CPU usage, and should be used with caution, especially in production environments.
- load(self) dict¶
Load all general objects from the database using bulk loading for efficiency.
- Return type:
dict[str, bytes]
- load_account(self, AccountId account_id) Account¶
Load the account associated with the given account ID (if found).
- Parameters:
account_id (AccountId) – The account ID to load.
- Return type:
Account or
None
- load_accounts(self) dict¶
Load all accounts from the database.
- Return type:
dict[AccountId, Account]
- load_actor(self, ComponentId component_id) dict¶
Load the state for the given actor.
- Parameters:
component_id (ComponentId) – The ID of the actor state dictionary to load.
- Return type:
dict[str, Any]
- load_all(self) dict¶
Load all cache data from the database.
- Returns:
A dictionary containing all cache data organized by category.
- Return type:
dict[str, dict]
- load_currencies(self) dict¶
Load all currencies from the database using bulk loading for efficiency.
- Return type:
dict[str, Currency]
- load_currency(self, str code) Currency¶
Load the currency associated with the given currency code (if found).
- Parameters:
code (str) – The currency code to load.
- Return type:
Currency or
None
- load_index_order_client(self) dict¶
Load the order to execution client index from the database.
- Return type:
dict[ClientOrderId, ClientId]
- load_index_order_position(self) dict¶
Load the order to position index from the database.
- Return type:
dict[ClientOrderId, PositionId]
- load_instrument(self, InstrumentId instrument_id) Instrument¶
Load the instrument associated with the given instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The instrument ID to load.
- Return type:
Instrument or
None
- load_instruments(self) dict¶
Load all instruments from the database using bulk loading for efficiency.
- Return type:
dict[InstrumentId, Instrument]
- load_order(self, ClientOrderId client_order_id) Order¶
Load the order associated with the given client order ID (if found).
- Parameters:
client_order_id (ClientOrderId) – The client order ID to load.
- Return type:
Order or
None
- load_orders(self) dict¶
Load all orders from the database.
- Return type:
dict[ClientOrderId, Order]
- load_position(self, PositionId position_id) Position¶
Load the position associated with the given ID (if found).
- Parameters:
position_id (PositionId) – The position ID to load.
- Return type:
Position or
None
- load_positions(self) dict¶
Load all positions from the database.
- Return type:
dict[PositionId, Position]
- load_strategy(self, StrategyId strategy_id) dict¶
Load the state for the given strategy.
- Parameters:
strategy_id (StrategyId) – The ID of the strategy state dictionary to load.
- Return type:
dict[str, bytes]
- load_synthetic(self, InstrumentId instrument_id) SyntheticInstrument¶
Load the synthetic instrument associated with the given synthetic instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The synthetic instrument ID to load.
- Return type:
SyntheticInstrument or
None- Raises:
ValueError – If instrument_id is not for a synthetic instrument.
- load_synthetics(self) dict¶
Load all synthetic instruments from the database using bulk loading for efficiency.
- Return type:
dict[InstrumentId, SyntheticInstrument]
- snapshot_order_state(self, Order order) void¶
Snapshot the state of the given order.
- Parameters:
order (Order) – The order for the state snapshot.
- snapshot_position_state(self, Position position, uint64_t ts_snapshot, Money unrealized_pnl=None) void¶
Snapshot the state of the given position.
- update_account(self, Account account) void¶
Update the given account in the database.
- Parameters:
account (The account to update (from last event).)
- update_actor(self, Actor actor) void¶
Update the given actor state in the database.
- Parameters:
actor (Actor) – The actor to update.
- update_order(self, Order order) void¶
Update the given order in the database.
- Parameters:
order (Order) – The order to update (from last event).
- class CacheFacade¶
Bases:
objectProvides a read-only facade for the common Cache.
- account(self, AccountId account_id) Account¶
Abstract method (implement in subclass).
- account_for_venue(self, Venue venue=None, AccountId account_id=None) Account¶
Abstract method (implement in subclass).
- accounts(self) list¶
Abstract method (implement in subclass).
- actor_ids(self) set¶
Abstract method (implement in subclass).
- add(self, str key, bytes value) void¶
Abstract method (implement in subclass).
- add_greeks(self, greeks) void¶
Abstract method (implement in subclass).
- add_yield_curve(self, yield_curve) void¶
Abstract method (implement in subclass).
- bar_count(self, BarType bar_type) int¶
Abstract method (implement in subclass).
- bars(self, BarType bar_type) list¶
Abstract method (implement in subclass).
- book_update_count(self, InstrumentId instrument_id) int¶
Abstract method (implement in subclass).
- clear_mark_xrate(self, Currency from_currency, Currency to_currency) void¶
Abstract method (implement in subclass).
- clear_mark_xrates(self) void¶
Abstract method (implement in subclass).
- client_order_id(self, VenueOrderId venue_order_id) ClientOrderId¶
Abstract method (implement in subclass).
- client_order_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Abstract method (implement in subclass).
- client_order_ids_closed(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Abstract method (implement in subclass).
- client_order_ids_emulated(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Abstract method (implement in subclass).
- client_order_ids_inflight(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Abstract method (implement in subclass).
- client_order_ids_open(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Abstract method (implement in subclass).
- exec_algorithm_ids(self) set¶
Abstract method (implement in subclass).
- exec_spawn_total_filled_qty(self, ClientOrderId exec_spawn_id, bool active_only=False) Quantity¶
Abstract method (implement in subclass).
- exec_spawn_total_leaves_qty(self, ClientOrderId exec_spawn_id, bool active_only=False) Quantity¶
Abstract method (implement in subclass).
- exec_spawn_total_quantity(self, ClientOrderId exec_spawn_id, bool active_only=False) Quantity¶
Abstract method (implement in subclass).
- funding_rate(self, InstrumentId instrument_id, int index=0) FundingRateUpdate¶
Abstract method (implement in subclass).
- funding_rate_count(self, InstrumentId instrument_id) int¶
Abstract method (implement in subclass).
- funding_rates(self, InstrumentId instrument_id) list¶
Abstract method (implement in subclass).
- get(self, str key) bytes¶
Abstract method (implement in subclass).
- get_mark_xrate(self, Currency from_currency, Currency to_currency)¶
Abstract method (implement in subclass).
- get_xrate(self, Venue venue, Currency from_currency, Currency to_currency, PriceType price_type=PriceType.MID)¶
Abstract method (implement in subclass).
- greeks(self, InstrumentId instrument_id)¶
Abstract method (implement in subclass).
- has_bars(self, BarType bar_type) bool¶
Abstract method (implement in subclass).
- has_funding_rates(self, InstrumentId instrument_id) bool¶
Abstract method (implement in subclass).
- has_index_prices(self, InstrumentId instrument_id) bool¶
Abstract method (implement in subclass).
- has_mark_prices(self, InstrumentId instrument_id) bool¶
Abstract method (implement in subclass).
- has_order_book(self, InstrumentId instrument_id) bool¶
Abstract method (implement in subclass).
- has_quote_ticks(self, InstrumentId instrument_id) bool¶
Abstract method (implement in subclass).
- has_trade_ticks(self, InstrumentId instrument_id) bool¶
Abstract method (implement in subclass).
- index_price(self, InstrumentId instrument_id, int index=0) IndexPriceUpdate¶
Abstract method (implement in subclass).
- index_price_count(self, InstrumentId instrument_id) int¶
Abstract method (implement in subclass).
- index_prices(self, InstrumentId instrument_id) list¶
Abstract method (implement in subclass).
- instrument(self, InstrumentId instrument_id) Instrument¶
Abstract method (implement in subclass).
- instrument_ids(self, Venue venue=None) list¶
Abstract method (implement in subclass).
- instruments(self, Venue venue=None, str underlying=None) list¶
Abstract method (implement in subclass).
- is_order_closed(self, ClientOrderId client_order_id) bool¶
Abstract method (implement in subclass).
- is_order_emulated(self, ClientOrderId client_order_id) bool¶
Abstract method (implement in subclass).
- is_order_inflight(self, ClientOrderId client_order_id) bool¶
Abstract method (implement in subclass).
- is_order_open(self, ClientOrderId client_order_id) bool¶
Abstract method (implement in subclass).
- is_order_pending_cancel_local(self, ClientOrderId client_order_id) bool¶
Abstract method (implement in subclass).
- is_position_closed(self, PositionId position_id) bool¶
Abstract method (implement in subclass).
- is_position_open(self, PositionId position_id) bool¶
Abstract method (implement in subclass).
- mark_price(self, InstrumentId instrument_id, int index=0) MarkPriceUpdate¶
Abstract method (implement in subclass).
- mark_price_count(self, InstrumentId instrument_id) int¶
Abstract method (implement in subclass).
- mark_prices(self, InstrumentId instrument_id) list¶
Abstract method (implement in subclass).
- order_exists(self, ClientOrderId client_order_id) bool¶
Abstract method (implement in subclass).
- order_list_exists(self, OrderListId order_list_id) bool¶
Abstract method (implement in subclass).
- order_list_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Abstract method (implement in subclass).
- order_lists(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) list¶
Abstract method (implement in subclass).
- orders(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Abstract method (implement in subclass).
- orders_closed(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Abstract method (implement in subclass).
- orders_closed_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Abstract method (implement in subclass).
- orders_emulated(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Abstract method (implement in subclass).
- orders_emulated_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Abstract method (implement in subclass).
- orders_for_exec_algorithm(self, ExecAlgorithmId exec_algorithm_id, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Abstract method (implement in subclass).
- orders_for_exec_spawn(self, ClientOrderId exec_spawn_id) list¶
Abstract method (implement in subclass).
- orders_for_position(self, PositionId position_id) list¶
Abstract method (implement in subclass).
- orders_inflight(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Abstract method (implement in subclass).
- orders_inflight_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Abstract method (implement in subclass).
- orders_open(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) list¶
Abstract method (implement in subclass).
- orders_open_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Abstract method (implement in subclass).
- orders_total_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, OrderSide side=OrderSide.NO_ORDER_SIDE, AccountId account_id=None) int¶
Abstract method (implement in subclass).
- own_ask_orders(self, InstrumentId instrument_id, set status=None, uint64_t accepted_buffer_ns=0, uint64_t ts_now=0) dict¶
Abstract method (implement in subclass).
- own_bid_orders(self, InstrumentId instrument_id, set status=None, uint64_t accepted_buffer_ns=0, uint64_t ts_now=0) dict¶
Abstract method (implement in subclass).
- own_order_book(self, InstrumentId instrument_id)¶
Abstract method (implement in subclass).
- position_closed_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Abstract method (implement in subclass).
- position_exists(self, PositionId position_id) bool¶
Abstract method (implement in subclass).
- position_for_order(self, ClientOrderId client_order_id) Position¶
Abstract method (implement in subclass).
- position_id(self, ClientOrderId client_order_id) PositionId¶
Abstract method (implement in subclass).
- position_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Abstract method (implement in subclass).
- position_open_ids(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) set¶
Abstract method (implement in subclass).
- position_snapshot_bytes(self, PositionId position_id) list¶
Abstract method (implement in subclass).
- position_snapshot_ids(self, InstrumentId instrument_id=None, AccountId account_id=None) set¶
Abstract method (implement in subclass).
- position_snapshots(self, PositionId position_id=None, AccountId account_id=None) list¶
Abstract method (implement in subclass).
- positions(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, PositionSide side=PositionSide.NO_POSITION_SIDE, AccountId account_id=None) list¶
Abstract method (implement in subclass).
- positions_closed(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) list¶
Abstract method (implement in subclass).
- positions_closed_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, AccountId account_id=None) int¶
Abstract method (implement in subclass).
- positions_open(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, PositionSide side=PositionSide.NO_POSITION_SIDE, AccountId account_id=None) list¶
Abstract method (implement in subclass).
- positions_open_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, PositionSide side=PositionSide.NO_POSITION_SIDE, AccountId account_id=None) int¶
Abstract method (implement in subclass).
- positions_total_count(self, Venue venue=None, InstrumentId instrument_id=None, StrategyId strategy_id=None, PositionSide side=PositionSide.NO_POSITION_SIDE, AccountId account_id=None) int¶
Abstract method (implement in subclass).
- price(self, InstrumentId instrument_id, PriceType price_type) Price¶
Abstract method (implement in subclass).
- prices(self, PriceType price_type) dict¶
Abstract method (implement in subclass).
- quote_tick(self, InstrumentId instrument_id, int index=0) QuoteTick¶
Abstract method (implement in subclass).
- quote_tick_count(self, InstrumentId instrument_id) int¶
Abstract method (implement in subclass).
- quote_ticks(self, InstrumentId instrument_id) list¶
Abstract method (implement in subclass).
- set_account_id_for_venue(self, Venue venue, AccountId account_id) void¶
Abstract method (implement in subclass).
- set_mark_xrate(self, Currency from_currency, Currency to_currency, double xrate) void¶
Abstract method (implement in subclass).
- set_specific_venue(self, Venue venue) void¶
Abstract method (implement in subclass).
- strategy_id_for_order(self, ClientOrderId client_order_id) StrategyId¶
Abstract method (implement in subclass).
- strategy_id_for_position(self, PositionId position_id) StrategyId¶
Abstract method (implement in subclass).
- strategy_ids(self) set¶
Abstract method (implement in subclass).
- synthetic(self, InstrumentId instrument_id) SyntheticInstrument¶
Abstract method (implement in subclass).
- synthetic_ids(self) list¶
Abstract method (implement in subclass).
- synthetics(self) list¶
Abstract method (implement in subclass).
- trade_tick(self, InstrumentId instrument_id, int index=0) TradeTick¶
Abstract method (implement in subclass).
- trade_tick_count(self, InstrumentId instrument_id) int¶
Abstract method (implement in subclass).
- trade_ticks(self, InstrumentId instrument_id) list¶
Abstract method (implement in subclass).
- venue_order_id(self, ClientOrderId client_order_id) VenueOrderId¶
Abstract method (implement in subclass).
- yield_curve(self, str curve_name)¶
Abstract method (implement in subclass).