mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
grid2: rewrite ExtendUpperPrice
This commit is contained in:
parent
533587ffd2
commit
725c624281
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user