From 54affd2f992223171fabe41aeb5678634c79fc0a Mon Sep 17 00:00:00 2001 From: c9s Date: Fri, 22 Jul 2022 11:47:48 +0800 Subject: [PATCH] pivotshort: quantity calculation -- sub debt --- pkg/strategy/pivotshort/breaklow.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/strategy/pivotshort/breaklow.go b/pkg/strategy/pivotshort/breaklow.go index 43ad6144d..9871718a1 100644 --- a/pkg/strategy/pivotshort/breaklow.go +++ b/pkg/strategy/pivotshort/breaklow.go @@ -374,16 +374,18 @@ func useQuantityOrBaseBalance(session *bbgo.ExchangeSession, market types.Market } // spot margin use the equity value, so we use the total quote balance here - maxPositionQuantity := risk.CalculateMaxPosition(price, accountValue, leverage) + maxPosition := risk.CalculateMaxPosition(price, accountValue, leverage) + debt := baseBalance.Debt() - log.Infof("margin leverage: calculated maxPositionQuantity=%f price=%f accountValue=%f %s leverage=%f", - maxPositionQuantity.Float64(), + log.Infof("margin leverage: calculated maxPosition=%f debt=%f price=%f accountValue=%f %s leverage=%f", + maxPosition.Float64(), + debt.Float64(), price.Float64(), accountValue.Float64(), market.QuoteCurrency, leverage.Float64()) - return maxPositionQuantity, nil + return maxPosition.Sub(debt), nil } if session.Futures || session.IsolatedFutures {