mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
grid2: rename filterPrice to roundAndTruncatePrice
This commit is contained in:
parent
a298950be8
commit
36e90cf5ca
|
@ -35,8 +35,8 @@ type Grid struct {
|
||||||
|
|
||||||
type Pin fixedpoint.Value
|
type Pin fixedpoint.Value
|
||||||
|
|
||||||
// filterPrice filters price with the given precision
|
// roundAndTruncatePrice rounds the given price at prec-1 and then truncate the price at prec
|
||||||
func filterPrice(p fixedpoint.Value, prec int) fixedpoint.Value {
|
func roundAndTruncatePrice(p fixedpoint.Value, prec int) fixedpoint.Value {
|
||||||
var pow10 = math.Pow10(prec)
|
var pow10 = math.Pow10(prec)
|
||||||
pp := math.Round(p.Float64()*pow10*10.0) / 10.0
|
pp := math.Round(p.Float64()*pow10*10.0) / 10.0
|
||||||
pp = math.Trunc(pp) / pow10
|
pp = math.Trunc(pp) / pow10
|
||||||
|
@ -71,12 +71,12 @@ func calculateArithmeticPins(lower, upper, spread, tickSize fixedpoint.Value) []
|
||||||
var ts = tickSize.Float64()
|
var ts = tickSize.Float64()
|
||||||
var prec = int(math.Round(math.Log10(ts) * -1.0))
|
var prec = int(math.Round(math.Log10(ts) * -1.0))
|
||||||
for p := lower; p.Compare(upper.Sub(spread)) <= 0; p = p.Add(spread) {
|
for p := lower; p.Compare(upper.Sub(spread)) <= 0; p = p.Add(spread) {
|
||||||
price := filterPrice(p, prec)
|
price := roundAndTruncatePrice(p, prec)
|
||||||
pins = append(pins, Pin(price))
|
pins = append(pins, Pin(price))
|
||||||
}
|
}
|
||||||
|
|
||||||
// this makes sure there is no error at the upper price
|
// this makes sure there is no error at the upper price
|
||||||
upperPrice := filterPrice(upper, prec)
|
upperPrice := roundAndTruncatePrice(upper, prec)
|
||||||
pins = append(pins, Pin(upperPrice))
|
pins = append(pins, Pin(upperPrice))
|
||||||
|
|
||||||
return pins
|
return pins
|
||||||
|
|
|
@ -243,8 +243,8 @@ func Test_filterPrice1(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
rst := filterPrice(tt.args.p, tt.args.prec)
|
rst := roundAndTruncatePrice(tt.args.p, tt.args.prec)
|
||||||
assert.Equalf(t, tt.want, rst.String(), "filterPrice(%v, %v)", tt.args.p, tt.args.prec)
|
assert.Equalf(t, tt.want, rst.String(), "roundAndTruncatePrice(%v, %v)", tt.args.p, tt.args.prec)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user