exchange.liquidation_price methods combined, dry_run check on exchange for liquidation price

This commit is contained in:
Sam Germain
2022-01-29 18:47:17 -06:00
parent 143c37d36f
commit b8f4cebce7
8 changed files with 140 additions and 124 deletions

View File

@@ -3975,13 +3975,13 @@ def test__amount_to_contracts(
@pytest.mark.parametrize('exchange_name,open_rate,is_short,leverage,trading_mode,collateral', [
# Bittrex
('bittrex', 2.0, False, 3.0, spot, None),
('bittrex', 2.0, False, 1.0, spot, cross),
('bittrex', 2.0, True, 3.0, spot, isolated),
('bittrex', 2.0, False, 3.0, 'spot', None),
('bittrex', 2.0, False, 1.0, 'spot', 'cross'),
('bittrex', 2.0, True, 3.0, 'spot', 'isolated'),
# Binance
('binance', 2.0, False, 3.0, spot, None),
('binance', 2.0, False, 1.0, spot, cross),
('binance', 2.0, True, 3.0, spot, isolated),
('binance', 2.0, False, 3.0, 'spot', None),
('binance', 2.0, False, 1.0, 'spot', 'cross'),
('binance', 2.0, True, 3.0, 'spot', 'isolated'),
])
def test_liquidation_price_is_none(
mocker,
@@ -3996,14 +3996,12 @@ def test_liquidation_price_is_none(
default_conf['trading_mode'] = trading_mode
default_conf['collateral'] = collateral
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
assert exchange.liquidation_price(
assert exchange.get_liquidation_price(
pair='DOGE/USDT',
open_rate=open_rate,
is_short=is_short,
mm_ratio=1535443.01,
position=71200.81144,
wallet_balance=-56354.57,
taker_fee_rate=0.01,
maintenance_amt=3683.979,
mm_ex_1=0.10,
upnl_ex_1=0.0
) is None
@@ -4014,13 +4012,13 @@ def test_liquidation_price_is_none(
'mm_ex_1, upnl_ex_1, maintenance_amt, position, open_rate, '
'mm_ratio, expected',
[
("binance", False, 1, futures, isolated, 1535443.01, 0.0,
("binance", False, 1, 'futures', 'isolated', 1535443.01, 0.0,
0.0, 135365.00, 3683.979, 1456.84, 0.10, 1114.78),
("binance", False, 1, futures, isolated, 1535443.01, 0.0,
("binance", False, 1, 'futures', 'isolated', 1535443.01, 0.0,
0.0, 16300.000, 109.488, 32481.980, 0.025, 18778.73),
("binance", False, 1, futures, cross, 1535443.01, 71200.81144,
("binance", False, 1, 'futures', 'cross', 1535443.01, 71200.81144,
-56354.57, 135365.00, 3683.979, 1456.84, 0.10, 1153.26),
("binance", False, 1, futures, cross, 1535443.01, 356512.508,
("binance", False, 1, 'futures', 'cross', 1535443.01, 356512.508,
-448192.89, 16300.000, 109.488, 32481.980, 0.025, 26316.89)
])
def test_liquidation_price(
@@ -4030,13 +4028,13 @@ def test_liquidation_price(
default_conf['trading_mode'] = trading_mode
default_conf['collateral'] = collateral
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
assert isclose(round(exchange.liquidation_price(
exchange.get_maintenance_ratio_and_amt = MagicMock(return_value=(mm_ratio, maintenance_amt))
assert isclose(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,
maintenance_amt=maintenance_amt,
position=position,
mm_ratio=mm_ratio
), 2), expected)