mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
grid2: fix ExtendUpperPrice and its tests
This commit is contained in:
parent
4fb2230e5d
commit
629cea0f44
|
@ -87,7 +87,11 @@ func (g *Grid) HasPin(pin Pin) (ok bool) {
|
|||
}
|
||||
|
||||
func (g *Grid) ExtendUpperPrice(upper fixedpoint.Value) (newPins []Pin) {
|
||||
newPins = calculateArithmeticPins(g.UpperPrice, upper, g.Spread, g.TickSize)
|
||||
if upper.Compare(g.UpperPrice) <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
newPins = calculateArithmeticPins(g.UpperPrice.Add(g.Spread), upper, g.Spread, g.TickSize)
|
||||
g.UpperPrice = upper
|
||||
g.addPins(newPins)
|
||||
return newPins
|
||||
|
|
|
@ -51,16 +51,19 @@ func TestGrid_HasPin(t *testing.T) {
|
|||
func TestGrid_ExtendUpperPrice(t *testing.T) {
|
||||
upper := number(500.0)
|
||||
lower := number(100.0)
|
||||
size := number(40.0)
|
||||
size := number(4.0)
|
||||
grid := NewGrid(lower, upper, size, number(0.01))
|
||||
originalSpread := grid.Spread
|
||||
|
||||
assert.Equal(t, number(10.0), originalSpread)
|
||||
assert.Len(t, grid.Pins, 40) // (1000-500) / 4
|
||||
t.Logf("pins: %+v", grid.Pins)
|
||||
assert.Equal(t, number(100.0), originalSpread)
|
||||
assert.Len(t, grid.Pins, 5) // (1000-500) / 4
|
||||
|
||||
newPins := grid.ExtendUpperPrice(number(1000.0))
|
||||
assert.Len(t, grid.Pins, 10)
|
||||
assert.Len(t, newPins, 5)
|
||||
assert.Equal(t, originalSpread, grid.Spread)
|
||||
assert.Len(t, newPins, 51) // (1000-500) / 4
|
||||
t.Logf("pins: %+v", grid.Pins)
|
||||
}
|
||||
|
||||
func TestGrid_ExtendLowerPrice(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user