added one test for binance isolated liq

This commit is contained in:
Sam Germain 2021-09-19 00:05:39 -06:00
parent 6ec4432c92
commit 544b88f026
3 changed files with 60 additions and 25 deletions

View File

@ -7,4 +7,3 @@ from freqtrade.enums.selltype import SellType
from freqtrade.enums.signaltype import SignalTagType, SignalType from freqtrade.enums.signaltype import SignalTagType, SignalType
from freqtrade.enums.state import State from freqtrade.enums.state import State
from freqtrade.enums.tradingmode import TradingMode from freqtrade.enums.tradingmode import TradingMode
from freqtrade.enums.marginmode import MarginMode

View File

@ -19,6 +19,7 @@ def liquidation_price(
entry_price_1_both: Optional[float], entry_price_1_both: Optional[float],
maintenance_margin_rate_both: Optional[float] maintenance_margin_rate_both: Optional[float]
) -> Optional[float]: ) -> Optional[float]:
if trading_mode == TradingMode.SPOT: if trading_mode == TradingMode.SPOT:
return None return None
@ -29,16 +30,34 @@ def liquidation_price(
) )
if exchange_name.lower() == "binance": 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 \ if (
or not position_1_both or not entry_price_1_both or not maintenance_margin_rate_both: 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( raise OperationalException(
f"Parameters wallet_balance, maintenance_margin_ex_1, unrealized_pnl_ex_1, maintenance_amount_both, " 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"position_1_both, entry_price_1_both, maintenance_margin_rate_both is required by liquidation_price "
f"when exchange is {exchange_name.lower()}") f"when exchange is {exchange_name.lower()}")
return binance(open_rate, is_short, leverage, trading_mode, collateral, wallet_balance, maintenance_margin_ex_1, return binance(
unrealized_pnl_ex_1, maintenance_amount_both, position_1_both, entry_price_1_both, open_rate,
maintenance_margin_rate_both) 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": elif exchange_name.lower() == "kraken":
return kraken(open_rate, is_short, leverage, trading_mode, collateral) return kraken(open_rate, is_short, leverage, trading_mode, collateral)
elif exchange_name.lower() == "ftx": elif exchange_name.lower() == "ftx":

View File

@ -46,7 +46,14 @@ def test_liquidation_price_is_none(
is_short, is_short,
leverage, leverage,
trading_mode, trading_mode,
collateral collateral,
1535443.01,
71200.81144,
-56354.57,
135365.00,
3683.979,
1456.84,
0.10,
) is None ) is None
@ -80,17 +87,14 @@ def test_liquidation_price_exception_thrown(
@pytest.mark.parametrize( @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
('binance', "2.0", False, "1.0", margin, cross, 1.0), ("binance", 0.0, False, 1, futures, cross, 1535443.01,
('binance', "2.0", False, "1.0", futures, cross, 1.0), 71200.81144, -56354.57, 135365.00, 3683.979, 1456.84, 0.10, 1153.26)
('binance', "2.0", False, "1.0", futures, isolated, 1.0),
# Kraken # Kraken
('kraken', "2.0", True, "3.0", margin, cross, 1.0),
('kraken', "2.0", True, "3.0", futures, cross, 1.0),
# FTX # 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( def test_liquidation_price(
@ -100,14 +104,27 @@ def test_liquidation_price(
leverage, leverage,
trading_mode, trading_mode,
collateral, 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( assert liquidation_price(
# exchange_name, exchange_name,
# open_rate, open_rate,
# is_short, is_short,
# leverage, leverage,
# trading_mode, trading_mode,
# collateral collateral,
# ) == result wallet_balance,
return # Here to avoid indent error maintenance_margin_ex_1,
unrealized_pnl_ex_1,
maintenance_amount_both,
position_1_both,
entry_price_1_both,
maintenance_margin_rate_both
) == liq_price