Esempio n. 1
0
        def test_kwargs(self, mock_init_trade):
            default_trade_args, _ = TradeFactory.get_default_args()
            Trade.open_from_tick(tick=TickFactory(),
                                 ref="test",
                                 **default_trade_args)

            assert mock_init_trade.call_count == 1
            assert mock_init_trade.call_args_list[0][1]["ref"] == "test"
Esempio n. 2
0
        def test_epic(self, mock_init_trade):
            tick = TickFactory()
            default_trade_args, _ = TradeFactory.get_default_args()

            Trade.open_from_tick(tick=tick, **default_trade_args)

            assert mock_init_trade.call_count == 1
            assert (mock_init_trade.call_args_list[0][1]["epic"] ==
                    default_trade_args["epic"])
Esempio n. 3
0
        def test_open_datetime(self, mock_init_trade):
            tick_datetime = arrow.get("2020-01-01 12:34:56")
            tick = TickFactory(datetime=tick_datetime)

            default_trade_args, _ = TradeFactory.get_default_args()
            Trade.open_from_tick(tick=tick, **default_trade_args)

            assert mock_init_trade.call_count == 1
            assert (mock_init_trade.call_args_list[0][1]["open_datetime"] ==
                    tick_datetime)
Esempio n. 4
0
        def test_valid_epic(self, mock_trade_open_from_tick):
            epic = EpicFactory()

            default_trade_args, _ = TradeFactory.get_default_args()
            default_trade_args["epic"] = epic

            Trade.open_from_epic(**default_trade_args)

            assert mock_trade_open_from_tick.call_args_list == [
                call(tick=epic.last_tick, **default_trade_args)
            ]
Esempio n. 5
0
        def test_direction(
            self,
            mock_init_trade,
            direction,
            bid,
            ask,
            expected_open,
            expected_current,
        ):

            tick_datetime = arrow.get("2020-01-01 12:34:56")
            tick = TickFactory(bid=bid, ask=ask, datetime=tick_datetime)
            default_trade_args, _ = TradeFactory.get_default_args()
            default_trade_args["direction"] = direction
            Trade.open_from_tick(tick=tick, **default_trade_args)

            assert mock_init_trade.call_count == 1
            assert mock_init_trade.call_args_list[0][1][
                "direction"] == direction
            assert mock_init_trade.call_args_list[0][1][
                "open_value"] == expected_open
            assert (mock_init_trade.call_args_list[0][1]["current_close_value"]
                    == expected_current)
Esempio n. 6
0
 def test_invalid_direction(self):
     tick = TickFactory()
     default_trade_args, _ = TradeFactory.get_default_args()
     default_trade_args["direction"] = "invalid"
     with pytest.raises(TradeException):
         Trade.open_from_tick(tick=tick, **default_trade_args)