From 35607ae03b0fc168d55be1f7d0262882d260edec Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 19 Mar 2022 14:54:36 +0100 Subject: [PATCH] Add test for min_leverage --- tests/test_freqtradebot.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 637cae83f..6e8b1afbf 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -996,6 +996,36 @@ def test_execute_entry_confirm_error(mocker, default_conf_usdt, fee, limit_order assert not freqtrade.execute_entry(pair, stake_amount) +@pytest.mark.parametrize("is_short", [False, True]) +def test_execute_entry_min_leverage(mocker, default_conf_usdt, fee, limit_order, is_short) -> None: + default_conf_usdt['trading_mode'] = 'futures' + default_conf_usdt['margin_mode'] = 'isolated' + freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt) + mocker.patch.multiple( + 'freqtrade.exchange.Exchange', + fetch_ticker=MagicMock(return_value={ + 'bid': 1.9, + 'ask': 2.2, + 'last': 1.9 + }), + create_order=MagicMock(return_value=limit_order[enter_side(is_short)]), + get_rate=MagicMock(return_value=0.11), + # Minimum stake-amount is ~5$ + get_maintenance_ratio_and_amt=MagicMock(return_value=(0.0, 0.0)), + _fetch_and_calculate_funding_fees=MagicMock(return_value=0), + get_fee=fee, + get_max_leverage=MagicMock(return_value=5.0), + ) + stake_amount = 2 + pair = 'SOL/BUSD:BUSD' + freqtrade.strategy.leverage = MagicMock(return_value=5.0) + + assert freqtrade.execute_entry(pair, stake_amount, is_short=is_short) + trade = Trade.query.first() + assert trade.leverage == 5.0 + # assert trade.stake_amount == 2 + + @pytest.mark.parametrize("is_short", [False, True]) def test_add_stoploss_on_exchange(mocker, default_conf_usdt, limit_order, is_short) -> None: patch_RPCManager(mocker)