Skip to content

Commit fc1efff

Browse files
authored
Merge pull request #1081 from c9s/bhwu/fix-recover
2 parents 45da0bd + ec0d438 commit fc1efff

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

pkg/strategy/grid2/strategy.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -1341,8 +1341,11 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
13411341
missingPrices := scanMissingPinPrices(orderBook, grid.Pins)
13421342
if numMissing := len(missingPrices); numMissing <= 1 {
13431343
s.logger.Infof("GRID RECOVER: no missing grid prices, stop re-playing order history")
1344+
s.addOrdersToActiveOrderBook(gridOrders)
13441345
s.setGrid(grid)
13451346
s.EmitGridReady()
1347+
s.updateGridNumOfOrdersMetrics()
1348+
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
13461349
return nil
13471350
} else {
13481351
s.logger.Infof("GRID RECOVER: found missing prices: %v", missingPrices)
@@ -1384,8 +1387,11 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
13841387
// if all orders on the order book are active orders, we don't need to recover.
13851388
if isCompleteGridOrderBook(orderBook, s.GridNum) {
13861389
s.logger.Infof("GRID RECOVER: all orders are active orders, do not need recover")
1390+
s.addOrdersToActiveOrderBook(gridOrders)
13871391
s.setGrid(grid)
13881392
s.EmitGridReady()
1393+
s.updateGridNumOfOrdersMetrics()
1394+
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
13891395
return nil
13901396
}
13911397

@@ -1407,11 +1413,7 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
14071413

14081414
// before we re-play the orders,
14091415
// we need to add these open orders to the active order book
1410-
activeOrderBook := s.orderExecutor.ActiveMakerOrders()
1411-
for _, gridOrder := range gridOrders {
1412-
// put the order back to the active order book so that we can receive order update
1413-
activeOrderBook.Add(gridOrder)
1414-
}
1416+
s.addOrdersToActiveOrderBook(gridOrders)
14151417

14161418
s.setGrid(grid)
14171419
s.EmitGridReady()
@@ -1435,6 +1437,14 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
14351437
return nil
14361438
}
14371439

1440+
func (s *Strategy) addOrdersToActiveOrderBook(gridOrders []types.Order) {
1441+
activeOrderBook := s.orderExecutor.ActiveMakerOrders()
1442+
for _, gridOrder := range gridOrders {
1443+
// put the order back to the active order book so that we can receive order update
1444+
activeOrderBook.Add(gridOrder)
1445+
}
1446+
}
1447+
14381448
func (s *Strategy) setGrid(grid *Grid) {
14391449
s.mu.Lock()
14401450
s.grid = grid
@@ -1857,4 +1867,4 @@ func roundUpMarketQuantity(market types.Market, v fixedpoint.Value, c string) (f
18571867
}
18581868

18591869
return v.Round(prec, fixedpoint.Up), prec
1860-
}
1870+
}

0 commit comments

Comments
 (0)