mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
FIX: [grid2] fix active orderbook at recovering
This commit is contained in:
parent
45da0bd4c7
commit
ec0d438f9d
|
@ -1341,8 +1341,11 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
|
|||
missingPrices := scanMissingPinPrices(orderBook, grid.Pins)
|
||||
if numMissing := len(missingPrices); numMissing <= 1 {
|
||||
s.logger.Infof("GRID RECOVER: no missing grid prices, stop re-playing order history")
|
||||
s.addOrdersToActiveOrderBook(gridOrders)
|
||||
s.setGrid(grid)
|
||||
s.EmitGridReady()
|
||||
s.updateGridNumOfOrdersMetrics()
|
||||
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
|
||||
return nil
|
||||
} else {
|
||||
s.logger.Infof("GRID RECOVER: found missing prices: %v", missingPrices)
|
||||
|
@ -1384,8 +1387,11 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
|
|||
// if all orders on the order book are active orders, we don't need to recover.
|
||||
if isCompleteGridOrderBook(orderBook, s.GridNum) {
|
||||
s.logger.Infof("GRID RECOVER: all orders are active orders, do not need recover")
|
||||
s.addOrdersToActiveOrderBook(gridOrders)
|
||||
s.setGrid(grid)
|
||||
s.EmitGridReady()
|
||||
s.updateGridNumOfOrdersMetrics()
|
||||
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -1407,11 +1413,7 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
|
|||
|
||||
// before we re-play the orders,
|
||||
// we need to add these open orders to the active order book
|
||||
activeOrderBook := s.orderExecutor.ActiveMakerOrders()
|
||||
for _, gridOrder := range gridOrders {
|
||||
// put the order back to the active order book so that we can receive order update
|
||||
activeOrderBook.Add(gridOrder)
|
||||
}
|
||||
s.addOrdersToActiveOrderBook(gridOrders)
|
||||
|
||||
s.setGrid(grid)
|
||||
s.EmitGridReady()
|
||||
|
@ -1435,6 +1437,14 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Strategy) addOrdersToActiveOrderBook(gridOrders []types.Order) {
|
||||
activeOrderBook := s.orderExecutor.ActiveMakerOrders()
|
||||
for _, gridOrder := range gridOrders {
|
||||
// put the order back to the active order book so that we can receive order update
|
||||
activeOrderBook.Add(gridOrder)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Strategy) setGrid(grid *Grid) {
|
||||
s.mu.Lock()
|
||||
s.grid = grid
|
||||
|
@ -1857,4 +1867,4 @@ func roundUpMarketQuantity(market types.Market, v fixedpoint.Value, c string) (f
|
|||
}
|
||||
|
||||
return v.Round(prec, fixedpoint.Up), prec
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user