Skip to content

Commit

Permalink
Add CacheConfig.drop_instruments_on_reset option
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Jan 12, 2024
1 parent eb05783 commit e57a92e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Released on TBD (UTC).
- Added `NautilusConfig.json_primitives` to convert object to Python dictionary with JSON primitive values
- Added `InstrumentClass.BOND`
- Added `MessageBusConfig` `use_trader_prefix` and `use_trader_id` options (provides more control over stream names)
- Added `CacheConfig.drop_instruments_on_reset` (default true to retain current behavior)
- Implemented core logging interface via the `log` library, thanks @twitu
- Implemented global atomic clock in Rust (improves performance and ensures properly monotonic timestamps in real-time)
- Improved Interactive Brokers adapter raising docker `RuntimeError` only when needed (not when using TWS), thanks @rsmb7z
Expand Down
1 change: 1 addition & 0 deletions nautilus_trader/cache/cache.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ cdef class Cache(CacheFacade):
cdef set _index_actors
cdef set _index_strategies
cdef set _index_exec_algorithms
cdef bint _drop_instruments_on_reset

cdef readonly int tick_capacity
"""The caches tick capacity.\n\n:returns: `int`"""
Expand Down
5 changes: 4 additions & 1 deletion nautilus_trader/cache/cache.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ cdef class Cache(CacheFacade):
self._xrate_calculator = ExchangeRateCalculator()

# Configuration
self._drop_instruments_on_reset = config.drop_instruments_on_reset
self.tick_capacity = config.tick_capacity
self.bar_capacity = config.bar_capacity
self.snapshot_orders = snapshot_orders
Expand Down Expand Up @@ -727,7 +728,6 @@ cdef class Cache(CacheFacade):
self._bars_bid.clear()
self._bars_ask.clear()
self._currencies.clear()
self._instruments.clear()
self._synthetics.clear()
self._accounts.clear()
self._orders.clear()
Expand All @@ -736,6 +736,9 @@ cdef class Cache(CacheFacade):
self._position_snapshots.clear()
self.clear_index()

if self._drop_instruments_on_reset:
self._instruments.clear()

self._log.debug(f"Reset cache.")

cpdef void flush_db(self):
Expand Down
9 changes: 6 additions & 3 deletions nautilus_trader/config/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,14 @@ class CacheConfig(NautilusConfig, frozen=True):
The buffer interval (milliseconds) between pipelined/batched transactions.
The recommended range if using buffered pipeling is [10, 1000] milliseconds,
with a good compromise being 100 milliseconds.
flush_on_start : bool, default False
If database should be flushed on start.
use_trader_prefix : bool, default True
If a 'trader-' prefix is used for keys.
use_instance_id : bool, default False
If the traders instance ID is used for keys.
flush_on_start : bool, default False
If database should be flushed on start.
drop_instruments_on_reset : bool, default True
If instruments data should be dropped from the caches memory on reset.
tick_capacity : PositiveInt, default 10_000
The maximum length for internal tick dequeues.
bar_capacity : PositiveInt, default 10_000
Expand All @@ -275,9 +277,10 @@ class CacheConfig(NautilusConfig, frozen=True):
encoding: str = "msgpack"
timestamps_as_iso8601: bool = False
buffer_interval_ms: PositiveInt | None = None
flush_on_start: bool = False
use_trader_prefix: bool = True
use_instance_id: bool = False
flush_on_start: bool = False
drop_instruments_on_reset: bool = True
tick_capacity: PositiveInt = 10_000
bar_capacity: PositiveInt = 10_000

Expand Down

0 comments on commit e57a92e

Please sign in to comment.