Merge pull request #1148 from c9s/grid2/fix/emit-ready-twice

FIX: fix emit ready twice and add error log
This commit is contained in:
kbearXD 2023-04-14 19:21:36 +08:00 committed by GitHub
commit 6fc3ee6a95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 6 deletions

View File

@ -58,13 +58,12 @@ func (s *Strategy) recoverByScanningTrades(ctx context.Context, session *bbgo.Ex
return errors.Wrap(err, "grid recover error")
}
// emit ready after recover
s.EmitGridReady()
// debug and send metrics
// wait for the reverse order to be placed
time.Sleep(2 * time.Second)
debugGrid(s.logger, s.grid, s.orderExecutor.ActiveMakerOrders())
// emit ready after recover
s.EmitGridReady()
s.updateGridNumOfOrdersMetricsWithLock()
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
@ -88,9 +87,6 @@ func (s *Strategy) recoverWithOpenOrdersByScanningTrades(ctx context.Context, hi
s.debugLog("open orders nums: %d, expected nums: %d", numGridOpenOrders, expectedNumOfOrders)
if expectedNumOfOrders == numGridOpenOrders {
// no need to recover
s.EmitGridReady()
s.updateGridNumOfOrdersMetricsWithLock()
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
return nil
} else if expectedNumOfOrders < numGridOpenOrders {
return fmt.Errorf("amount of grid's open orders should not > amount of expected grid's orders")

View File

@ -1941,6 +1941,7 @@ func (s *Strategy) startProcess(ctx context.Context, session *bbgo.ExchangeSessi
s.logger.Infof("recoverWhenStart is set, trying to recover grid orders...")
if err := s.recoverGrid(ctx, session); err != nil {
// if recover fail, return and do not open grid
s.logger.WithError(err).Error("failed to start process, recover error")
s.EmitGridError(errors.Wrapf(err, "failed to start process, recover error"))
return
}