Fix non-testing liquidation test

This commit is contained in:
Matthias 2022-08-29 21:04:09 +02:00
parent efc3b39fb8
commit eee2071e32

View File

@ -5023,7 +5023,7 @@ def test_get_liquidation_price1(mocker, default_conf):
) )
@pytest.mark.parametrize('liquidation_buffer', [0.0, 0.05]) @pytest.mark.parametrize('liquidation_buffer', [0.0, 0.05])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"is_short,trading_mode,exchange_name,margin_mode,leverage,open_rate,amount,expected_liq", [ "is_short,trading_mode,exchange_name,margin_mode,leverage,open_rate,amount,expected_liq", [
(False, 'spot', 'binance', '', 5.0, 10.0, 1.0, None), (False, 'spot', 'binance', '', 5.0, 10.0, 1.0, None),
@ -5036,20 +5036,22 @@ def test_get_liquidation_price1(mocker, default_conf):
(True, 'futures', 'binance', 'isolated', 5.0, 10.0, 1.0, 11.89108910891089), (True, 'futures', 'binance', 'isolated', 5.0, 10.0, 1.0, 11.89108910891089),
(True, 'futures', 'binance', 'isolated', 3.0, 10.0, 1.0, 13.211221122079207), (True, 'futures', 'binance', 'isolated', 3.0, 10.0, 1.0, 13.211221122079207),
(True, 'futures', 'binance', 'isolated', 5.0, 8.0, 1.0, 9.514851485148514), (True, 'futures', 'binance', 'isolated', 5.0, 8.0, 1.0, 9.514851485148514),
(True, 'futures', 'binance', 'isolated', 5.0, 10.0, 0.6, 12.557755775577558), (True, 'futures', 'binance', 'isolated', 5.0, 10.0, 0.6, 11.897689768976898),
# Binance, long # Binance, long
(False, 'futures', 'binance', 'isolated', 5, 10, 1.0, 8.070707070707071), (False, 'futures', 'binance', 'isolated', 5, 10, 1.0, 8.070707070707071),
(False, 'futures', 'binance', 'isolated', 5, 8, 1.0, 6.454545454545454), (False, 'futures', 'binance', 'isolated', 5, 8, 1.0, 6.454545454545454),
(False, 'futures', 'binance', 'isolated', 3, 10, 1.0, 6.717171717171718), (False, 'futures', 'binance', 'isolated', 3, 10, 1.0, 6.723905723905723),
(False, 'futures', 'binance', 'isolated', 5, 10, 0.6, 7.39057239057239), (False, 'futures', 'binance', 'isolated', 5, 10, 0.6, 8.063973063973064),
# Gateio/okx, short # Gateio/okx, short
(True, 'futures', 'gateio', 'isolated', 5, 10, 1.0, 11.87413417771621), (True, 'futures', 'gateio', 'isolated', 5, 10, 1.0, 11.89108910891089),
(True, 'futures', 'gateio', 'isolated', 5, 10, 2.0, 11.87413417771621), (True, 'futures', 'gateio', 'isolated', 5, 10, 2.0, 11.886138613861386),
(True, 'futures', 'gateio', 'isolated', 3, 10, 1.0, 13.476180850346978), (True, 'futures', 'gateio', 'isolated', 3, 10, 1.0, 13.211221122112212),
(True, 'futures', 'gateio', 'isolated', 5, 8, 1.0, 9.499307342172967), (True, 'futures', 'gateio', 'isolated', 5, 8, 1.0, 9.514851485148514),
# Gateio/okx, long # Gateio/okx, long
(False, 'futures', 'gateio', 'isolated', 5.0, 10.0, 1.0, 8.085708510208207), (False, 'futures', 'gateio', 'isolated', 5.0, 10.0, 1.0, 8.070707070707071),
(False, 'futures', 'gateio', 'isolated', 3.0, 10.0, 1.0, 6.738090425173506), (False, 'futures', 'gateio', 'isolated', 3.0, 10.0, 1.0, 6.723905723905723),
(True, 'futures', 'okx', 'isolated', 5, 8, 1.0, 9.514851485148514),
(False, 'futures', 'okx', 'isolated', 3.0, 10.0, 1.0, 6.723905723905723),
# (True, 'futures', 'okx', 'isolated', 11.87413417771621), # (True, 'futures', 'okx', 'isolated', 11.87413417771621),
# (False, 'futures', 'okx', 'isolated', 8.085708510208207), # (False, 'futures', 'okx', 'isolated', 8.085708510208207),
] ]
@ -5135,7 +5137,8 @@ def test_get_liquidation_price(
pair='ETH/USDT:USDT', pair='ETH/USDT:USDT',
open_rate=open_rate, open_rate=open_rate,
amount=amount, amount=amount,
stake_amount=amount * open_rate / leverage, stake_amount=(amount * open_rate) / leverage,
wallet_balance=(amount * open_rate) / leverage,
# leverage=leverage, # leverage=leverage,
is_short=is_short, is_short=is_short,
) )
@ -5144,7 +5147,7 @@ def test_get_liquidation_price(
else: else:
buffer_amount = liquidation_buffer * abs(open_rate - expected_liq) buffer_amount = liquidation_buffer * abs(open_rate - expected_liq)
expected_liq = expected_liq - buffer_amount if is_short else expected_liq + buffer_amount expected_liq = expected_liq - buffer_amount if is_short else expected_liq + buffer_amount
isclose(expected_liq, liq) assert pytest.approx(expected_liq) == liq
@pytest.mark.parametrize('contract_size,order_amount', [ @pytest.mark.parametrize('contract_size,order_amount', [