feat: support backtesting with cross configuration
This commit is contained in:
@@ -213,12 +213,17 @@ class Binance(Exchange):
|
|||||||
mm_ex_1: float = 0.0
|
mm_ex_1: float = 0.0
|
||||||
upnl_ex_1: float = 0.0
|
upnl_ex_1: float = 0.0
|
||||||
pairs = [trade.pair for trade in open_trades]
|
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:
|
for trade in open_trades:
|
||||||
if trade.pair == pair:
|
if trade.pair == pair:
|
||||||
# Only "other" trades are considered
|
# Only "other" trades are considered
|
||||||
continue
|
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(
|
mm_ratio1, maint_amnt1 = self.get_maintenance_ratio_and_amt(
|
||||||
trade.pair, trade.stake_amount
|
trade.pair, trade.stake_amount
|
||||||
)
|
)
|
||||||
@@ -226,6 +231,7 @@ class Binance(Exchange):
|
|||||||
mm_ex_1 += maint_margin
|
mm_ex_1 += maint_margin
|
||||||
|
|
||||||
upnl_ex_1 += trade.amount * mark_price - trade.amount * trade.open_rate
|
upnl_ex_1 += trade.amount * mark_price - trade.amount * trade.open_rate
|
||||||
|
|
||||||
cross_vars = upnl_ex_1 - mm_ex_1
|
cross_vars = upnl_ex_1 - mm_ex_1
|
||||||
|
|
||||||
side_1 = -1 if is_short else 1
|
side_1 = -1 if is_short else 1
|
||||||
|
|||||||
Reference in New Issue
Block a user