grid2: fix upper price buy order issue

This commit is contained in:
c9s 2023-02-10 17:51:50 +08:00
parent 34ab53303a
commit 4eca007d3d
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -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,