Ejemplo n.º 1
0
    def test_anterior_tick(self):
        epic = EpicFactory()
        last_tick = TickFactory(datetime=arrow.get("2020-01-01 12:34:56"))
        epic.last_tick = last_tick

        new_tick = TickFactory(datetime=arrow.get("2020-01-01 12:34:55"))

        with pytest.raises(EpicException):
            epic.on_new_tick(new_tick)
Ejemplo n.º 2
0
    def test_update_frame_sets(self, mocker):
        epic = EpicFactory()

        frame_set_mock = mocker.Mock()
        epic.frame_sets["test"] = frame_set_mock

        new_tick = TickFactory()

        epic.on_new_tick(new_tick)

        assert frame_set_mock.on_new_tick.call_args_list == [call(new_tick)]
Ejemplo n.º 3
0
    def test_update_trades(self, mocker):
        epic = EpicFactory()

        trade = TradeFactory(direction=TradeDirection.BUY, quantity=4, epic=epic)
        epic.trade_provider.open_trade(trade)
        trade_update_mock = mocker.patch.object(trade, "update_from_tick")

        new_tick = TickFactory()
        epic.on_new_tick(new_tick)

        assert trade_update_mock.call_args_list == [call(new_tick)]
Ejemplo n.º 4
0
    def test_convert_tick_datetime(self):
        epic = EpicFactory(timezone="Asia/Tokyo")

        tz_NY = pytz.timezone("America/New_York")
        datetime_NY = datetime.now(tz_NY)
        tick = TickFactory(datetime=datetime_NY)

        epic.on_new_tick(tick)

        # datetime is converted to epic timezone
        assert epic.last_tick.datetime.tzinfo == tz.gettz(epic.timezone)
Ejemplo n.º 5
0
    def test_update_strategies_call_on_every_tick__inactive_strategy(self, mocker):
        epic = EpicFactory()

        strategy_mock = mocker.Mock(spec=BaseStrategy)
        strategy_mock.is_active.return_value = False
        epic.strategies["test"] = strategy_mock

        new_tick = TickFactory()

        epic.on_new_tick(new_tick)

        assert strategy_mock.on_every_tick.call_args_list == []
Ejemplo n.º 6
0
    def test_update_strategies_call_on_market_open__nominal(self, mocker):
        mocker.patch(f"{CLASS_DEFINITION_PATH}.is_market_open", return_value=True)
        epic = EpicFactory()
        epic.market_open = False

        strategy_mock = mocker.Mock(spec=BaseStrategy)
        strategy_mock.is_active.return_value = True
        epic.strategies["test"] = strategy_mock

        new_tick = TickFactory()

        epic.on_new_tick(new_tick)

        assert strategy_mock.on_market_open.call_args_list == [call(epic)]
Ejemplo n.º 7
0
    def test_update_strategies_call_on_market_open__no_call_expected(
        self,
        mocker,
        market_open_before_tick,
        market_open_after_tick,
        strategy_is_active,
    ):
        mocker.patch(
            f"{CLASS_DEFINITION_PATH}.is_market_open",
            return_value=market_open_after_tick,
        )
        epic = EpicFactory()
        epic.market_open = market_open_before_tick

        strategy_mock = mocker.Mock(spec=BaseStrategy)
        strategy_mock.is_active.return_value = strategy_is_active
        epic.strategies["test"] = strategy_mock

        new_tick = TickFactory()

        epic.on_new_tick(new_tick)

        assert strategy_mock.on_market_open.call_args_list == []
Ejemplo n.º 8
0
    def test_update_last_tick(self):
        epic = EpicFactory()
        tick = TickFactory()
        epic.on_new_tick(tick)

        assert epic.last_tick == tick
Ejemplo n.º 9
0
    def test_in_holidays(self):
        tick = TickFactory(datetime=arrow.get("2020-01-01 12:00:00"))
        epic = EpicFactory(holidays=[date(2020, 1, 1)])
        epic.on_new_tick(tick)

        assert epic.market_open is False
Ejemplo n.º 10
0
    def test_out_of_trade_days(self):
        tick = TickFactory(datetime=arrow.get("2020-01-01 12:00:00"))
        epic = EpicFactory(trade_days=[0, 1, 3, 4, 5])
        epic.on_new_tick(tick)

        assert epic.market_open is False
Ejemplo n.º 11
0
    def test_after_close(self):
        tick = TickFactory(datetime=arrow.get("2020-01-01 18:01:00"))
        epic = EpicFactory(close_time=time(18, 0))
        epic.on_new_tick(tick)

        assert epic.market_open is False
Ejemplo n.º 12
0
    def test_before_open(self):
        tick = TickFactory(datetime=arrow.get("2020-01-01 08:59:59"))
        epic = EpicFactory(open_time=time(9, 0))
        epic.on_new_tick(tick)

        assert epic.market_open is False
Ejemplo n.º 13
0
    def test_nominal(self):
        tick = TickFactory(datetime=arrow.get("2020-01-01 12:00:00"))
        epic = EpicFactory()
        epic.on_new_tick(tick)

        assert epic.market_open is True