Skip to content

Commit

Permalink
new flag DisableOrderGroupIDFilter to only query order group id
Browse files Browse the repository at this point in the history
  • Loading branch information
kbearXD committed May 30, 2024
1 parent 1d0b4e5 commit 8415678
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
14 changes: 8 additions & 6 deletions pkg/strategy/dca2/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/strategy/dca2/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand All @@ -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)
})
Expand All @@ -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)
})
Expand Down
5 changes: 3 additions & 2 deletions pkg/strategy/dca2/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 8415678

Please sign in to comment.