FIX: fix emit ready twice and add error log

This commit is contained in:
chiahung 2023-04-14 18:30:38 +08:00
parent d63734f365
commit a0aae23bf3
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") return errors.Wrap(err, "grid recover error")
} }
// emit ready after recover
s.EmitGridReady()
// debug and send metrics // debug and send metrics
// wait for the reverse order to be placed // wait for the reverse order to be placed
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
debugGrid(s.logger, s.grid, s.orderExecutor.ActiveMakerOrders()) debugGrid(s.logger, s.grid, s.orderExecutor.ActiveMakerOrders())
// emit ready after recover
s.EmitGridReady()
s.updateGridNumOfOrdersMetricsWithLock() s.updateGridNumOfOrdersMetricsWithLock()
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders()) 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) s.debugLog("open orders nums: %d, expected nums: %d", numGridOpenOrders, expectedNumOfOrders)
if expectedNumOfOrders == numGridOpenOrders { if expectedNumOfOrders == numGridOpenOrders {
// no need to recover // no need to recover
s.EmitGridReady()
s.updateGridNumOfOrdersMetricsWithLock()
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
return nil return nil
} else if expectedNumOfOrders < numGridOpenOrders { } else if expectedNumOfOrders < numGridOpenOrders {
return fmt.Errorf("amount of grid's open orders should not > amount of expected grid's orders") 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...") s.logger.Infof("recoverWhenStart is set, trying to recover grid orders...")
if err := s.recoverGrid(ctx, session); err != nil { if err := s.recoverGrid(ctx, session); err != nil {
// if recover fail, return and do not open grid // 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")) s.EmitGridError(errors.Wrapf(err, "failed to start process, recover error"))
return return
} }