feat: support backtesting with cross configuration

This commit is contained in:
Matthias
2024-09-05 18:06:22 +02:00
parent 36ae564d26
commit c5525d356e

View File

@@ -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