diff --git a/tests/exchange/test_binance.py b/tests/exchange/test_binance.py index 983a499dd..269b616d3 100644 --- a/tests/exchange/test_binance.py +++ b/tests/exchange/test_binance.py @@ -171,11 +171,12 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side): @pytest.mark.parametrize( - "is_short, trading_mode, margin_mode, wallet_balance, " - "maintenance_amt, amount, open_rate, mark_price, other_contracts," + "pair, is_short, trading_mode, margin_mode, wallet_balance, " + "maintenance_amt, amount, open_rate, mark_price, open_trades," "mm_ratio, expected", [ ( + "ETH/USDT:USDT", False, "futures", "isolated", @@ -189,6 +190,7 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side): 1114.78, ), ( + "ETH/USDT:USDT", False, "futures", "isolated", @@ -202,6 +204,7 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side): 18778.73, ), ( + "ETH/USDT:USDT", False, "futures", "cross", @@ -222,12 +225,23 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side): "mark_price": 31967.27, "mm_ratio": 0.025, "maintenance_amt": 16300.0, - } + }, + { + # From calc example + "pair": "ETH/USDT:USDT", + "open_rate": 1456.84, + "amount": 3683.979, + "stake_amount": 5366967.96, + "mark_price": 1335.18, + "mm_ratio": 0.10, + "maintenance_amt": 135365.00, + }, ], 0.10, 1153.26, ), ( + "BTC/USDT:USDT", False, "futures", "cross", @@ -239,6 +253,16 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side): 32481.980, # open_rate 31967.27, # mark_price [ + { + # From calc example + "pair": "BTC/USDT:USDT", + "open_rate": 32481.98, + "amount": 109.488, + "stake_amount": 3556387.02624, # open_rate * amount + "mark_price": 31967.27, + "mm_ratio": 0.025, + "maintenance_amt": 16300.0, + }, { # From calc example "pair": "ETH/USDT:USDT", @@ -248,7 +272,7 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side): "mark_price": 1335.18, "mm_ratio": 0.10, "maintenance_amt": 135365.00, - } + }, ], 0.025, 26316.89, @@ -258,6 +282,7 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side): def test_liquidation_price_binance( mocker, default_conf, + pair, is_short, trading_mode, margin_mode, @@ -266,7 +291,7 @@ def test_liquidation_price_binance( amount, open_rate, mark_price, - other_contracts, + open_trades, mm_ratio, expected, ): @@ -275,9 +300,9 @@ def test_liquidation_price_binance( default_conf["liquidation_buffer"] = 0.0 exchange = get_patched_exchange(mocker, default_conf, exchange="binance") - def get_maint_ratio(pair, stake_amount): - if pair != "DOGE/USDT": - oc = [c for c in other_contracts if c["pair"] == pair][0] + def get_maint_ratio(pair_, stake_amount): + if pair_ != pair: + oc = [c for c in open_trades if c["pair"] == pair_][0] return oc["mm_ratio"], oc["maintenance_amt"] return mm_ratio, maintenance_amt @@ -286,14 +311,14 @@ def test_liquidation_price_binance( pytest.approx( round( exchange.get_liquidation_price( - pair="DOGE/USDT", + pair=pair, open_rate=open_rate, is_short=is_short, wallet_balance=wallet_balance, amount=amount, stake_amount=open_rate * amount, leverage=5, - other_trades=other_contracts, + open_trades=open_trades, ), 2, )