grid2: rename filterPrice to roundAndTruncatePrice

This commit is contained in:
c9s 2024-02-23 18:50:57 +08:00
parent a298950be8
commit 36e90cf5ca
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 6 additions and 6 deletions

View File

@ -35,8 +35,8 @@ type Grid struct {
type Pin fixedpoint.Value
// filterPrice filters price with the given precision
func filterPrice(p fixedpoint.Value, prec int) fixedpoint.Value {
// roundAndTruncatePrice rounds the given price at prec-1 and then truncate the price at prec
func roundAndTruncatePrice(p fixedpoint.Value, prec int) fixedpoint.Value {
var pow10 = math.Pow10(prec)
pp := math.Round(p.Float64()*pow10*10.0) / 10.0
pp = math.Trunc(pp) / pow10
@ -71,12 +71,12 @@ func calculateArithmeticPins(lower, upper, spread, tickSize fixedpoint.Value) []
var ts = tickSize.Float64()
var prec = int(math.Round(math.Log10(ts) * -1.0))
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))
}
// this makes sure there is no error at the upper price
upperPrice := filterPrice(upper, prec)
upperPrice := roundAndTruncatePrice(upper, prec)
pins = append(pins, Pin(upperPrice))
return pins

View File

@ -243,8 +243,8 @@ func Test_filterPrice1(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rst := filterPrice(tt.args.p, tt.args.prec)
assert.Equalf(t, tt.want, rst.String(), "filterPrice(%v, %v)", tt.args.p, tt.args.prec)
rst := roundAndTruncatePrice(tt.args.p, tt.args.prec)
assert.Equalf(t, tt.want, rst.String(), "roundAndTruncatePrice(%v, %v)", tt.args.p, tt.args.prec)
})
}
}