bbgo: add order update time check

This commit is contained in:
c9s 2023-08-17 17:31:24 +08:00
parent 1cadaf9265
commit c91861ca9a
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 11 additions and 16 deletions

View File

@ -254,18 +254,6 @@ func (b *ActiveOrderBook) Print() {
}
}
// update updates the order stores in the internal order storage
func (b *ActiveOrderBook) update(orders ...types.Order) {
hasSymbol := len(b.Symbol) > 0
for _, order := range orders {
if hasSymbol && b.Symbol != order.Symbol {
continue
}
b.orders.Update(order)
}
}
// Update updates the order by the order status and emit the related events.
// When order is filled, the order will be removed from the internal order storage.
// When order is New or PartiallyFilled, the internal order will be updated according to the latest order update.
@ -283,6 +271,15 @@ func (b *ActiveOrderBook) Update(order types.Order) {
return
}
// if order update time is too old, skip it
if previousOrder, ok := b.orders.Get(order.OrderID); ok {
previousUpdateTime := previousOrder.UpdateTime.Time()
if !previousUpdateTime.IsZero() && order.UpdateTime.Before(previousUpdateTime) {
b.mu.Unlock()
return
}
}
switch order.Status {
case types.OrderStatusFilled:
// make sure we have the order and we remove it
@ -295,11 +292,11 @@ func (b *ActiveOrderBook) Update(order types.Order) {
b.C.Emit()
case types.OrderStatusPartiallyFilled:
b.update(order)
b.orders.Update(order)
b.mu.Unlock()
case types.OrderStatusNew:
b.update(order)
b.orders.Update(order)
b.mu.Unlock()
b.C.Emit()

View File

@ -2127,9 +2127,7 @@ func (s *Strategy) handleConnect(ctx context.Context, session *bbgo.ExchangeSess
activeOrderBook := s.orderExecutor.ActiveMakerOrders()
activeOrders := activeOrderBook.Orders()
for _, o := range activeOrders {
var updatedOrder *types.Order
err := retry.GeneralBackoff(ctx, func() error {
var err error
updatedOrder, err = s.orderQueryService.QueryOrder(ctx, types.OrderQuery{