mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
grid2: fix pin price algorithm
This commit is contained in:
parent
4bf0cb6a0c
commit
854ac4f8ea
|
@ -35,11 +35,14 @@ type Pin fixedpoint.Value
|
|||
|
||||
func calculateArithmeticPins(lower, upper, spread, tickSize fixedpoint.Value) []Pin {
|
||||
var pins []Pin
|
||||
|
||||
// tickSize number is like 0.01, 0.1, 0.001
|
||||
var ts = tickSize.Float64()
|
||||
var prec = int(math.Round(math.Log10(ts) * -1.0))
|
||||
var pow10 = math.Pow10(prec)
|
||||
for p := lower; p.Compare(upper) <= 0; p = p.Add(spread) {
|
||||
// tickSize here = 0.01
|
||||
pp := p.Float64() / ts
|
||||
pp = math.Round(pp) * ts
|
||||
pp := math.Round(p.Float64()*pow10*10.0) / 10.0
|
||||
pp = math.Trunc(pp) / pow10
|
||||
pin := Pin(fixedpoint.NewFromFloat(pp))
|
||||
pins = append(pins, pin)
|
||||
}
|
||||
|
|
|
@ -172,31 +172,31 @@ func Test_calculateArithmeticPins(t *testing.T) {
|
|||
Pin(number(1000.0)),
|
||||
Pin(number(1066.660)),
|
||||
Pin(number(1133.330)),
|
||||
Pin(number("1199.99")),
|
||||
Pin(number("1200.00")),
|
||||
Pin(number(1266.660)),
|
||||
Pin(number(1333.330)),
|
||||
Pin(number(1399.990)),
|
||||
Pin(number(1400.000)),
|
||||
Pin(number(1466.660)),
|
||||
Pin(number(1533.330)),
|
||||
Pin(number(1599.990)),
|
||||
Pin(number(1600.000)),
|
||||
Pin(number(1666.660)),
|
||||
Pin(number(1733.330)),
|
||||
Pin(number(1799.990)),
|
||||
Pin(number(1800.000)),
|
||||
Pin(number(1866.660)),
|
||||
Pin(number(1933.330)),
|
||||
Pin(number(1999.990)),
|
||||
Pin(number(2000.000)),
|
||||
Pin(number(2066.660)),
|
||||
Pin(number(2133.330)),
|
||||
Pin(number("2199.99")),
|
||||
Pin(number("2200.00")),
|
||||
Pin(number(2266.660)),
|
||||
Pin(number(2333.330)),
|
||||
Pin(number("2399.99")),
|
||||
Pin(number("2400.00")),
|
||||
Pin(number(2466.660)),
|
||||
Pin(number(2533.330)),
|
||||
Pin(number("2599.99")),
|
||||
Pin(number("2600.00")),
|
||||
Pin(number(2666.660)),
|
||||
Pin(number(2733.330)),
|
||||
Pin(number(2799.990)),
|
||||
Pin(number(2800.000)),
|
||||
Pin(number(2866.660)),
|
||||
Pin(number(2933.330)),
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user