mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
grid2: improve number func
This commit is contained in:
parent
f46fc7ee80
commit
4fb2230e5d
|
@ -9,19 +9,25 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func number(a interface{}) fixedpoint.Value {
|
func number(a interface{}) fixedpoint.Value {
|
||||||
if s, ok := a.(string); ok {
|
switch v := a.(type) {
|
||||||
return fixedpoint.MustNewFromString(s)
|
case string:
|
||||||
|
return fixedpoint.MustNewFromString(v)
|
||||||
|
case int:
|
||||||
|
return fixedpoint.NewFromInt(int64(v))
|
||||||
|
case int64:
|
||||||
|
return fixedpoint.NewFromInt(int64(v))
|
||||||
|
case float64:
|
||||||
|
return fixedpoint.NewFromFloat(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
f := a.(float64)
|
return fixedpoint.Zero
|
||||||
return fixedpoint.NewFromFloat(f)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewGrid(t *testing.T) {
|
func TestNewGrid(t *testing.T) {
|
||||||
upper := fixedpoint.NewFromFloat(500.0)
|
upper := fixedpoint.NewFromFloat(500.0)
|
||||||
lower := fixedpoint.NewFromFloat(100.0)
|
lower := fixedpoint.NewFromFloat(100.0)
|
||||||
size := fixedpoint.NewFromFloat(100.0)
|
size := fixedpoint.NewFromFloat(100.0)
|
||||||
grid := NewGrid(lower, upper, size, number(2.0))
|
grid := NewGrid(lower, upper, size, number(0.01))
|
||||||
assert.Equal(t, upper, grid.UpperPrice)
|
assert.Equal(t, upper, grid.UpperPrice)
|
||||||
assert.Equal(t, lower, grid.LowerPrice)
|
assert.Equal(t, lower, grid.LowerPrice)
|
||||||
assert.Equal(t, fixedpoint.NewFromFloat(4), grid.Spread)
|
assert.Equal(t, fixedpoint.NewFromFloat(4), grid.Spread)
|
||||||
|
@ -35,7 +41,7 @@ func TestGrid_HasPin(t *testing.T) {
|
||||||
upper := fixedpoint.NewFromFloat(500.0)
|
upper := fixedpoint.NewFromFloat(500.0)
|
||||||
lower := fixedpoint.NewFromFloat(100.0)
|
lower := fixedpoint.NewFromFloat(100.0)
|
||||||
size := fixedpoint.NewFromFloat(100.0)
|
size := fixedpoint.NewFromFloat(100.0)
|
||||||
grid := NewGrid(lower, upper, size, number(2))
|
grid := NewGrid(lower, upper, size, number(0.01))
|
||||||
|
|
||||||
assert.True(t, grid.HasPin(Pin(number(100.0))))
|
assert.True(t, grid.HasPin(Pin(number(100.0))))
|
||||||
assert.True(t, grid.HasPin(Pin(number(500.0))))
|
assert.True(t, grid.HasPin(Pin(number(500.0))))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user