From c5525d356ec8b4702337f2b7cff3410465e44c03 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 5 Sep 2024 18:06:22 +0200 Subject: [PATCH] feat: support backtesting with cross configuration --- freqtrade/exchange/binance.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index a837068d1..a2aac6fb2 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -213,12 +213,17 @@ class Binance(Exchange): mm_ex_1: float = 0.0 upnl_ex_1: float = 0.0 pairs = [trade.pair for trade in open_trades] - funding_rates = self.fetch_funding_rates(pairs) + if self._config["runmode"] in ("live", "dry_run"): + funding_rates = self.fetch_funding_rates(pairs) for trade in open_trades: if trade.pair == pair: # Only "other" trades are considered continue - mark_price = funding_rates[trade.pair]["markPrice"] + if self._config["runmode"] in ("live", "dry_run"): + mark_price = funding_rates[trade.pair]["markPrice"] + else: + # Fall back to open rate for backtesting + mark_price = trade.open_rate mm_ratio1, maint_amnt1 = self.get_maintenance_ratio_and_amt( trade.pair, trade.stake_amount ) @@ -226,6 +231,7 @@ class Binance(Exchange): mm_ex_1 += maint_margin upnl_ex_1 += trade.amount * mark_price - trade.amount * trade.open_rate + cross_vars = upnl_ex_1 - mm_ex_1 side_1 = -1 if is_short else 1