From f0370a767709e520313ba2eac231811ebfbca531 Mon Sep 17 00:00:00 2001 From: Chris Sellers Date: Fri, 22 Dec 2023 20:02:15 +1100 Subject: [PATCH] Move Portfolio down to Actor --- nautilus_trader/adapters/sandbox/execution.py | 5 + nautilus_trader/adapters/sandbox/factory.py | 5 + nautilus_trader/backtest/engine.pyx | 1 + nautilus_trader/backtest/exchange.pyx | 5 + nautilus_trader/common/actor.pxd | 4 + nautilus_trader/common/actor.pyx | 6 + nautilus_trader/execution/algorithm.pxd | 3 - nautilus_trader/execution/algorithm.pyx | 3 +- nautilus_trader/execution/emulator.pyx | 8 +- nautilus_trader/system/kernel.py | 5 +- nautilus_trader/trading/strategy.pxd | 2 - nautilus_trader/trading/strategy.pyx | 4 +- nautilus_trader/trading/trader.py | 1 + .../adapters/sandbox/conftest.py | 2 + .../infrastructure/test_cache_database.py | 2 + tests/unit_tests/backtest/test_exchange.py | 3 + .../backtest/test_exchange_bitmex.py | 1 + ...est_exchange_bracket_if_touched_entries.py | 3 +- .../backtest/test_exchange_contingencies.py | 1 + .../backtest/test_exchange_l2_mbp.py | 1 + .../backtest/test_exchange_stop_limits.py | 1 + .../backtest/test_exchange_trailing_stops.py | 1 + tests/unit_tests/common/test_actor.py | 123 +++++++++++++++++- tests/unit_tests/execution/test_algorithm.py | 3 +- tests/unit_tests/execution/test_emulator.py | 2 +- .../execution/test_emulator_list.py | 3 +- .../unit_tests/live/test_execution_engine.py | 2 +- tests/unit_tests/risk/test_engine.py | 4 +- tests/unit_tests/trading/test_strategy.py | 1 + tests/unit_tests/trading/test_trader.py | 1 + 30 files changed, 181 insertions(+), 25 deletions(-) diff --git a/nautilus_trader/adapters/sandbox/execution.py b/nautilus_trader/adapters/sandbox/execution.py index add51b1a8717..56f47349a27f 100644 --- a/nautilus_trader/adapters/sandbox/execution.py +++ b/nautilus_trader/adapters/sandbox/execution.py @@ -50,6 +50,7 @@ from nautilus_trader.model.objects import AccountBalance from nautilus_trader.model.objects import Currency from nautilus_trader.model.objects import Money +from nautilus_trader.portfolio.base import PortfolioFacade class SandboxExecutionClient(LiveExecutionClient): @@ -60,6 +61,8 @@ class SandboxExecutionClient(LiveExecutionClient): ---------- loop : asyncio.AbstractEventLoop The event loop for the client. + portfolio : PortfolioFacade + The read-only portfolio for the client. msgbus : MessageBus The message bus for the client. cache : Cache @@ -76,6 +79,7 @@ class SandboxExecutionClient(LiveExecutionClient): def __init__( self, loop: asyncio.AbstractEventLoop, + portfolio: PortfolioFacade, msgbus: MessageBus, cache: Cache, clock: LiveClock, @@ -116,6 +120,7 @@ def __init__( leverages={}, instruments=self.INSTRUMENTS, modules=[], + portfolio=portfolio, msgbus=self._msgbus, cache=cache, fill_model=FillModel(), diff --git a/nautilus_trader/adapters/sandbox/factory.py b/nautilus_trader/adapters/sandbox/factory.py index 5f6df8bde926..fee9f4e6dc46 100644 --- a/nautilus_trader/adapters/sandbox/factory.py +++ b/nautilus_trader/adapters/sandbox/factory.py @@ -22,6 +22,7 @@ from nautilus_trader.common.component import MessageBus from nautilus_trader.common.logging import Logger from nautilus_trader.live.factories import LiveExecClientFactory +from nautilus_trader.portfolio import PortfolioFacade class SandboxLiveExecClientFactory(LiveExecClientFactory): @@ -34,6 +35,7 @@ def create( # type: ignore loop: asyncio.AbstractEventLoop, name: str, config: SandboxExecutionClientConfig, + portfolio: PortfolioFacade, msgbus: MessageBus, cache: Cache, clock: LiveClock, @@ -50,6 +52,8 @@ def create( # type: ignore The client name. config : dict[str, object] The configuration for the client. + portfolio : PortfolioFacade + The read-only portfolio for the client. msgbus : MessageBus The message bus for the client. cache : Cache @@ -67,6 +71,7 @@ def create( # type: ignore exec_client = SandboxExecutionClient( loop=loop, clock=clock, + portfolio=portfolio, msgbus=msgbus, cache=cache, logger=logger, diff --git a/nautilus_trader/backtest/engine.pyx b/nautilus_trader/backtest/engine.pyx index b6ec9dac215a..47540caa10ac 100644 --- a/nautilus_trader/backtest/engine.pyx +++ b/nautilus_trader/backtest/engine.pyx @@ -447,6 +447,7 @@ cdef class BacktestEngine: leverages=leverages or {}, instruments=[], modules=modules, + portfolio=self.kernel.portfolio, msgbus=self.kernel.msgbus, cache=self.kernel.cache, fill_model=fill_model, diff --git a/nautilus_trader/backtest/exchange.pyx b/nautilus_trader/backtest/exchange.pyx index e224e6302c35..adcd21a3edd1 100644 --- a/nautilus_trader/backtest/exchange.pyx +++ b/nautilus_trader/backtest/exchange.pyx @@ -58,6 +58,7 @@ from nautilus_trader.model.objects cimport AccountBalance from nautilus_trader.model.objects cimport Money from nautilus_trader.model.objects cimport Price from nautilus_trader.model.orders.base cimport Order +from nautilus_trader.portfolio.base cimport PortfolioFacade cdef class SimulatedExchange: @@ -80,6 +81,8 @@ cdef class SimulatedExchange: The account default leverage (for margin accounts). leverages : dict[InstrumentId, Decimal] The instrument specific leverage configuration (for margin accounts). + portfolio : PortfolioFacade + The read-only portfolio for the exchange. msgbus : MessageBus The message bus for the exchange. cache : CacheFacade @@ -139,6 +142,7 @@ cdef class SimulatedExchange: leverages not None: dict[InstrumentId, Decimal], list instruments not None, list modules not None, + PortfolioFacade portfolio not None, MessageBus msgbus not None, CacheFacade cache not None, TestClock clock not None, @@ -204,6 +208,7 @@ cdef class SimulatedExchange: Condition.not_in(module, self.modules, "module", "modules") module.register_venue(self) module.register_base( + portfolio=portfolio, msgbus=msgbus, cache=cache, clock=clock, diff --git a/nautilus_trader/common/actor.pxd b/nautilus_trader/common/actor.pxd index ba1ba3ecb27d..f7e54d798623 100644 --- a/nautilus_trader/common/actor.pxd +++ b/nautilus_trader/common/actor.pxd @@ -48,6 +48,7 @@ from nautilus_trader.model.identifiers cimport InstrumentId from nautilus_trader.model.identifiers cimport Venue from nautilus_trader.model.instruments.base cimport Instrument from nautilus_trader.model.instruments.synthetic cimport SyntheticInstrument +from nautilus_trader.portfolio.base cimport PortfolioFacade cdef class Actor(Component): @@ -60,6 +61,8 @@ cdef class Actor(Component): cdef dict _indicators_for_trades cdef dict _indicators_for_bars + cdef readonly PortfolioFacade portfolio + """The read-only portfolio for the actor.\n\n:returns: `PortfolioFacade`""" cdef readonly config """The actors configuration.\n\n:returns: `NautilusConfig`""" cdef readonly Clock clock @@ -102,6 +105,7 @@ cdef class Actor(Component): cpdef void register_base( self, + PortfolioFacade portfolio, MessageBus msgbus, CacheFacade cache, Clock clock, diff --git a/nautilus_trader/common/actor.pyx b/nautilus_trader/common/actor.pyx index 0198f0fbe456..47624e27fc80 100644 --- a/nautilus_trader/common/actor.pyx +++ b/nautilus_trader/common/actor.pyx @@ -77,6 +77,7 @@ from nautilus_trader.model.identifiers cimport InstrumentId from nautilus_trader.model.identifiers cimport Venue from nautilus_trader.model.instruments.base cimport Instrument from nautilus_trader.model.instruments.synthetic cimport SyntheticInstrument +from nautilus_trader.portfolio.base cimport PortfolioFacade cdef class Actor(Component): @@ -546,6 +547,7 @@ cdef class Actor(Component): cpdef void register_base( self, + PortfolioFacade portfolio, MessageBus msgbus, CacheFacade cache, Clock clock, @@ -556,6 +558,8 @@ cdef class Actor(Component): Parameters ---------- + portfolio : PortfolioFacade + The read-only portfolio for the actor. msgbus : MessageBus The message bus for the actor. cache : CacheFacade @@ -570,6 +574,7 @@ cdef class Actor(Component): System method (not intended to be called by user code). """ + Condition.not_none(portfolio, "portfolio") Condition.not_none(msgbus, "msgbus") Condition.not_none(cache, "cache") Condition.not_none(clock, "clock") @@ -580,6 +585,7 @@ cdef class Actor(Component): self._change_logger(logger) self._change_msgbus(msgbus) # The trader ID is assigned here + self.portfolio = portfolio # Assigned as PortfolioFacade self.msgbus = msgbus self.cache = cache self.clock = self._clock diff --git a/nautilus_trader/execution/algorithm.pxd b/nautilus_trader/execution/algorithm.pxd index 4179f854f6ae..459139489710 100644 --- a/nautilus_trader/execution/algorithm.pxd +++ b/nautilus_trader/execution/algorithm.pxd @@ -71,9 +71,6 @@ cdef class ExecAlgorithm(Actor): cdef dict _exec_spawn_ids cdef set _subscribed_strategies - cdef readonly PortfolioFacade portfolio - """The read-only portfolio for the strategy.\n\n:returns: `PortfolioFacade`""" - # -- REGISTRATION --------------------------------------------------------------------------------- cpdef void register( diff --git a/nautilus_trader/execution/algorithm.pyx b/nautilus_trader/execution/algorithm.pyx index 531922dc58ba..8527d7010b4e 100644 --- a/nautilus_trader/execution/algorithm.pyx +++ b/nautilus_trader/execution/algorithm.pyx @@ -184,14 +184,13 @@ cdef class ExecAlgorithm(Actor): Condition.not_none(logger, "logger") self.register_base( + portfolio=portfolio, msgbus=msgbus, cache=cache, clock=clock, logger=logger, ) - self.portfolio = portfolio - # Register endpoints self._msgbus.register(endpoint=f"{self.id}.execute", handler=self.execute) diff --git a/nautilus_trader/execution/emulator.pyx b/nautilus_trader/execution/emulator.pyx index df4d6e7c3c5b..4a59118401e7 100644 --- a/nautilus_trader/execution/emulator.pyx +++ b/nautilus_trader/execution/emulator.pyx @@ -72,6 +72,7 @@ from nautilus_trader.model.objects cimport Quantity from nautilus_trader.model.orders.base cimport Order from nautilus_trader.model.orders.limit cimport LimitOrder from nautilus_trader.model.orders.market cimport MarketOrder +from nautilus_trader.portfolio.base cimport PortfolioFacade cdef set SUPPORTED_TRIGGERS = {TriggerType.DEFAULT, TriggerType.BID_ASK, TriggerType.LAST_TRADE} @@ -83,8 +84,8 @@ cdef class OrderEmulator(Actor): Parameters ---------- - trader_id : TraderId - The trader ID for the order emulator. + portfolio : PortfolioFacade + The read-only portfolio for the order emulator. msgbus : MessageBus The message bus for the order emulator. cache : Cache @@ -100,7 +101,7 @@ cdef class OrderEmulator(Actor): def __init__( self, - TraderId trader_id not None, + PortfolioFacade portfolio, MessageBus msgbus not None, Cache cache not None, Clock clock not None, @@ -113,6 +114,7 @@ cdef class OrderEmulator(Actor): super().__init__() self.register_base( + portfolio=portfolio, msgbus=msgbus, cache=cache, clock=clock, diff --git a/nautilus_trader/system/kernel.py b/nautilus_trader/system/kernel.py index 7f869b52f764..55bed43568cd 100644 --- a/nautilus_trader/system/kernel.py +++ b/nautilus_trader/system/kernel.py @@ -381,7 +381,7 @@ def __init__( # noqa (too complex) self.exec_engine.load_cache() self._emulator = OrderEmulator( - trader_id=self._trader_id, + portfolio=self._portfolio, msgbus=self._msgbus, cache=self._cache, clock=self._clock, @@ -419,8 +419,9 @@ def __init__( # noqa (too complex) trader=self._trader, ) self._controller.register_base( - cache=self._cache, + portfolio=self._portfolio, msgbus=self._msgbus, + cache=self._cache, clock=self._clock, logger=self._logger, ) diff --git a/nautilus_trader/trading/strategy.pxd b/nautilus_trader/trading/strategy.pxd index 6615e0654042..18aac5ded2a4 100644 --- a/nautilus_trader/trading/strategy.pxd +++ b/nautilus_trader/trading/strategy.pxd @@ -70,8 +70,6 @@ from nautilus_trader.portfolio.base cimport PortfolioFacade cdef class Strategy(Actor): cdef OrderManager _manager - cdef readonly PortfolioFacade portfolio - """The read-only portfolio for the strategy.\n\n:returns: `PortfolioFacade`""" cdef readonly OrderFactory order_factory """The order factory for the strategy.\n\n:returns: `OrderFactory`""" cdef readonly str order_id_tag diff --git a/nautilus_trader/trading/strategy.pyx b/nautilus_trader/trading/strategy.pyx index 052df14b74bf..0660fc2a82c8 100644 --- a/nautilus_trader/trading/strategy.pyx +++ b/nautilus_trader/trading/strategy.pyx @@ -104,6 +104,7 @@ from nautilus_trader.model.orders.base cimport Order from nautilus_trader.model.orders.list cimport OrderList from nautilus_trader.model.orders.market cimport MarketOrder from nautilus_trader.model.position cimport Position +from nautilus_trader.portfolio.base cimport PortfolioFacade cdef class Strategy(Actor): @@ -277,14 +278,13 @@ cdef class Strategy(Actor): Condition.not_none(logger, "logger") self.register_base( + portfolio=portfolio, msgbus=msgbus, cache=cache, clock=clock, logger=logger, ) - self.portfolio = portfolio # Assigned as PortfolioFacade - self.order_factory = OrderFactory( trader_id=self.trader_id, strategy_id=self.id, diff --git a/nautilus_trader/trading/trader.py b/nautilus_trader/trading/trader.py index 1e4a41745bb2..1219d95d4ca2 100644 --- a/nautilus_trader/trading/trader.py +++ b/nautilus_trader/trading/trader.py @@ -319,6 +319,7 @@ def add_actor(self, actor: Actor) -> None: # Wire component into trader actor.register_base( + portfolio=self._portfolio, msgbus=self._msgbus, cache=self._cache, clock=clock, # Clock per component diff --git a/tests/integration_tests/adapters/sandbox/conftest.py b/tests/integration_tests/adapters/sandbox/conftest.py index c2d86d26c638..950ee7314795 100644 --- a/tests/integration_tests/adapters/sandbox/conftest.py +++ b/tests/integration_tests/adapters/sandbox/conftest.py @@ -32,6 +32,7 @@ def venue() -> Venue: def exec_client( instrument, event_loop, + portfolio, msgbus, cache, clock, @@ -41,6 +42,7 @@ def exec_client( SandboxExecutionClient.INSTRUMENTS = [instrument] return SandboxExecutionClient( loop=event_loop, + portfolio=portfolio, msgbus=msgbus, cache=cache, clock=clock, diff --git a/tests/integration_tests/infrastructure/test_cache_database.py b/tests/integration_tests/infrastructure/test_cache_database.py index 7ce5730690dc..02ad6d7030e3 100644 --- a/tests/integration_tests/infrastructure/test_cache_database.py +++ b/tests/integration_tests/infrastructure/test_cache_database.py @@ -487,6 +487,7 @@ async def test_update_actor(self): # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1018,6 +1019,7 @@ async def test_delete_actor(self): # Arrange, Act actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, diff --git a/tests/unit_tests/backtest/test_exchange.py b/tests/unit_tests/backtest/test_exchange.py index 7c4dd8fd434b..0266d0c33814 100644 --- a/tests/unit_tests/backtest/test_exchange.py +++ b/tests/unit_tests/backtest/test_exchange.py @@ -141,6 +141,7 @@ def setup(self) -> None: instruments=[USDJPY_SIM], modules=[], fill_model=FillModel(), + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -2629,6 +2630,7 @@ def test_adjust_account_when_account_frozen_does_not_change_balance(self) -> Non instruments=[USDJPY_SIM], modules=[], fill_model=FillModel(), + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -2938,6 +2940,7 @@ def reset(self): instruments=[USDJPY_SIM], modules=[self.module], fill_model=FillModel(), + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, diff --git a/tests/unit_tests/backtest/test_exchange_bitmex.py b/tests/unit_tests/backtest/test_exchange_bitmex.py index b26826d4d761..2d48092a1cda 100644 --- a/tests/unit_tests/backtest/test_exchange_bitmex.py +++ b/tests/unit_tests/backtest/test_exchange_bitmex.py @@ -105,6 +105,7 @@ def setup(self): starting_balances=[Money(20, BTC)], default_leverage=Decimal(50), leverages={}, + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, instruments=[XBTUSD_BITMEX], diff --git a/tests/unit_tests/backtest/test_exchange_bracket_if_touched_entries.py b/tests/unit_tests/backtest/test_exchange_bracket_if_touched_entries.py index ac10a1022694..2acf073d53c2 100644 --- a/tests/unit_tests/backtest/test_exchange_bracket_if_touched_entries.py +++ b/tests/unit_tests/backtest/test_exchange_bracket_if_touched_entries.py @@ -103,7 +103,7 @@ def setup(self): ) self.emulator = OrderEmulator( - trader_id=self.trader_id, + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -121,6 +121,7 @@ def setup(self): instruments=[ETHUSDT_PERP_BINANCE], modules=[], fill_model=FillModel(), + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, diff --git a/tests/unit_tests/backtest/test_exchange_contingencies.py b/tests/unit_tests/backtest/test_exchange_contingencies.py index c9a9221b6dc2..6db66a39b010 100644 --- a/tests/unit_tests/backtest/test_exchange_contingencies.py +++ b/tests/unit_tests/backtest/test_exchange_contingencies.py @@ -109,6 +109,7 @@ def setup(self): instruments=[ETHUSDT_PERP_BINANCE], modules=[], fill_model=FillModel(), + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, diff --git a/tests/unit_tests/backtest/test_exchange_l2_mbp.py b/tests/unit_tests/backtest/test_exchange_l2_mbp.py index 5b90be9c8cfc..061e4feba2a8 100644 --- a/tests/unit_tests/backtest/test_exchange_l2_mbp.py +++ b/tests/unit_tests/backtest/test_exchange_l2_mbp.py @@ -115,6 +115,7 @@ def setup(self): instruments=[USDJPY_SIM], modules=[], fill_model=FillModel(), + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, diff --git a/tests/unit_tests/backtest/test_exchange_stop_limits.py b/tests/unit_tests/backtest/test_exchange_stop_limits.py index aed113ab7907..e17c1f9da079 100644 --- a/tests/unit_tests/backtest/test_exchange_stop_limits.py +++ b/tests/unit_tests/backtest/test_exchange_stop_limits.py @@ -113,6 +113,7 @@ def setup(self): instruments=[USDJPY_SIM], modules=[], fill_model=FillModel(), + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, diff --git a/tests/unit_tests/backtest/test_exchange_trailing_stops.py b/tests/unit_tests/backtest/test_exchange_trailing_stops.py index 3e3cab861bdd..2dc4febd9510 100644 --- a/tests/unit_tests/backtest/test_exchange_trailing_stops.py +++ b/tests/unit_tests/backtest/test_exchange_trailing_stops.py @@ -122,6 +122,7 @@ def setup(self) -> None: instruments=[USDJPY_SIM], modules=[], fill_model=FillModel(), + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, diff --git a/tests/unit_tests/common/test_actor.py b/tests/unit_tests/common/test_actor.py index 3bd96062b87a..c56c7bb79f22 100644 --- a/tests/unit_tests/common/test_actor.py +++ b/tests/unit_tests/common/test_actor.py @@ -48,6 +48,7 @@ from nautilus_trader.model.identifiers import Symbol from nautilus_trader.model.identifiers import Venue from nautilus_trader.persistence.writer import StreamingFeatherWriter +from nautilus_trader.portfolio.portfolio import Portfolio from nautilus_trader.test_kit.mocks.actors import KaboomActor from nautilus_trader.test_kit.mocks.actors import MockActor from nautilus_trader.test_kit.mocks.data import data_catalog_setup @@ -88,6 +89,13 @@ def setup(self) -> None: self.cache = TestComponentStubs.cache() + self.portfolio = Portfolio( + msgbus=self.msgbus, + cache=self.cache, + clock=self.clock, + logger=self.logger, + ) + self.data_engine = DataEngine( msgbus=self.msgbus, cache=self.cache, @@ -141,6 +149,7 @@ def test_id(self) -> None: # Arrange, Act actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -162,6 +171,7 @@ def test_initialization(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -179,6 +189,7 @@ def test_register_warning_event(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -195,6 +206,7 @@ def test_deregister_warning_event(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -213,6 +225,7 @@ def test_handle_event(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -231,6 +244,7 @@ def test_on_start_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -247,6 +261,7 @@ def test_on_stop_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -263,6 +278,7 @@ def test_on_resume_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -279,6 +295,7 @@ def test_on_reset_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -295,6 +312,7 @@ def test_on_dispose_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -311,6 +329,7 @@ def test_on_degrade_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -327,6 +346,7 @@ def test_on_fault_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -343,6 +363,7 @@ def test_on_instrument_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -359,6 +380,7 @@ def test_on_order_book_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -375,6 +397,7 @@ def test_on_order_book_delta_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -391,6 +414,7 @@ def test_on_ticker_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -407,6 +431,7 @@ def test_on_venue_status_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -423,6 +448,7 @@ def test_on_instrument_status_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -439,6 +465,7 @@ def test_on_event_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -455,6 +482,7 @@ def test_on_quote_tick_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -473,6 +501,7 @@ def test_on_trade_tick_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -491,6 +520,7 @@ def test_on_bar_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -509,6 +539,7 @@ def test_on_historical_data_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -527,6 +558,7 @@ def test_on_data_when_not_overridden_does_nothing(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -551,6 +583,7 @@ def test_start_when_invalid_state_does_not_start(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -567,6 +600,7 @@ def test_stop_when_invalid_state_does_not_stop(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -583,6 +617,7 @@ def test_resume_when_invalid_state_does_not_resume(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -599,6 +634,7 @@ def test_reset_when_invalid_state_does_not_reset(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -615,6 +651,7 @@ def test_dispose_when_invalid_state_does_not_dispose(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -631,6 +668,7 @@ def test_degrade_when_invalid_state_does_not_degrade(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -647,6 +685,7 @@ def test_fault_when_invalid_state_does_not_fault(self) -> None: # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -663,6 +702,7 @@ def test_start_when_user_code_raises_error_logs_and_reraises(self) -> None: # Arrange actor = KaboomActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -678,6 +718,7 @@ def test_stop_when_user_code_raises_error_logs_and_reraises(self) -> None: # Arrange actor = KaboomActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -696,6 +737,7 @@ def test_resume_when_user_code_raises_error_logs_and_reraises(self) -> None: # Arrange actor = KaboomActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -716,6 +758,7 @@ def test_reset_when_user_code_raises_error_logs_and_reraises(self) -> None: # Arrange actor = KaboomActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -731,6 +774,7 @@ def test_dispose_when_user_code_raises_error_logs_and_reraises(self) -> None: # Arrange actor = KaboomActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -746,6 +790,7 @@ def test_degrade_when_user_code_raises_error_logs_and_reraises(self) -> None: # Arrange actor = KaboomActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -764,6 +809,7 @@ def test_fault_when_user_code_raises_error_logs_and_reraises(self) -> None: # Arrange actor = KaboomActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -782,6 +828,7 @@ def test_handle_quote_tick_when_user_code_raises_exception_logs_and_reraises(sel # Arrange actor = KaboomActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -801,6 +848,7 @@ def test_handle_trade_tick_when_user_code_raises_exception_logs_and_reraises(sel # Arrange actor = KaboomActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -820,6 +868,7 @@ def test_handle_bar_when_user_code_raises_exception_logs_and_reraises(self) -> N # Arrange actor = KaboomActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -839,6 +888,7 @@ def test_handle_data_when_user_code_raises_exception_logs_and_reraises(self) -> # Arrange actor = KaboomActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -864,6 +914,7 @@ def test_handle_event_when_user_code_raises_exception_logs_and_reraises(self) -> # Arrange actor = KaboomActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -883,6 +934,7 @@ def test_start(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -900,6 +952,7 @@ def test_stop(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -918,6 +971,7 @@ def test_resume(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -938,6 +992,7 @@ def test_reset(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -955,6 +1010,7 @@ def test_dispose(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -974,6 +1030,7 @@ def test_degrade(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -993,6 +1050,7 @@ def test_fault(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1012,6 +1070,7 @@ def test_handle_instrument_with_blow_up_logs_exception(self) -> None: # Arrange actor = KaboomActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1029,6 +1088,7 @@ def test_handle_instrument_when_not_running_does_not_send_to_on_instrument(self) # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1046,6 +1106,7 @@ def test_handle_instrument_when_running_sends_to_on_instrument(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1065,6 +1126,7 @@ def test_handle_instruments_when_running_sends_to_on_instruments(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1084,6 +1146,7 @@ def test_handle_instruments_when_not_running_does_not_send_to_on_instrument(self # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1101,6 +1164,7 @@ def test_handle_ticker_when_not_running_does_not_send_to_on_quote_tick(self) -> # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1120,6 +1184,7 @@ def test_handle_ticker_when_running_sends_to_on_quote_tick(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1141,6 +1206,7 @@ def test_handle_quote_tick_when_not_running_does_not_send_to_on_quote_tick(self) # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1160,6 +1226,7 @@ def test_handle_quote_tick_when_running_sends_to_on_quote_tick(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1181,6 +1248,7 @@ def test_handle_trade_tick_when_not_running_does_not_send_to_on_trade_tick(self) # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1200,6 +1268,7 @@ def test_handle_trade_tick_when_running_sends_to_on_trade_tick(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1221,6 +1290,7 @@ def test_handle_bar_when_not_running_does_not_send_to_on_bar(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1240,6 +1310,7 @@ def test_handle_bar_when_running_sends_to_on_bar(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1261,6 +1332,7 @@ def test_handle_bars(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1283,6 +1355,7 @@ def test_handle_data_when_not_running_does_not_send_to_on_data(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1308,6 +1381,7 @@ def test_handle_data_when_running_sends_to_on_data(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1335,6 +1409,7 @@ def test_add_synthetic_instrument_when_already_exists(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1352,6 +1427,7 @@ def test_add_synthetic_instrument_when_no_synthetic(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1370,6 +1446,7 @@ def test_update_synthetic_instrument_when_no_synthetic(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1386,6 +1463,7 @@ def test_update_synthetic_instrument(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1461,6 +1539,7 @@ def test_cancel_task_when_no_executor(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1476,6 +1555,7 @@ def test_cancel_all_tasks_when_no_executor(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1492,6 +1572,7 @@ def test_run_in_executor_when_no_executor(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1516,6 +1597,7 @@ def test_queue_for_executor_when_no_executor(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1537,6 +1619,7 @@ def test_subscribe_custom_data(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1551,7 +1634,7 @@ def test_subscribe_custom_data(self) -> None: # Assert assert self.data_engine.command_count == 0 assert ( - actor.msgbus.subscriptions()[0].topic + actor.msgbus.subscriptions()[4].topic == "data.NewsEvent.type=NEWS_WIRE.topic=Earthquake" ) @@ -1559,6 +1642,7 @@ def test_subscribe_custom_data_with_client_id(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1573,7 +1657,7 @@ def test_subscribe_custom_data_with_client_id(self) -> None: # Assert assert self.data_engine.command_count == 1 assert ( - actor.msgbus.subscriptions()[0].topic + actor.msgbus.subscriptions()[4].topic == "data.NewsEvent.type=NEWS_WIRE.topic=Earthquake" ) @@ -1581,6 +1665,7 @@ def test_unsubscribe_custom_data(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1595,12 +1680,13 @@ def test_unsubscribe_custom_data(self) -> None: # Assert assert self.data_engine.command_count == 0 - assert actor.msgbus.subscriptions() == [] + assert len(actor.msgbus.subscriptions()) == 4 # Portfolio subscriptions only def test_unsubscribe_custom_data_with_client_id(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1615,12 +1701,13 @@ def test_unsubscribe_custom_data_with_client_id(self) -> None: # Assert assert self.data_engine.command_count == 2 - assert actor.msgbus.subscriptions() == [] + assert len(actor.msgbus.subscriptions()) == 4 # Portfolio subscriptions only def test_subscribe_order_book(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1637,6 +1724,7 @@ def test_unsubscribe_order_book(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1655,6 +1743,7 @@ def test_subscribe_order_book_data(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1671,6 +1760,7 @@ def test_unsubscribe_order_book_deltas(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1689,6 +1779,7 @@ def test_subscribe_instruments(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1710,6 +1801,7 @@ def test_unsubscribe_instruments(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1727,6 +1819,7 @@ def test_subscribe_instrument(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1745,6 +1838,7 @@ def test_unsubscribe_instrument(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1764,6 +1858,7 @@ def test_subscribe_ticker(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1782,6 +1877,7 @@ def test_unsubscribe_ticker(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1801,6 +1897,7 @@ def test_subscribe_quote_ticks(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1819,6 +1916,7 @@ def test_unsubscribe_quote_ticks(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1838,6 +1936,7 @@ def test_subscribe_trade_ticks(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1856,6 +1955,7 @@ def test_unsubscribe_trade_ticks(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1875,6 +1975,7 @@ def test_publish_data_sends_to_subscriber(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1901,6 +2002,7 @@ def test_publish_signal_warns_invalid_type(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1915,6 +2017,7 @@ def test_publish_signal_sends_to_subscriber(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1942,6 +2045,7 @@ def test_publish_data_persist(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1970,6 +2074,7 @@ def test_subscribe_bars(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -1989,6 +2094,7 @@ def test_unsubscribe_bars(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -2010,6 +2116,7 @@ def test_subscribe_venue_status(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -2026,6 +2133,7 @@ def test_request_data_sends_request_to_data_engine(self) -> None: handler: list[NewsEvent] = [] actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -2051,6 +2159,7 @@ def test_request_quote_ticks_sends_request_to_data_engine(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -2071,6 +2180,7 @@ def test_request_quote_ticks_with_registered_callback(self) -> None: handler: list[QuoteTick] = [] actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -2105,6 +2215,7 @@ def test_request_trade_ticks_sends_request_to_data_engine(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -2125,6 +2236,7 @@ def test_request_trade_ticks_with_registered_callback(self) -> None: handler: list[TradeTick] = [] actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -2158,6 +2270,7 @@ def test_request_bars_sends_request_to_data_engine(self) -> None: # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -2180,6 +2293,7 @@ def test_request_bars_with_registered_callback(self) -> None: handler: list[Bar] = [] actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -2222,6 +2336,7 @@ def test_request_bars_with_invalid_params_raises_value_error(self, start, stop): # Arrange actor = MockActor() actor.register_base( + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, diff --git a/tests/unit_tests/execution/test_algorithm.py b/tests/unit_tests/execution/test_algorithm.py index 3a92ec02f3e5..09a6c1cde7fc 100644 --- a/tests/unit_tests/execution/test_algorithm.py +++ b/tests/unit_tests/execution/test_algorithm.py @@ -131,7 +131,7 @@ def setup(self) -> None: ) self.emulator = OrderEmulator( - trader_id=self.trader_id, + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -150,6 +150,7 @@ def setup(self) -> None: instruments=[ETHUSDT_PERP_BINANCE], modules=[], fill_model=FillModel(), + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, diff --git a/tests/unit_tests/execution/test_emulator.py b/tests/unit_tests/execution/test_emulator.py index 512defea1333..8435b74504f6 100644 --- a/tests/unit_tests/execution/test_emulator.py +++ b/tests/unit_tests/execution/test_emulator.py @@ -136,7 +136,7 @@ def setup(self) -> None: ) self.emulator = OrderEmulator( - trader_id=self.trader_id, + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, diff --git a/tests/unit_tests/execution/test_emulator_list.py b/tests/unit_tests/execution/test_emulator_list.py index 112109de8529..f529de735474 100644 --- a/tests/unit_tests/execution/test_emulator_list.py +++ b/tests/unit_tests/execution/test_emulator_list.py @@ -127,7 +127,7 @@ def setup(self) -> None: ) self.emulator = OrderEmulator( - trader_id=self.trader_id, + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -147,6 +147,7 @@ def setup(self) -> None: instruments=[ETHUSDT_PERP_BINANCE], modules=[], fill_model=FillModel(), + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, diff --git a/tests/unit_tests/live/test_execution_engine.py b/tests/unit_tests/live/test_execution_engine.py index 40be75092a16..24331797d73c 100644 --- a/tests/unit_tests/live/test_execution_engine.py +++ b/tests/unit_tests/live/test_execution_engine.py @@ -144,7 +144,7 @@ def setup(self): ) self.emulator = OrderEmulator( - trader_id=self.trader_id, + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, diff --git a/tests/unit_tests/risk/test_engine.py b/tests/unit_tests/risk/test_engine.py index e32d572b2ddc..e63ebf6c9109 100644 --- a/tests/unit_tests/risk/test_engine.py +++ b/tests/unit_tests/risk/test_engine.py @@ -117,7 +117,7 @@ def setup(self): ) self.emulator = OrderEmulator( - trader_id=self.trader_id, + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, @@ -2047,7 +2047,7 @@ def setup(self): ) self.emulator = OrderEmulator( - trader_id=self.trader_id, + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, clock=self.clock, diff --git a/tests/unit_tests/trading/test_strategy.py b/tests/unit_tests/trading/test_strategy.py index 902e5236abf4..73b3d287e02f 100644 --- a/tests/unit_tests/trading/test_strategy.py +++ b/tests/unit_tests/trading/test_strategy.py @@ -132,6 +132,7 @@ def setup(self) -> None: starting_balances=[Money(1_000_000, USD)], default_leverage=Decimal(50), leverages={}, + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, instruments=[USDJPY_SIM], diff --git a/tests/unit_tests/trading/test_trader.py b/tests/unit_tests/trading/test_trader.py index 90e1b03d0baf..96940c5f1891 100644 --- a/tests/unit_tests/trading/test_trader.py +++ b/tests/unit_tests/trading/test_trader.py @@ -103,6 +103,7 @@ def setup(self) -> None: starting_balances=[Money(1_000_000, USD)], default_leverage=Decimal(50), leverages={}, + portfolio=self.portfolio, msgbus=self.msgbus, cache=self.cache, instruments=[USDJPY_SIM],