From 8c09c9668ae8e3071bb908ac1e3f166b4b8c7d30 Mon Sep 17 00:00:00 2001 From: c9s Date: Fri, 26 May 2023 14:49:56 +0800 Subject: [PATCH] grid2: improve base quote investment check --- pkg/strategy/grid2/strategy.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/strategy/grid2/strategy.go b/pkg/strategy/grid2/strategy.go index fc95d9e9e..b1f7e9d7f 100644 --- a/pkg/strategy/grid2/strategy.go +++ b/pkg/strategy/grid2/strategy.go @@ -850,12 +850,16 @@ func (s *Strategy) calculateBaseQuoteInvestmentQuantity(quoteInvestment, baseInv } } - quoteSideQuantity := quoteInvestment.Div(totalQuotePrice) - if numberOfSellOrders > 0 { - return fixedpoint.Min(quoteSideQuantity, baseQuantity), nil + if totalQuotePrice.Sign() > 0 && quoteInvestment.Sign() > 0 { + quoteSideQuantity := quoteInvestment.Div(totalQuotePrice) + if numberOfSellOrders > 0 { + return fixedpoint.Min(quoteSideQuantity, baseQuantity), nil + } + + return quoteSideQuantity, nil } - return quoteSideQuantity, nil + return baseQuantity, nil } func (s *Strategy) newTriggerPriceHandler(ctx context.Context, session *bbgo.ExchangeSession) types.KLineCallback { @@ -1079,7 +1083,7 @@ func (s *Strategy) openGrid(ctx context.Context, session *bbgo.ExchangeSession) } } else { // calculate the quantity from the investment configuration - if !s.QuoteInvestment.IsZero() && !s.BaseInvestment.IsZero() { + if !s.BaseInvestment.IsZero() { quantity, err2 := s.calculateBaseQuoteInvestmentQuantity(s.QuoteInvestment, s.BaseInvestment, lastPrice, s.grid.Pins) if err2 != nil { s.EmitGridError(err2)