From 725c624281d253c2272c904f64a3648176fd022b Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 6 Nov 2022 10:14:07 +0800 Subject: [PATCH] grid2: rewrite ExtendUpperPrice --- pkg/strategy/grid2/grid.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/strategy/grid2/grid.go b/pkg/strategy/grid2/grid.go index bc11d99b2..c6670228d 100644 --- a/pkg/strategy/grid2/grid.go +++ b/pkg/strategy/grid2/grid.go @@ -90,19 +90,15 @@ func (g *Grid) HasPin(pin Pin) (ok bool) { } func (g *Grid) ExtendUpperPrice(upper fixedpoint.Value) (newPins []Pin) { - g.UpperPrice = upper - - // since the grid is extended, the size should be updated as well spread := g.Spread() - g.Size = (g.UpperPrice - g.LowerPrice).Div(spread).Floor() - lastPinPrice := fixedpoint.Value(g.Pins[len(g.Pins)-1]) - for p := lastPinPrice.Add(spread); p <= g.UpperPrice; p = p.Add(spread) { + startPrice := g.UpperPrice.Add(spread) + for p := startPrice; p.Compare(upper) <= 0; p = p.Add(spread) { newPins = append(newPins, Pin(p)) } - g.Pins = append(g.Pins, newPins...) - g.updatePinsCache() + g.UpperPrice = upper + g.addPins(newPins) return newPins }