pivotshort: check maximum margin leverage

This commit is contained in:
c9s 2022-07-14 17:38:11 +08:00
parent 0284d090d8
commit adb96cac39
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -231,6 +231,14 @@ func useQuantityOrBaseBalance(session *bbgo.ExchangeSession, market types.Market
baseBalanceValue := baseBalance.Total().Mul(price)
accountValue := baseBalanceValue.Add(quoteBalance.Total())
if session.IsolatedMargin {
originLeverage := leverage
leverage = fixedpoint.Max(leverage, fixedpoint.NewFromInt(10))
log.Infof("using isolated margin, maxLeverage=10 originalLeverage=%f currentLeverage=%f",
originLeverage.Float64(),
leverage.Float64())
}
// spot margin use the equity value, so we use the total quote balance here
maxPositionQuantity := risk.CalculateMaxPosition(price, accountValue, leverage)