Merge pull request #834 from c9s/strategy/pivotshort

fix: strategy/pivotshort: add trade loss to the account value calculation
This commit is contained in:
Yo-An Lin 2022-07-21 13:50:10 +08:00 committed by GitHub
commit e09e2dfff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -261,11 +261,14 @@ func useQuantityOrBaseBalance(session *bbgo.ExchangeSession, market types.Market
baseBalanceValue := baseBalance.Net().Mul(price) baseBalanceValue := baseBalance.Net().Mul(price)
accountValue := baseBalanceValue.Add(quoteBalance.Net()) accountValue := baseBalanceValue.Add(quoteBalance.Net())
// avoid using all account value since there will be some trade loss for interests and the fee
accountValue = accountValue.Mul(one.Sub(fixedpoint.NewFromFloat(0.01)))
log.Infof("calculated account value %f %s", accountValue.Float64(), market.QuoteCurrency) log.Infof("calculated account value %f %s", accountValue.Float64(), market.QuoteCurrency)
if session.IsolatedMargin { if session.IsolatedMargin {
originLeverage := leverage originLeverage := leverage
leverage = fixedpoint.Max(leverage, fixedpoint.NewFromInt(10)) leverage = fixedpoint.Min(leverage, fixedpoint.NewFromInt(10)) // max leverage is 10
log.Infof("using isolated margin, maxLeverage=10 originalLeverage=%f currentLeverage=%f", log.Infof("using isolated margin, maxLeverage=10 originalLeverage=%f currentLeverage=%f",
originLeverage.Float64(), originLeverage.Float64(),
leverage.Float64()) leverage.Float64())