def test_fault_when_not_initialized_raises_invalid_state_trigger(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) # Act, Assert with pytest.raises(InvalidStateTrigger): actor.fault()
def test_on_event_when_not_overridden_does_nothing(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) # Act actor.on_event(TestEventStubs.cash_account_state()) # Assert assert True # Exception not raised
def test_on_order_book_delta_when_not_overridden_does_nothing(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) # Act actor.on_order_book_delta(TestDataStubs.order_book_snapshot()) # Assert assert True # Exception not raised
def test_on_instrument_when_not_overridden_does_nothing(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) # Act actor.on_instrument(TestInstrumentProvider.btcusdt_binance()) # Assert assert True # Exception not raised
def test_on_fault_when_not_overridden_does_nothing(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) # Act actor.on_fault() # Assert assert True # Exception not raised
def test_on_venue_status_update_when_not_overridden_does_nothing(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) # Act actor.on_venue_status_update(TestDataStubs.venue_status_update()) # Assert assert True # Exception not raised
def test_on_ticker_when_not_overridden_does_nothing(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) # Act actor.on_ticker(TestDataStubs.ticker()) # Assert assert True # Exception not raised
def test_handle_event(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) event = TestEventStubs.cash_account_state() # Act actor.handle_event(event) # Assert assert True # Exception not raised
def test_on_trade_tick_when_not_overridden_does_nothing(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) tick = TestDataStubs.trade_tick_5decimal() # Act actor.on_trade_tick(tick) # Assert assert True # Exception not raised
def test_on_bar_when_not_overridden_does_nothing(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) bar = TestDataStubs.bar_5decimal() # Act actor.on_bar(bar) # Assert assert True # Exception not raised
def test_clear_actors(self): # Arrange actors = [ Actor(ActorConfig(component_id="MyPlugin-01")), Actor(ActorConfig(component_id="MyPlugin-02")), ] self.trader.add_actors(actors) # Act self.trader.clear_actors() # Assert assert self.trader.actor_ids() == []
def test_initialization(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( trader_id=self.trader_id, msgbus=self.msgbus, cache=self.cache, clock=self.clock, logger=self.logger, ) # Act, Assert assert actor.state == ComponentState.INITIALIZED assert actor.is_initialized
def test_pre_initialization(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) # Act, Assert assert actor.state == ComponentState.PRE_INITIALIZED assert not actor.is_initialized
def test_on_data_when_not_overridden_does_nothing(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) news_event = NewsEvent( impact=NewsImpact.HIGH, name="Unemployment Rate", currency=EUR, ts_event=0, ts_init=0, ) # Act actor.on_data(news_event) # Assert assert True # Exception not raised
def test_add_actor(self): # Arrange config = ActorConfig(component_id="MyPlugin-01") actor = Actor(config) # Act self.trader.add_actor(actor) # Assert assert self.trader.actor_ids() == [ComponentId("MyPlugin-01")]
def test_deregister_warning_event(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) actor.register_base( trader_id=self.trader_id, msgbus=self.msgbus, cache=self.cache, clock=self.clock, logger=self.logger, ) actor.register_warning_event(OrderDenied) # Act actor.deregister_warning_event(OrderDenied) # Assert assert True # Exception not raised
def test_stop_when_not_initialized_raises_invalid_state_trigger(self): # Arrange actor = Actor(config=ActorConfig(component_id=self.component_id)) try: actor.start() except InvalidStateTrigger: # Normally a bad practice but allows strategy to be put into # the needed state to run the test. pass # Act, Assert with pytest.raises(InvalidStateTrigger): actor.stop()
def test_actor_fully_qualified_name(self): # Arrange, Act, Assert assert Actor.fully_qualified_name( ) == "nautilus_trader.common.actor.Actor"
def test_id(self): # Arrange, Act actor = Actor(config=ActorConfig(component_id=self.component_id)) # Assert assert actor.id == ComponentId(self.component_id)