diff --git a/pkg/strategy/grid2/strategy.go b/pkg/strategy/grid2/strategy.go index fb697b6ff..72c5bb174 100644 --- a/pkg/strategy/grid2/strategy.go +++ b/pkg/strategy/grid2/strategy.go @@ -186,6 +186,9 @@ type Strategy struct { gridClosedCallbacks []func() gridErrorCallbacks []func(err error) + // filledOrderIDMap is used to prevent processing the same order ID twice. + filledOrderIDMap *types.SyncOrderMap + // mu is used for locking the grid object field, avoid double grid opening mu sync.Mutex @@ -240,6 +243,7 @@ func (s *Strategy) Defaults() error { } func (s *Strategy) Initialize() error { + s.filledOrderIDMap = types.NewSyncOrderMap() s.logger = log.WithFields(s.LogFields) return nil } @@ -505,8 +509,8 @@ func (s *Strategy) processFilledOrder(o types.Order) { // we calculate profit only when the order is placed successfully if profit != nil { - s.logger.Infof("GENERATED GRID PROFIT: %+v", profit) s.GridProfitStats.AddProfit(profit) + s.logger.Infof("GENERATED GRID PROFIT: %+v; TOTAL GRID PROFIT BECOMES: %f", profit, s.GridProfitStats.TotalQuoteProfit.Float64()) s.EmitGridProfit(s.GridProfitStats, profit) } } @@ -518,6 +522,12 @@ func (s *Strategy) handleOrderFilled(o types.Order) { return } + if s.filledOrderIDMap.Exists(o.OrderID) { + s.logger.Warn("duplicated id (%d) of filled order detected", o.OrderID) + return + } + s.filledOrderIDMap.Add(o) + s.logger.Infof("GRID ORDER FILLED: %s", o.String()) s.updateFilledOrderMetrics(o) s.processFilledOrder(o) @@ -2130,4 +2140,4 @@ func queryOpenOrdersUntilSuccessful(ctx context.Context, ex types.Exchange, symb err = generalBackoff(ctx, op) return openOrders, err -} +} \ No newline at end of file