FIX: [grid2] fix active orderbook at recovering

This commit is contained in:
gx578007 2023-03-05 14:29:31 +08:00
parent 45da0bd4c7
commit ec0d438f9d

View File

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