Ejemplo n.º 1
0
    def test_closed(self):
        fr = FrameFactory()

        next_frame = FrameFactory()
        fr.next_frame = next_frame

        assert fr.closed is True
Ejemplo n.º 2
0
    def test_update_last_tick(self):
        tick = TickFactory()
        fr = FrameFactory()

        fr.on_new_tick(tick)

        assert fr.last_tick == tick
Ejemplo n.º 3
0
    def test_update_high_tick(self):
        fr = FrameFactory()
        fr.high_tick = TickFactory(bid=99, ask=101)

        new_high = TickFactory(bid=100, ask=102)
        fr.on_new_tick(new_high)

        assert fr.high_tick == new_high
Ejemplo n.º 4
0
    def test_update_low_tick(self):
        fr = FrameFactory()
        fr.low_tick = TickFactory(bid=99, ask=101)

        new_low = TickFactory(bid=98, ask=100)
        fr.on_new_tick(new_low)

        assert fr.low_tick == new_low
Ejemplo n.º 5
0
    def test_indicators_on_new_tick_called__indicator_none(
            self, mocker, market_open):
        epic_mock = mocker.Mock()
        epic_mock.market_open = market_open
        parent_framset = FrameSetFactory()
        indicator_mock = mocker.Mock()
        indicator_mock.ref = "my_indicator_ref"
        parent_framset.epic = epic_mock
        parent_framset.add_indicator(indicator_mock)
        fr = FrameFactory(parent_frameset=parent_framset)
        fr.indicators = {"my_indicator_ref": None}

        tick = TickFactory()
        fr.on_new_tick(tick)

        assert indicator_mock.build_value_from_frame.call_args_list == [
            call(fr, market_open),  # call on Frame Init
            call(fr, market_open),
        ]
Ejemplo n.º 6
0
    def test_base_indicator_value_call(self, mocker):
        init_mock = mocker.patch.object(
            BaseIndicatorValue, "__init__", wraps=BaseIndicatorValue.__init__
        )

        frame_mock = FrameFactory()
        rsi = RSIFactory()
        rsi.rsi_periods = 5
        rsiv = RSIValue(frame=frame_mock, indicator=rsi)

        assert init_mock.call_args_list == [call(rsiv, frame=frame_mock, indicator=rsi)]
Ejemplo n.º 7
0
    def test_indicators_not_empty(self, mocker):
        epic_mock = mocker.Mock()
        epic_mock.market_open = True
        parent_framset = FrameSetFactory()
        indicator_mock = mocker.Mock()
        indicator_mock.ref = "my_indicator_ref"
        indicator_mock.build_value_from_frame.return_value = "indicator_value"
        parent_framset.epic = epic_mock
        parent_framset.add_indicator(indicator_mock)
        fr = FrameFactory(parent_frameset=parent_framset)

        assert fr.indicators == {"my_indicator_ref": "indicator_value"}
Ejemplo n.º 8
0
    def test_create_new_frame_call__gap(self, mocker):
        fs = FrameSetFactory(unit=Unit.SECOND, unit_quantity=10)
        create_new_frame_mock = mocker.patch.object(fs,
                                                    "create_new_frame",
                                                    wraps=fs.create_new_frame)
        current_last_tick = TickFactory()
        current_frame = FrameFactory(
            first_tick=current_last_tick,
            period_start=arrow.get("2020-01-01 12:34:10"),
            period_end=arrow.get("2020-01-01 12:34:20"),
        )
        fs.frames = [current_frame]

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

        assert create_new_frame_mock.call_args_list == [
            call(
                current_last_tick,
                arrow.get("2020-01-01 12:34:20"),
                arrow.get("2020-01-01 12:34:30"),
            ),
            call(
                current_last_tick,
                arrow.get("2020-01-01 12:34:30"),
                arrow.get("2020-01-01 12:34:40"),
            ),
            call(
                current_last_tick,
                arrow.get("2020-01-01 12:34:40"),
                arrow.get("2020-01-01 12:34:50"),
            ),
            call(
                new_tick,
                arrow.get("2020-01-01 12:34:50"),
                arrow.get("2020-01-01 12:35:00"),
            ),
        ]
Ejemplo n.º 9
0
    def test_period_start(self):
        period_start = arrow.utcnow()

        fr = FrameFactory(period_start=period_start)

        assert fr.period_start == period_start
Ejemplo n.º 10
0
    def test_indicators__no_indicators(self):
        fr = FrameFactory()

        assert fr.indicators == {}
Ejemplo n.º 11
0
    def test_low_tick__default(self):
        tick = TickFactory()

        fr = FrameFactory(first_tick=tick)

        assert fr.low_tick == tick
Ejemplo n.º 12
0
    def test_nb_ticks__default(self):
        fr = FrameFactory()

        assert fr.nb_ticks == 1
Ejemplo n.º 13
0
    def test_previous_frame__manual(self):
        previous_frame = FrameFactory()

        fr = FrameFactory(previous_frame=previous_frame)

        assert fr.previous_frame == previous_frame
Ejemplo n.º 14
0
    def test_previous_frame__default(self):
        fr = FrameFactory()

        assert fr.previous_frame is None
Ejemplo n.º 15
0
    def test_period_end__manual(self):
        period_end = arrow.utcnow()

        fr = FrameFactory(period_end=period_end)

        assert fr.period_end == period_end
Ejemplo n.º 16
0
    def test_period_end__default(self):
        fr = FrameFactory()

        assert fr.period_end is None
Ejemplo n.º 17
0
    def test_resistance3(self):
        bpt = BasePivotType(indicator="test", frame=FrameFactory())

        with pytest.raises(NotImplementedError):
            bpt.resistance3
Ejemplo n.º 18
0
    def test_not_closed(self):
        fr = FrameFactory()

        assert fr.closed is False
Ejemplo n.º 19
0
    def test_frame(self):
        fr = FrameFactory()
        biv = BaseIndicatorValueFactory(frame=fr)

        assert biv.frame == fr
Ejemplo n.º 20
0
    def test_first_tick(self):
        tick = TickFactory()

        fr = FrameFactory(first_tick=tick)

        assert fr.first_tick == tick
Ejemplo n.º 21
0
    def test_nb_ticks_update(self):
        fr = FrameFactory()

        fr.on_new_tick(TickFactory())

        assert fr.nb_ticks == 2
Ejemplo n.º 22
0
    def test_exists(self):
        fs = FrameSetFactory()
        last_frame = FrameFactory()
        fs.frames = ["first", last_frame]

        assert fs.current == last_frame
Ejemplo n.º 23
0
    def test_get_not_existing(self):
        fr = FrameFactory()

        assert fr["undefined"] is None
Ejemplo n.º 24
0
    def test_existing(self):
        fr = FrameFactory()

        fr.indicators["test_indicator"] = "test"

        assert fr["test_indicator"] == "test"
Ejemplo n.º 25
0
    def test_support2(self):
        bpt = BasePivotType(indicator="test", frame=FrameFactory())

        with pytest.raises(NotImplementedError):
            bpt.support2