grid2: fix upper price error

This commit is contained in:
c9s 2023-02-10 17:22:19 +08:00
parent 2fed98ea55
commit 34ab53303a
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -40,13 +40,16 @@ func calculateArithmeticPins(lower, upper, spread, tickSize fixedpoint.Value) []
var ts = tickSize.Float64()
var prec = int(math.Round(math.Log10(ts) * -1.0))
var pow10 = math.Pow10(prec)
for p := lower; p.Compare(upper) <= 0; p = p.Add(spread) {
for p := lower; p.Compare(upper.Sub(spread)) <= 0; p = p.Add(spread) {
pp := math.Round(p.Float64()*pow10*10.0) / 10.0
pp = math.Trunc(pp) / pow10
pin := Pin(fixedpoint.NewFromFloat(pp))
pins = append(pins, pin)
}
// this makes sure there is no error at the upper price
pins = append(pins, Pin(upper))
return pins
}