Example #1
0
    def test_handle_data_when_running_sends_to_on_data(self):
        # Arrange
        actor = MockActor()
        actor.register_base(
            trader_id=self.trader_id,
            msgbus=self.msgbus,
            cache=self.cache,
            clock=self.clock,
            logger=self.logger,
        )

        actor.start()

        data = NewsEvent(
            impact=NewsImpact.HIGH,
            name="Unemployment Rate",
            currency=USD,
            ts_event=0,
            ts_init=0,
        )

        # Act
        actor.handle_data(data)

        # Assert
        assert actor.calls == ["on_start", "on_data"]
        assert actor.object_storer.get_store()[0] == data
Example #2
0
    def test_start(self):
        # Arrange
        actor = MockActor()
        actor.register_base(
            trader_id=self.trader_id,
            msgbus=self.msgbus,
            cache=self.cache,
            clock=self.clock,
            logger=self.logger,
        )

        # Act
        actor.start()

        # Assert
        assert "on_start" in actor.calls
        assert actor.state == ComponentState.RUNNING
Example #3
0
    def test_handle_instrument_when_running_sends_to_on_instrument(self):
        # Arrange
        actor = MockActor()
        actor.register_base(
            trader_id=self.trader_id,
            msgbus=self.msgbus,
            cache=self.cache,
            clock=self.clock,
            logger=self.logger,
        )

        actor.start()

        # Act
        actor.handle_instrument(AUDUSD_SIM)

        # Assert
        assert actor.calls == ["on_start", "on_instrument"]
        assert actor.object_storer.get_store()[0] == AUDUSD_SIM
Example #4
0
    def test_handle_trade_tick_when_running_sends_to_on_trade_tick(self):
        # Arrange
        actor = MockActor()
        actor.register_base(
            trader_id=self.trader_id,
            msgbus=self.msgbus,
            cache=self.cache,
            clock=self.clock,
            logger=self.logger,
        )

        actor.start()

        tick = TestStubs.trade_tick_5decimal(AUDUSD_SIM.id)

        # Act
        actor.handle_trade_tick(tick)

        # Assert
        assert actor.calls == ["on_start", "on_trade_tick"]
        assert actor.object_storer.get_store()[0] == tick
Example #5
0
    def test_handle_bar_when_running_sends_to_on_bar(self):
        # Arrange
        actor = MockActor()
        actor.register_base(
            trader_id=self.trader_id,
            msgbus=self.msgbus,
            cache=self.cache,
            clock=self.clock,
            logger=self.logger,
        )

        actor.start()

        bar = TestStubs.bar_5decimal()

        # Act
        actor.handle_bar(bar)

        # Assert
        assert actor.calls == ["on_start", "on_bar"]
        assert actor.object_storer.get_store()[0] == bar