Merge pull request #1180 from c9s/c9s/grid2-params-fix

FIX: [grid2] fix base quote investment check
This commit is contained in:
Yo-An Lin 2023-05-26 14:58:57 +08:00 committed by GitHub
commit a7a4660b2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -766,7 +766,7 @@ func (s *Strategy) calculateBaseQuoteInvestmentQuantity(quoteInvestment, baseInv
// then reduce the numberOfSellOrders
numberOfSellOrders := s.BaseGridNum
// if it's not configured
// if it's not configured, calculate the number of sell orders
if numberOfSellOrders == 0 {
for i := len(pins) - 1; i >= 0; i-- {
pin := pins[i]
@ -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)