diff --git a/pkg/strategy/dca2/collector.go b/pkg/strategy/dca2/collector.go index 85907acd6..9d4201d9f 100644 --- a/pkg/strategy/dca2/collector.go +++ b/pkg/strategy/dca2/collector.go @@ -22,9 +22,10 @@ type Round struct { } type Collector struct { - logger *logrus.Entry - symbol string - groupID uint32 + logger *logrus.Entry + symbol string + groupID uint32 + filterGroupID bool // service ex types.Exchange @@ -34,7 +35,7 @@ type Collector struct { queryClosedOrderDesc descendingClosedOrderQueryService } -func NewCollector(logger *logrus.Entry, symbol string, groupID uint32, ex types.Exchange) *Collector { +func NewCollector(logger *logrus.Entry, symbol string, groupID uint32, filterGroupID bool, ex types.Exchange) *Collector { historyService, ok := ex.(types.ExchangeTradeHistoryService) if !ok { logger.Errorf("exchange %s doesn't support ExchangeTradeHistoryService", ex.Name()) @@ -63,6 +64,7 @@ func NewCollector(logger *logrus.Entry, symbol string, groupID uint32, ex types. logger: logger, symbol: symbol, groupID: groupID, + filterGroupID: filterGroupID, ex: ex, historyService: historyService, queryService: queryService, @@ -99,7 +101,7 @@ func (rc Collector) CollectCurrentRound(ctx context.Context) (Round, error) { lastSide := takeProfitSide for _, order := range allOrders { // group id filter is used for debug when local running - if order.GroupID != rc.groupID { + if rc.filterGroupID && order.GroupID != rc.groupID { continue } @@ -135,7 +137,7 @@ func (rc *Collector) CollectFinishRounds(ctx context.Context, fromOrderID uint64 var round Round for _, order := range orders { // skip not this strategy order - if order.GroupID != rc.groupID { + if rc.filterGroupID && order.GroupID != rc.groupID { continue } @@ -146,14 +148,14 @@ func (rc *Collector) CollectFinishRounds(ctx context.Context, fromOrderID uint64 round.TakeProfitOrders = append(round.TakeProfitOrders, order) if order.Status != types.OrderStatusFilled { - rc.logger.Infof("take-profit order is %s not filled, so this round is not finished. Keep collecting", order.Status) + rc.logger.Infof("take-profit order is not filled (%s), so this round is not finished. Keep collecting", order.Status) continue } for _, o := range round.TakeProfitOrders { if types.IsActiveOrder(o) { // Should not happen ! but we only log it - rc.logger.Errorf("there is at least one take-profit order (%d) is still active, please check it", o.OrderID) + rc.logger.Errorf("unexpected error, there is at least one take-profit order #%d is still active, please check it. %s", o.OrderID, o.String()) } } diff --git a/pkg/strategy/dca2/collector_test.go b/pkg/strategy/dca2/collector_test.go index 302ac6292..6818428a5 100644 --- a/pkg/strategy/dca2/collector_test.go +++ b/pkg/strategy/dca2/collector_test.go @@ -18,7 +18,7 @@ func Test_NewCollector(t *testing.T) { mockEx := mocks.NewMockExchange(mockCtrl) mockEx.EXPECT().Name().Return(types.ExchangeMax) - collector := NewCollector(logger, symbol, 0, mockEx) + collector := NewCollector(logger, symbol, 0, false, mockEx) assert.Nil(t, collector) }) @@ -40,7 +40,7 @@ func Test_NewCollector(t *testing.T) { ExchangeTradeHistoryService: mockTradeHistoryService, } - collector := NewCollector(logger, symbol, 0, ex) + collector := NewCollector(logger, symbol, 0, false, ex) assert.Nil(t, collector) }) @@ -65,7 +65,7 @@ func Test_NewCollector(t *testing.T) { ExchangeOrderQueryService: mockOrderQueryService, } - collector := NewCollector(logger, symbol, 0, ex) + collector := NewCollector(logger, symbol, 0, false, ex) assert.Nil(t, collector) }) diff --git a/pkg/strategy/dca2/strategy.go b/pkg/strategy/dca2/strategy.go index 9d23395a6..a43830700 100644 --- a/pkg/strategy/dca2/strategy.go +++ b/pkg/strategy/dca2/strategy.go @@ -63,7 +63,8 @@ type Strategy struct { CoolDownInterval types.Duration `json:"coolDownInterval"` // OrderGroupID is the group ID used for the strategy instance for canceling orders - OrderGroupID uint32 `json:"orderGroupID"` + OrderGroupID uint32 `json:"orderGroupID"` + DisableOrderGroupIDFilter bool `json:"disableOrderGroupIDFilter"` // RecoverWhenStart option is used for recovering dca states RecoverWhenStart bool `json:"recoverWhenStart"` @@ -185,7 +186,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo. } // collector - s.collector = NewCollector(s.logger, s.Symbol, s.OrderGroupID, s.ExchangeSession.Exchange) + s.collector = NewCollector(s.logger, s.Symbol, s.OrderGroupID, !s.DisableOrderGroupIDFilter, s.ExchangeSession.Exchange) if s.collector == nil { return fmt.Errorf("failed to initialize collector") }