added one test for binance isolated liq
This commit is contained in:
parent
6ec4432c92
commit
544b88f026
@ -7,4 +7,3 @@ from freqtrade.enums.selltype import SellType
|
||||
from freqtrade.enums.signaltype import SignalTagType, SignalType
|
||||
from freqtrade.enums.state import State
|
||||
from freqtrade.enums.tradingmode import TradingMode
|
||||
from freqtrade.enums.marginmode import MarginMode
|
||||
|
@ -19,6 +19,7 @@ def liquidation_price(
|
||||
entry_price_1_both: Optional[float],
|
||||
maintenance_margin_rate_both: Optional[float]
|
||||
) -> Optional[float]:
|
||||
|
||||
if trading_mode == TradingMode.SPOT:
|
||||
return None
|
||||
|
||||
@ -29,16 +30,34 @@ def liquidation_price(
|
||||
)
|
||||
|
||||
if exchange_name.lower() == "binance":
|
||||
if not wallet_balance or not maintenance_margin_ex_1 or not unrealized_pnl_ex_1 or not maintenance_amount_both \
|
||||
or not position_1_both or not entry_price_1_both or not maintenance_margin_rate_both:
|
||||
if (
|
||||
not wallet_balance or
|
||||
not maintenance_margin_ex_1 or
|
||||
not unrealized_pnl_ex_1 or
|
||||
not maintenance_amount_both or
|
||||
not position_1_both or
|
||||
not entry_price_1_both or
|
||||
not maintenance_margin_rate_both
|
||||
):
|
||||
raise OperationalException(
|
||||
f"Parameters wallet_balance, maintenance_margin_ex_1, unrealized_pnl_ex_1, maintenance_amount_both, "
|
||||
f"position_1_both, entry_price_1_both, maintenance_margin_rate_both is required by liquidation_price "
|
||||
f"when exchange is {exchange_name.lower()}")
|
||||
|
||||
return binance(open_rate, is_short, leverage, trading_mode, collateral, wallet_balance, maintenance_margin_ex_1,
|
||||
unrealized_pnl_ex_1, maintenance_amount_both, position_1_both, entry_price_1_both,
|
||||
maintenance_margin_rate_both)
|
||||
return binance(
|
||||
open_rate,
|
||||
is_short,
|
||||
leverage,
|
||||
trading_mode,
|
||||
collateral,
|
||||
wallet_balance,
|
||||
maintenance_margin_ex_1,
|
||||
unrealized_pnl_ex_1,
|
||||
maintenance_amount_both,
|
||||
position_1_both,
|
||||
entry_price_1_both,
|
||||
maintenance_margin_rate_both
|
||||
)
|
||||
elif exchange_name.lower() == "kraken":
|
||||
return kraken(open_rate, is_short, leverage, trading_mode, collateral)
|
||||
elif exchange_name.lower() == "ftx":
|
||||
|
@ -46,7 +46,14 @@ def test_liquidation_price_is_none(
|
||||
is_short,
|
||||
leverage,
|
||||
trading_mode,
|
||||
collateral
|
||||
collateral,
|
||||
1535443.01,
|
||||
71200.81144,
|
||||
-56354.57,
|
||||
135365.00,
|
||||
3683.979,
|
||||
1456.84,
|
||||
0.10,
|
||||
) is None
|
||||
|
||||
|
||||
@ -80,17 +87,14 @@ def test_liquidation_price_exception_thrown(
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'exchange_name,open_rate,is_short,leverage,trading_mode,collateral,result', [
|
||||
('exchange_name,open_rate,is_short,leverage,trading_mode,collateral,wallet_balance,'
|
||||
'maintenance_margin_ex_1,unrealized_pnl_ex_1,maintenance_amount_both,'
|
||||
'position_1_both,entry_price_1_both,maintenance_margin_rate_both,liq_price'), [
|
||||
# Binance
|
||||
('binance', "2.0", False, "1.0", margin, cross, 1.0),
|
||||
('binance', "2.0", False, "1.0", futures, cross, 1.0),
|
||||
('binance', "2.0", False, "1.0", futures, isolated, 1.0),
|
||||
("binance", 0.0, False, 1, futures, cross, 1535443.01,
|
||||
71200.81144, -56354.57, 135365.00, 3683.979, 1456.84, 0.10, 1153.26)
|
||||
# Kraken
|
||||
('kraken', "2.0", True, "3.0", margin, cross, 1.0),
|
||||
('kraken', "2.0", True, "3.0", futures, cross, 1.0),
|
||||
# FTX
|
||||
('ftx', "2.0", False, "3.0", margin, cross, 1.0),
|
||||
('ftx', "2.0", False, "3.0", futures, cross, 1.0),
|
||||
]
|
||||
)
|
||||
def test_liquidation_price(
|
||||
@ -100,14 +104,27 @@ def test_liquidation_price(
|
||||
leverage,
|
||||
trading_mode,
|
||||
collateral,
|
||||
result
|
||||
wallet_balance,
|
||||
maintenance_margin_ex_1,
|
||||
unrealized_pnl_ex_1,
|
||||
maintenance_amount_both,
|
||||
position_1_both,
|
||||
entry_price_1_both,
|
||||
maintenance_margin_rate_both,
|
||||
liq_price
|
||||
):
|
||||
# assert liquidation_price(
|
||||
# exchange_name,
|
||||
# open_rate,
|
||||
# is_short,
|
||||
# leverage,
|
||||
# trading_mode,
|
||||
# collateral
|
||||
# ) == result
|
||||
return # Here to avoid indent error
|
||||
assert liquidation_price(
|
||||
exchange_name,
|
||||
open_rate,
|
||||
is_short,
|
||||
leverage,
|
||||
trading_mode,
|
||||
collateral,
|
||||
wallet_balance,
|
||||
maintenance_margin_ex_1,
|
||||
unrealized_pnl_ex_1,
|
||||
maintenance_amount_both,
|
||||
position_1_both,
|
||||
entry_price_1_both,
|
||||
maintenance_margin_rate_both
|
||||
) == liq_price
|
||||
|
Loading…
Reference in New Issue
Block a user