bbgo: triggering pending order update event ot the handler

This commit is contained in:
c9s 2023-02-23 18:08:21 +08:00
parent 31c9ebf34b
commit b666c8bf40
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 15 additions and 4 deletions

View File

@ -307,13 +307,23 @@ func (b *ActiveOrderBook) Add(orders ...types.Order) {
// add the order to the active order book and check the pending order
func (b *ActiveOrderBook) add(order types.Order) {
if pendingOrder, ok := b.pendingOrderUpdates.Get(order.OrderID); ok {
// if the pending order update time is newer than the adding order
// we should use the pending order rather than the adding order.
// if pending order is older, than we should add the new one, and drop the pending order
if pendingOrder.UpdateTime.Time().After(order.UpdateTime.Time()) {
b.orders.Add(pendingOrder)
} else {
b.orders.Add(order)
order = pendingOrder
}
b.orders.Add(order)
b.pendingOrderUpdates.Remove(pendingOrder.OrderID)
// when using add(order), it's usually a new maker order on the order book.
// so, when it's not status=new, we should trigger order update handler
if order.Status != types.OrderStatusNew {
// emit the order update handle function to trigger callback
b.orderUpdateHandler(order)
}
b.pendingOrderUpdates.Remove(order.OrderID)
} else {
b.orders.Add(order)
}

View File

@ -1615,6 +1615,7 @@ func (s *Strategy) recoverGrid(ctx context.Context, session *bbgo.ExchangeSessio
}
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
return nil
}
// openOrdersMismatches verifies if the open orders are on the grid pins