mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #1056 from c9s/fix/grid2/upper-price
grid2: fix upper price error
This commit is contained in:
commit
7ed0a0225e
|
@ -40,13 +40,16 @@ func calculateArithmeticPins(lower, upper, spread, tickSize fixedpoint.Value) []
|
|||
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) {
|
||||
for p := lower; p.Compare(upper.Sub(spread)) <= 0; p = p.Add(spread) {
|
||||
pp := math.Round(p.Float64()*pow10*10.0) / 10.0
|
||||
pp = math.Trunc(pp) / pow10
|
||||
pin := Pin(fixedpoint.NewFromFloat(pp))
|
||||
pins = append(pins, pin)
|
||||
}
|
||||
|
||||
// this makes sure there is no error at the upper price
|
||||
pins = append(pins, Pin(upper))
|
||||
|
||||
return pins
|
||||
}
|
||||
|
||||
|
|
|
@ -956,7 +956,8 @@ func (s *Strategy) generateGridOrders(totalQuote, totalBase, lastPrice fixedpoin
|
|||
})
|
||||
usedBase = usedBase.Add(quantity)
|
||||
} else if i > 0 {
|
||||
// next price
|
||||
// if we don't have enough base asset
|
||||
// then we need to place a buy order at the next price.
|
||||
nextPin := pins[i-1]
|
||||
nextPrice := fixedpoint.Value(nextPin)
|
||||
submitOrders = append(submitOrders, types.SubmitOrder{
|
||||
|
@ -975,10 +976,17 @@ func (s *Strategy) generateGridOrders(totalQuote, totalBase, lastPrice fixedpoin
|
|||
// skip i == 0
|
||||
}
|
||||
} else {
|
||||
// if price spread is not enabled, and we have already placed a sell order index on the top of this price,
|
||||
// then we should skip
|
||||
if s.ProfitSpread.IsZero() && i+1 == si {
|
||||
continue
|
||||
}
|
||||
|
||||
// should never place a buy order at the upper price
|
||||
if i == len(pins)-1 {
|
||||
continue
|
||||
}
|
||||
|
||||
submitOrders = append(submitOrders, types.SubmitOrder{
|
||||
Symbol: s.Symbol,
|
||||
Type: types.OrderTypeLimit,
|
||||
|
|
Loading…
Reference in New Issue
Block a user