feat: add cross margin balance logic

This commit is contained in:
Matthias
2024-12-08 19:38:25 +01:00
parent 8cb82df055
commit 6887ed4bf7

View File

@@ -136,12 +136,22 @@ class Wallets:
used_stake = tot_in_trades
cross_margin = 0.0
if self._config.get("margin_mode") == "cross":
# In cross-margin mode, the total balance is used as collateral.
for curr, bal in self._start_cap.items():
if curr == self._stake_currency:
continue
rate = self._exchange.get_conversion_rate(curr, self._stake_currency)
if rate:
cross_margin += bal * rate
current_stake = self._start_cap.get(self._stake_currency, 0) + tot_profit - tot_in_trades
total_stake = current_stake + used_stake
_wallets[self._stake_currency] = Wallet(
currency=self._stake_currency,
free=current_stake,
free=current_stake + cross_margin,
used=used_stake,
total=total_stake,
)