grid2: fix quantity calculation

This commit is contained in:
c9s 2022-12-01 14:51:28 +08:00
parent e80c8f2959
commit 22569fcb30
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -360,7 +360,7 @@ func (s *Strategy) calculateQuoteBaseInvestmentQuantity(quoteInvestment, baseInv
maxNumberOfSellOrders := numberOfSellOrders + 1
minBaseQuantity := fixedpoint.Max(s.Market.MinNotional.Div(lastPrice), s.Market.MinQuantity)
maxBaseQuantity := fixedpoint.Zero
for maxBaseQuantity.Compare(s.Market.MinQuantity) <= 0 {
for maxBaseQuantity.Compare(s.Market.MinQuantity) <= 0 || maxBaseQuantity.Compare(minBaseQuantity) <= 0 {
maxNumberOfSellOrders--
maxBaseQuantity = baseInvestment.Div(fixedpoint.NewFromInt(int64(maxNumberOfSellOrders)))
}
@ -398,7 +398,8 @@ func (s *Strategy) calculateQuoteBaseInvestmentQuantity(quoteInvestment, baseInv
}
}
return quoteInvestment.Div(totalQuotePrice), nil
quoteSideQuantity := quoteInvestment.Div(totalQuotePrice)
return fixedpoint.Max(quoteSideQuantity, maxBaseQuantity), nil
}
// setupGridOrders