From 1b7056853b12f5534f65d205174efca1b6e486cc Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 24 Aug 2024 18:06:08 +0200 Subject: [PATCH] refactor: move test_liquidation_price_binance to binance test file --- tests/exchange/test_binance.py | 105 ++++++++++++++++++++++++++++++++ tests/exchange/test_exchange.py | 105 -------------------------------- 2 files changed, 105 insertions(+), 105 deletions(-) diff --git a/tests/exchange/test_binance.py b/tests/exchange/test_binance.py index a5f9ea654c5..0ae1d6e20f8 100644 --- a/tests/exchange/test_binance.py +++ b/tests/exchange/test_binance.py @@ -170,6 +170,111 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side): assert not exchange.stoploss_adjust(sl2, order, side=side) +@pytest.mark.parametrize( + "exchange_name, is_short, trading_mode, margin_mode, wallet_balance, " + "mm_ex_1, upnl_ex_1, maintenance_amt, amount, open_rate, " + "mm_ratio, expected", + [ + ( + "binance", + False, + "futures", + "isolated", + 1535443.01, + 0.0, + 0.0, + 135365.00, + 3683.979, + 1456.84, + 0.10, + 1114.78, + ), + ( + "binance", + False, + "futures", + "isolated", + 1535443.01, + 0.0, + 0.0, + 16300.000, + 109.488, + 32481.980, + 0.025, + 18778.73, + ), + ( + "binance", + False, + "futures", + "cross", + 1535443.01, + 71200.81144, + -56354.57, + 135365.00, + 3683.979, + 1456.84, + 0.10, + 1153.26, + ), + ( + "binance", + False, + "futures", + "cross", + 1535443.01, + 356512.508, + -448192.89, + 16300.000, + 109.488, + 32481.980, + 0.025, + 26316.89, + ), + ], +) +def test_liquidation_price_binance( + mocker, + default_conf, + exchange_name, + open_rate, + is_short, + trading_mode, + margin_mode, + wallet_balance, + mm_ex_1, + upnl_ex_1, + maintenance_amt, + amount, + mm_ratio, + expected, +): + default_conf["trading_mode"] = trading_mode + default_conf["margin_mode"] = margin_mode + default_conf["liquidation_buffer"] = 0.0 + exchange = get_patched_exchange(mocker, default_conf, exchange=exchange_name) + exchange.get_maintenance_ratio_and_amt = MagicMock(return_value=(mm_ratio, maintenance_amt)) + assert ( + pytest.approx( + round( + exchange.get_liquidation_price( + pair="DOGE/USDT", + open_rate=open_rate, + is_short=is_short, + wallet_balance=wallet_balance, + mm_ex_1=mm_ex_1, + upnl_ex_1=upnl_ex_1, + amount=amount, + stake_amount=open_rate * amount, + leverage=5, + ), + 2, + ) + ) + == expected + ) + + def test_fill_leverage_tiers_binance(default_conf, mocker): api_mock = MagicMock() api_mock.fetch_leverage_tiers = MagicMock( diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 1e43cf51b14..2e99ddcded5 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -5667,111 +5667,6 @@ def test_liquidation_price_is_none( ) -@pytest.mark.parametrize( - "exchange_name, is_short, trading_mode, margin_mode, wallet_balance, " - "mm_ex_1, upnl_ex_1, maintenance_amt, amount, open_rate, " - "mm_ratio, expected", - [ - ( - "binance", - False, - "futures", - "isolated", - 1535443.01, - 0.0, - 0.0, - 135365.00, - 3683.979, - 1456.84, - 0.10, - 1114.78, - ), - ( - "binance", - False, - "futures", - "isolated", - 1535443.01, - 0.0, - 0.0, - 16300.000, - 109.488, - 32481.980, - 0.025, - 18778.73, - ), - ( - "binance", - False, - "futures", - "cross", - 1535443.01, - 71200.81144, - -56354.57, - 135365.00, - 3683.979, - 1456.84, - 0.10, - 1153.26, - ), - ( - "binance", - False, - "futures", - "cross", - 1535443.01, - 356512.508, - -448192.89, - 16300.000, - 109.488, - 32481.980, - 0.025, - 26316.89, - ), - ], -) -def test_liquidation_price_binance( - mocker, - default_conf, - exchange_name, - open_rate, - is_short, - trading_mode, - margin_mode, - wallet_balance, - mm_ex_1, - upnl_ex_1, - maintenance_amt, - amount, - mm_ratio, - expected, -): - default_conf["trading_mode"] = trading_mode - default_conf["margin_mode"] = margin_mode - default_conf["liquidation_buffer"] = 0.0 - exchange = get_patched_exchange(mocker, default_conf, exchange=exchange_name) - exchange.get_maintenance_ratio_and_amt = MagicMock(return_value=(mm_ratio, maintenance_amt)) - assert ( - pytest.approx( - round( - exchange.get_liquidation_price( - pair="DOGE/USDT", - open_rate=open_rate, - is_short=is_short, - wallet_balance=wallet_balance, - mm_ex_1=mm_ex_1, - upnl_ex_1=upnl_ex_1, - amount=amount, - stake_amount=open_rate * amount, - leverage=5, - ), - 2, - ) - ) - == expected - ) - - def test_get_max_pair_stake_amount( mocker, default_conf,