feat: implement liquidation price update on all order fills

This commit is contained in:
Matthias
2024-09-05 18:07:01 +02:00
parent c5525d356e
commit abe01f8f48

View File

@@ -26,6 +26,7 @@ from freqtrade.enums import (
CandleType, CandleType,
ExitCheckTuple, ExitCheckTuple,
ExitType, ExitType,
MarginMode,
RunMode, RunMode,
TradingMode, TradingMode,
) )
@@ -207,6 +208,7 @@ class Backtesting:
self.required_startup = self.dataprovider.get_required_startup(self.timeframe) self.required_startup = self.dataprovider.get_required_startup(self.timeframe)
self.trading_mode: TradingMode = config.get("trading_mode", TradingMode.SPOT) self.trading_mode: TradingMode = config.get("trading_mode", TradingMode.SPOT)
self.margin_mode: MarginMode = config.get("margin_mode", MarginMode.ISOLATED)
# strategies which define "can_short=True" will fail to load in Spot mode. # strategies which define "can_short=True" will fail to load in Spot mode.
self._can_short = self.trading_mode != TradingMode.SPOT self._can_short = self.trading_mode != TradingMode.SPOT
self._position_stacking: bool = self.config.get("position_stacking", False) self._position_stacking: bool = self.config.get("position_stacking", False)
@@ -699,8 +701,11 @@ class Backtesting:
current_time=current_date, current_time=current_date,
) )
if not (order.ft_order_side == trade.exit_side and order.safe_amount == trade.amount): if self.margin_mode == MarginMode.CROSS or not (
# trade is still open order.ft_order_side == trade.exit_side and order.safe_amount == trade.amount
):
# trade is still open or we are in cross margin mode and
# must update all liquidation prices
update_liquidation_prices( update_liquidation_prices(
trade, trade,
exchange=self.exchange, exchange=self.exchange,
@@ -708,8 +713,8 @@ class Backtesting:
stake_currency=self.config["stake_currency"], stake_currency=self.config["stake_currency"],
dry_run=self.config["dry_run"], dry_run=self.config["dry_run"],
) )
if not (order.ft_order_side == trade.exit_side and order.safe_amount == trade.amount):
self._call_adjust_stop(current_date, trade, order.ft_price) self._call_adjust_stop(current_date, trade, order.ft_price)
# pass
return True return True
return False return False