Merge pull request #1062 from c9s/fix/grid2/recover-sorting

fix: grid2: fix recover sorting
This commit is contained in:
Yo-An Lin 2023-02-22 09:58:55 +08:00 committed by GitHub
commit 09db017101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -223,6 +223,8 @@ func (e *GeneralOrderExecutor) SubmitOrders(ctx context.Context, submitOrders ..
}
if len(errIdx) > 0 {
time.Sleep(200 * time.Millisecond)
createdOrders2, err2 := BatchRetryPlaceOrder(ctx, e.session.Exchange, errIdx, formattedOrders...)
if err2 != nil {
err = multierr.Append(err, err2)

View File

@ -1238,9 +1238,9 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
// for reverse order recovering, we need the orders to be sort by update time ascending-ly
types.SortOrdersUpdateTimeAscending(tmpOrders)
if len(tmpOrders) > 1 && len(tmpOrders) == int(s.GridNum)+1 {
if len(tmpOrders) > 1 && len(tmpOrders) == int(s.GridNum) {
// remove the latest updated order because it's near the empty slot
tmpOrders = tmpOrders[:len(tmpOrders)-1]
tmpOrders = tmpOrders[1:]
}
// we will only submit reverse orders for filled orders
@ -1248,7 +1248,7 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
s.logger.Infof("GRID RECOVER: found %d filled grid orders, will re-replay the order event in the following order:", len(filledOrders))
for i, o := range filledOrders {
s.logger.Infof("%d) %s", i, o.String())
s.logger.Infof("%d) %s", i+1, o.String())
}
// before we re-play the orders,
@ -1264,8 +1264,12 @@ func (s *Strategy) recoverGridWithOpenOrders(ctx context.Context, historyService
for _, o := range filledOrders {
s.processFilledOrder(o)
time.Sleep(100 * time.Millisecond)
}
// wait for the reverse order to be placed
time.Sleep(2 * time.Second)
s.logger.Infof("GRID RECOVER COMPLETE")
debugGrid(grid, s.orderExecutor.ActiveMakerOrders())