This commit is contained in:
chiahung 2023-11-07 17:00:29 +08:00
parent df2fd170db
commit 4a40c8bea2
2 changed files with 20 additions and 8 deletions

View File

@ -116,12 +116,16 @@ func syncActiveOrders(ctx context.Context, opts SyncActiveOrdersOpts) error {
// no need to sync active order already in active orderbook, because we only need to know if it filled or not. // no need to sync active order already in active orderbook, because we only need to know if it filled or not.
delete(openOrdersMap, activeOrder.OrderID) delete(openOrdersMap, activeOrder.OrderID)
} else { } else {
opts.logger.Infof("found active order #%d is not in the open orders, updating...", activeOrder.OrderID) opts.logger.Infof("[ActiveOrderRecover] found active order #%d is not in the open orders, updating...", activeOrder.OrderID)
if isActiveOrderBookUpdated, err := syncActiveOrder(ctx, opts.activeOrderBook, opts.orderQueryService, activeOrder.OrderID, syncBefore); err != nil { isActiveOrderBookUpdated, err := syncActiveOrder(ctx, opts.activeOrderBook, opts.orderQueryService, activeOrder.OrderID, syncBefore)
if err != nil {
opts.logger.WithError(err).Errorf("[ActiveOrderRecover] unable to query order #%d", activeOrder.OrderID) opts.logger.WithError(err).Errorf("[ActiveOrderRecover] unable to query order #%d", activeOrder.OrderID)
errs = multierr.Append(errs, err) errs = multierr.Append(errs, err)
} else if !isActiveOrderBookUpdated { continue
}
if !isActiveOrderBookUpdated {
opts.logger.Infof("[ActiveOrderRecover] active order #%d is updated in 3 min, skip updating...", activeOrder.OrderID) opts.logger.Infof("[ActiveOrderRecover] active order #%d is updated in 3 min, skip updating...", activeOrder.OrderID)
} }
} }

View File

@ -98,8 +98,8 @@ func (s *Strategy) recover(ctx context.Context) error {
activeOrdersInTwinOrderBook, err := buildTwinOrderBook(pins, activeOrders) activeOrdersInTwinOrderBook, err := buildTwinOrderBook(pins, activeOrders)
openOrdersInTwinOrderBook, err := buildTwinOrderBook(pins, openOrders) openOrdersInTwinOrderBook, err := buildTwinOrderBook(pins, openOrders)
s.logger.Infof("active orders' twin orderbook\n%s", activeOrdersInTwinOrderBook.String()) s.logger.Infof("[Recover] active orders' twin orderbook\n%s", activeOrdersInTwinOrderBook.String())
s.logger.Infof("open orders in twin orderbook\n%s", openOrdersInTwinOrderBook.String()) s.logger.Infof("[Recover] open orders in twin orderbook\n%s", openOrdersInTwinOrderBook.String())
// remove index 0, because twin orderbook's price is from the second one // remove index 0, because twin orderbook's price is from the second one
pins = pins[1:] pins = pins[1:]
@ -131,7 +131,9 @@ func (s *Strategy) recover(ctx context.Context) error {
// case 1 // case 1
if activeOrderID == 0 { if activeOrderID == 0 {
activeOrderBook.Add(openOrder.GetOrder()) order := openOrder.GetOrder()
s.logger.Infof("[Recover] found open order #%d is not in the active orderbook, adding...", order.OrderID)
activeOrderBook.Add(order)
// also add open orders into active order's twin orderbook, we will use this active orderbook to recover empty price grid // also add open orders into active order's twin orderbook, we will use this active orderbook to recover empty price grid
activeOrdersInTwinOrderBook.AddTwinOrder(v, openOrder) activeOrdersInTwinOrderBook.AddTwinOrder(v, openOrder)
continue continue
@ -140,11 +142,17 @@ func (s *Strategy) recover(ctx context.Context) error {
// case 2 // case 2
if openOrderID == 0 { if openOrderID == 0 {
order := activeOrder.GetOrder() order := activeOrder.GetOrder()
if isActiveOrderBookUpdated, err := syncActiveOrder(ctx, activeOrderBook, s.orderQueryService, order.OrderID, syncBefore); err != nil { s.logger.Infof("[Recover] found active order #%d is not in the open orders, updating...", order.OrderID)
isActiveOrderBookUpdated, err := syncActiveOrder(ctx, activeOrderBook, s.orderQueryService, order.OrderID, syncBefore)
if err != nil {
s.logger.WithError(err).Errorf("[Recover] unable to query order #%d", order.OrderID) s.logger.WithError(err).Errorf("[Recover] unable to query order #%d", order.OrderID)
} else if !isActiveOrderBookUpdated { continue
}
if !isActiveOrderBookUpdated {
s.logger.Infof("[Recover] active order #%d is updated in 3 min, skip updating...", order.OrderID) s.logger.Infof("[Recover] active order #%d is updated in 3 min, skip updating...", order.OrderID)
} }
continue continue
} }