Added Tests for Binance Liquidation price
This commit is contained in:
parent
6a81730a74
commit
98d2d2f485
@ -1,2 +1,3 @@
|
|||||||
# flake8: noqa: F401
|
# flake8: noqa: F401
|
||||||
from freqtrade.leverage.interest import interest
|
from freqtrade.leverage.interest import interest
|
||||||
|
from freqtrade.leverage.liquidation_price import liquidation_price
|
||||||
|
@ -123,7 +123,7 @@ def binance(
|
|||||||
# Liquidation Price of USDⓈ-M Futures Contracts Isolated
|
# Liquidation Price of USDⓈ-M Futures Contracts Isolated
|
||||||
|
|
||||||
# Isolated margin mode, then TMM=0,UPNL=0
|
# Isolated margin mode, then TMM=0,UPNL=0
|
||||||
return (wb + cum_b - (side_1_both * position_1_both * ep1_both)) / (
|
return (wb + cum_b - side_1_both * position_1_both * ep1_both) / (
|
||||||
position_1_both * mmr_b - side_1_both * position_1_both)
|
position_1_both * mmr_b - side_1_both * position_1_both)
|
||||||
|
|
||||||
elif trading_mode == TradingMode.FUTURES and collateral == Collateral.CROSS:
|
elif trading_mode == TradingMode.FUTURES and collateral == Collateral.CROSS:
|
||||||
@ -131,7 +131,7 @@ def binance(
|
|||||||
# Liquidation Price of USDⓈ-M Futures Contracts Cross
|
# Liquidation Price of USDⓈ-M Futures Contracts Cross
|
||||||
|
|
||||||
# Isolated margin mode, then TMM=0,UPNL=0
|
# Isolated margin mode, then TMM=0,UPNL=0
|
||||||
return (wb - tmm_1 + upnl_1 + cum_b - (side_1_both * position_1_both * ep1_both)) / (
|
return (wb - tmm_1 + upnl_1 + cum_b - side_1_both * position_1_both * ep1_both) / (
|
||||||
position_1_both * mmr_b - side_1_both * position_1_both)
|
position_1_both * mmr_b - side_1_both * position_1_both)
|
||||||
|
|
||||||
# If nothing was returned
|
# If nothing was returned
|
||||||
|
40
tests/leverage/test_liquidation_price.py
Normal file
40
tests/leverage/test_liquidation_price.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
from math import isclose
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from freqtrade.enums import TradingMode, Collateral
|
||||||
|
from freqtrade.leverage import liquidation_price
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'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, '
|
||||||
|
'expected',
|
||||||
|
[
|
||||||
|
("binance", 0.0, False, 1, TradingMode.FUTURES, Collateral.ISOLATED, 1535443.01, 71200.81144, -56354.57,
|
||||||
|
135365.00, 3683.979, 1456.84, 0.10, 1114.78),
|
||||||
|
("binance", 0.0, False, 1, TradingMode.FUTURES, Collateral.ISOLATED, 1535443.01, 356512.508, -448192.89,
|
||||||
|
16300.000, 109.488, 32481.980, 0.025, 18778.73),
|
||||||
|
("binance", 0.0, False, 1, TradingMode.FUTURES, Collateral.CROSS, 1535443.01, 71200.81144, -56354.57, 135365.00,
|
||||||
|
3683.979, 1456.84, 0.10, 1153.26),
|
||||||
|
("binance", 0.0, False, 1, TradingMode.FUTURES, Collateral.CROSS, 1535443.01, 356512.508, -448192.89, 16300.000,
|
||||||
|
109.488, 32481.980, 0.025, 26316.89)
|
||||||
|
])
|
||||||
|
def test_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, expected):
|
||||||
|
assert isclose(round(liquidation_price(
|
||||||
|
exchange_name=exchange_name,
|
||||||
|
open_rate=open_rate,
|
||||||
|
is_short=is_short,
|
||||||
|
leverage=leverage,
|
||||||
|
trading_mode=trading_mode,
|
||||||
|
collateral=collateral,
|
||||||
|
wallet_balance=wallet_balance,
|
||||||
|
maintenance_margin_ex_1=maintenance_margin_ex_1,
|
||||||
|
unrealized_pnl_ex_1=unrealized_pnl_ex_1,
|
||||||
|
maintenance_amount_both=maintenance_amount_both,
|
||||||
|
position_1_both=position_1_both,
|
||||||
|
entry_price_1_both=entry_price_1_both,
|
||||||
|
maintenance_margin_rate_both=maintenance_margin_rate_both
|
||||||
|
), 2), expected)
|
Loading…
Reference in New Issue
Block a user