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() == []
Exemplo n.º 2
0
    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()
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
    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
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    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")]
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
    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
Exemplo n.º 13
0
    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
Exemplo n.º 14
0
    def test_create_from_path(self):
        # Arrange
        config = ActorConfig(component_id="MyActor", )
        importable = ImportableActorConfig(
            path="tests.test_kit.mocks.actors:MockActor",
            config=config,
        )

        # Act
        strategy = ActorFactory.create(importable)

        # Assert
        assert isinstance(strategy, MockActor)
        assert repr(config) == "ActorConfig(component_id='MyActor')"
Exemplo n.º 15
0
    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
Exemplo n.º 16
0
    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()
Exemplo n.º 17
0
    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
Exemplo n.º 18
0
    def test_register_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,
        )

        # Act
        actor.register_warning_event(OrderDenied)

        # Assert
        assert True  # Exception not raised
Exemplo n.º 19
0
    def test_create_from_source(self):
        # Arrange
        config = ActorConfig(component_id="MyActor", )

        source = pkgutil.get_data("tests.test_kit", "mocks.py")
        importable = ImportableActorConfig(
            module="MockActor",
            source=source,
            config=config,
        )

        # Act
        strategy = ActorFactory.create(importable)

        # Assert
        assert isinstance(strategy, MockActor)
        assert repr(config) == "ActorConfig()"
Exemplo n.º 20
0
    def test_id(self):
        # Arrange, Act
        actor = Actor(config=ActorConfig(component_id=self.component_id))

        # Assert
        assert actor.id == ComponentId(self.component_id)