Merge pull request #1088 from c9s/fix/grid2/recover

This commit is contained in:
Yo-An Lin 2023-03-08 18:42:16 +08:00 committed by GitHub
commit 93dc8e3147
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 12 deletions

View File

@ -1413,9 +1413,10 @@ 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
s.addOrdersToActiveOrderBook(gridOrders)
s.setGrid(grid)
s.EmitGridReady()
s.updateGridNumOfOrdersMetrics()
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
for i := range filledOrders {
// avoid using the iterator
@ -1523,14 +1524,11 @@ func (s *Strategy) replayOrderHistory(ctx context.Context, grid *Grid, orderBook
return nil
}
// isCompleteGridOrderBook checks if the number of open orders == gridNum - 1 and all orders are active order
func isCompleteGridOrderBook(orderBook *bbgo.ActiveOrderBook, gridNum int64) bool {
tmpOrders := orderBook.Orders()
if len(tmpOrders) == int(gridNum) && types.OrdersAll(tmpOrders, types.IsActiveOrder) {
return true
}
return false
activeOrders := types.OrdersActive(tmpOrders)
return len(activeOrders) == int(gridNum)-1
}
func findEarliestOrderID(orders []types.Order) (uint64, bool) {

View File

@ -395,17 +395,25 @@ func (o Order) SlackAttachment() slack.Attachment {
}
}
func OrdersFilled(in []Order) (out []Order) {
func OrdersFilter(in []Order, f func(o Order) bool) (out []Order) {
for _, o := range in {
switch o.Status {
case OrderStatusFilled:
o2 := o
out = append(out, o2)
if f(o) {
out = append(out, o)
}
}
return out
}
func OrdersActive(in []Order) []Order {
return OrdersFilter(in, IsActiveOrder)
}
func OrdersFilled(in []Order) (out []Order) {
return OrdersFilter(in, func(o Order) bool {
return o.Status == OrderStatusFilled
})
}
func OrdersAll(orders []Order, f func(o Order) bool) bool {
for _, o := range orders {
if !f(o) {