refactor: rename dry-liquidation parameter
passing all open trades will be more flexible for the future.
This commit is contained in:
@@ -153,7 +153,7 @@ class Binance(Exchange):
|
|||||||
stake_amount: float,
|
stake_amount: float,
|
||||||
leverage: float,
|
leverage: float,
|
||||||
wallet_balance: float, # Or margin balance
|
wallet_balance: float, # Or margin balance
|
||||||
other_trades: list,
|
open_trades: list,
|
||||||
) -> Optional[float]:
|
) -> Optional[float]:
|
||||||
"""
|
"""
|
||||||
Important: Must be fetching data from cached values as this is used by backtesting!
|
Important: Must be fetching data from cached values as this is used by backtesting!
|
||||||
@@ -171,7 +171,7 @@ class Binance(Exchange):
|
|||||||
:param wallet_balance: Amount of margin_mode in the wallet being used to trade
|
:param wallet_balance: Amount of margin_mode in the wallet being used to trade
|
||||||
Cross-Margin Mode: crossWalletBalance
|
Cross-Margin Mode: crossWalletBalance
|
||||||
Isolated-Margin Mode: isolatedWalletBalance
|
Isolated-Margin Mode: isolatedWalletBalance
|
||||||
:param other_trades: List of other open trades in the same wallet
|
:param open_trades: List of open trades in the same wallet
|
||||||
|
|
||||||
# * Only required for Cross
|
# * Only required for Cross
|
||||||
:param mm_ex_1: (TMM)
|
:param mm_ex_1: (TMM)
|
||||||
@@ -191,7 +191,7 @@ class Binance(Exchange):
|
|||||||
if self.margin_mode == MarginMode.CROSS:
|
if self.margin_mode == MarginMode.CROSS:
|
||||||
mm_ex_1: float = 0.0
|
mm_ex_1: float = 0.0
|
||||||
upnl_ex_1: float = 0.0
|
upnl_ex_1: float = 0.0
|
||||||
for trade in other_trades:
|
for trade in open_trades:
|
||||||
mm_ratio1, maint_amnt1 = self.get_maintenance_ratio_and_amt(
|
mm_ratio1, maint_amnt1 = self.get_maintenance_ratio_and_amt(
|
||||||
trade["pair"], trade["stake_amount"]
|
trade["pair"], trade["stake_amount"]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ class Bybit(Exchange):
|
|||||||
stake_amount: float,
|
stake_amount: float,
|
||||||
leverage: float,
|
leverage: float,
|
||||||
wallet_balance: float, # Or margin balance
|
wallet_balance: float, # Or margin balance
|
||||||
other_trades: list,
|
open_trades: list,
|
||||||
) -> Optional[float]:
|
) -> Optional[float]:
|
||||||
"""
|
"""
|
||||||
Important: Must be fetching data from cached values as this is used by backtesting!
|
Important: Must be fetching data from cached values as this is used by backtesting!
|
||||||
@@ -177,7 +177,7 @@ class Bybit(Exchange):
|
|||||||
:param wallet_balance: Amount of margin_mode in the wallet being used to trade
|
:param wallet_balance: Amount of margin_mode in the wallet being used to trade
|
||||||
Cross-Margin Mode: crossWalletBalance
|
Cross-Margin Mode: crossWalletBalance
|
||||||
Isolated-Margin Mode: isolatedWalletBalance
|
Isolated-Margin Mode: isolatedWalletBalance
|
||||||
:param other_trades: List of other open trades in the same wallet
|
:param open_trades: List of other open trades in the same wallet
|
||||||
"""
|
"""
|
||||||
|
|
||||||
market = self.markets[pair]
|
market = self.markets[pair]
|
||||||
|
|||||||
@@ -3532,7 +3532,7 @@ class Exchange:
|
|||||||
stake_amount: float,
|
stake_amount: float,
|
||||||
leverage: float,
|
leverage: float,
|
||||||
wallet_balance: float,
|
wallet_balance: float,
|
||||||
other_trades: Optional[list] = None,
|
open_trades: Optional[list] = None,
|
||||||
) -> Optional[float]:
|
) -> Optional[float]:
|
||||||
"""
|
"""
|
||||||
Set's the margin mode on the exchange to cross or isolated for a specific pair
|
Set's the margin mode on the exchange to cross or isolated for a specific pair
|
||||||
@@ -3554,7 +3554,7 @@ class Exchange:
|
|||||||
leverage=leverage,
|
leverage=leverage,
|
||||||
stake_amount=stake_amount,
|
stake_amount=stake_amount,
|
||||||
wallet_balance=wallet_balance,
|
wallet_balance=wallet_balance,
|
||||||
other_trades=other_trades or [],
|
open_trades=open_trades or [],
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
positions = self.fetch_positions(pair)
|
positions = self.fetch_positions(pair)
|
||||||
@@ -3580,7 +3580,7 @@ class Exchange:
|
|||||||
stake_amount: float,
|
stake_amount: float,
|
||||||
leverage: float,
|
leverage: float,
|
||||||
wallet_balance: float, # Or margin balance
|
wallet_balance: float, # Or margin balance
|
||||||
other_trades: list,
|
open_trades: list,
|
||||||
) -> Optional[float]:
|
) -> Optional[float]:
|
||||||
"""
|
"""
|
||||||
Important: Must be fetching data from cached values as this is used by backtesting!
|
Important: Must be fetching data from cached values as this is used by backtesting!
|
||||||
@@ -3605,7 +3605,7 @@ class Exchange:
|
|||||||
:param wallet_balance: Amount of margin_mode in the wallet being used to trade
|
:param wallet_balance: Amount of margin_mode in the wallet being used to trade
|
||||||
Cross-Margin Mode: crossWalletBalance
|
Cross-Margin Mode: crossWalletBalance
|
||||||
Isolated-Margin Mode: isolatedWalletBalance
|
Isolated-Margin Mode: isolatedWalletBalance
|
||||||
:param other_trades: List of other open trades in the same wallet
|
:param open_trades: List of other open trades in the same wallet
|
||||||
"""
|
"""
|
||||||
|
|
||||||
market = self.markets[pair]
|
market = self.markets[pair]
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ def update_liquidation_prices(
|
|||||||
stake_amount=t.stake_amount,
|
stake_amount=t.stake_amount,
|
||||||
leverage=trade.leverage,
|
leverage=trade.leverage,
|
||||||
wallet_balance=total_wallet_stake,
|
wallet_balance=total_wallet_stake,
|
||||||
other_trades=[tr for tr in open_trades if t.id != tr.id],
|
open_trades=[tr for tr in open_trades],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif trade:
|
elif trade:
|
||||||
|
|||||||
@@ -6009,7 +6009,7 @@ def test_get_liquidation_price1(mocker, default_conf):
|
|||||||
stake_amount=18.884 * 0.8,
|
stake_amount=18.884 * 0.8,
|
||||||
leverage=leverage,
|
leverage=leverage,
|
||||||
wallet_balance=18.884 * 0.8,
|
wallet_balance=18.884 * 0.8,
|
||||||
other_trades=[],
|
open_trades=[],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -6140,7 +6140,7 @@ def test_get_liquidation_price(
|
|||||||
wallet_balance=amount * open_rate / leverage,
|
wallet_balance=amount * open_rate / leverage,
|
||||||
leverage=leverage,
|
leverage=leverage,
|
||||||
is_short=is_short,
|
is_short=is_short,
|
||||||
other_trades=[],
|
open_trades=[],
|
||||||
)
|
)
|
||||||
if expected_liq is None:
|
if expected_liq is None:
|
||||||
assert liq is None
|
assert liq is None
|
||||||
|
|||||||
Reference in New Issue
Block a user