new flag DisableOrderGroupIDFilter to only query order group id

This commit is contained in:
kbearXD 2024-05-30 17:23:22 +08:00
parent 1d0b4e5cb8
commit 60160cd7b4
3 changed files with 16 additions and 13 deletions

View File

@ -22,9 +22,10 @@ type Round struct {
} }
type Collector struct { type Collector struct {
logger *logrus.Entry logger *logrus.Entry
symbol string symbol string
groupID uint32 groupID uint32
filterGroupID bool
// service // service
ex types.Exchange ex types.Exchange
@ -34,7 +35,7 @@ type Collector struct {
queryClosedOrderDesc descendingClosedOrderQueryService 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) historyService, ok := ex.(types.ExchangeTradeHistoryService)
if !ok { if !ok {
logger.Errorf("exchange %s doesn't support ExchangeTradeHistoryService", ex.Name()) 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, logger: logger,
symbol: symbol, symbol: symbol,
groupID: groupID, groupID: groupID,
filterGroupID: filterGroupID,
ex: ex, ex: ex,
historyService: historyService, historyService: historyService,
queryService: queryService, queryService: queryService,
@ -99,7 +101,7 @@ func (rc Collector) CollectCurrentRound(ctx context.Context) (Round, error) {
lastSide := takeProfitSide lastSide := takeProfitSide
for _, order := range allOrders { for _, order := range allOrders {
// group id filter is used for debug when local running // group id filter is used for debug when local running
if order.GroupID != rc.groupID { if rc.filterGroupID && order.GroupID != rc.groupID {
continue continue
} }
@ -135,7 +137,7 @@ func (rc *Collector) CollectFinishRounds(ctx context.Context, fromOrderID uint64
var round Round var round Round
for _, order := range orders { for _, order := range orders {
// skip not this strategy order // skip not this strategy order
if order.GroupID != rc.groupID { if rc.filterGroupID && order.GroupID != rc.groupID {
continue continue
} }
@ -146,14 +148,14 @@ func (rc *Collector) CollectFinishRounds(ctx context.Context, fromOrderID uint64
round.TakeProfitOrders = append(round.TakeProfitOrders, order) round.TakeProfitOrders = append(round.TakeProfitOrders, order)
if order.Status != types.OrderStatusFilled { 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 continue
} }
for _, o := range round.TakeProfitOrders { for _, o := range round.TakeProfitOrders {
if types.IsActiveOrder(o) { if types.IsActiveOrder(o) {
// Should not happen ! but we only log it // 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())
} }
} }

View File

@ -18,7 +18,7 @@ func Test_NewCollector(t *testing.T) {
mockEx := mocks.NewMockExchange(mockCtrl) mockEx := mocks.NewMockExchange(mockCtrl)
mockEx.EXPECT().Name().Return(types.ExchangeMax) mockEx.EXPECT().Name().Return(types.ExchangeMax)
collector := NewCollector(logger, symbol, 0, mockEx) collector := NewCollector(logger, symbol, 0, false, mockEx)
assert.Nil(t, collector) assert.Nil(t, collector)
}) })
@ -40,7 +40,7 @@ func Test_NewCollector(t *testing.T) {
ExchangeTradeHistoryService: mockTradeHistoryService, ExchangeTradeHistoryService: mockTradeHistoryService,
} }
collector := NewCollector(logger, symbol, 0, ex) collector := NewCollector(logger, symbol, 0, false, ex)
assert.Nil(t, collector) assert.Nil(t, collector)
}) })
@ -65,7 +65,7 @@ func Test_NewCollector(t *testing.T) {
ExchangeOrderQueryService: mockOrderQueryService, ExchangeOrderQueryService: mockOrderQueryService,
} }
collector := NewCollector(logger, symbol, 0, ex) collector := NewCollector(logger, symbol, 0, false, ex)
assert.Nil(t, collector) assert.Nil(t, collector)
}) })

View File

@ -63,7 +63,8 @@ type Strategy struct {
CoolDownInterval types.Duration `json:"coolDownInterval"` CoolDownInterval types.Duration `json:"coolDownInterval"`
// OrderGroupID is the group ID used for the strategy instance for canceling orders // 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 option is used for recovering dca states
RecoverWhenStart bool `json:"recoverWhenStart"` RecoverWhenStart bool `json:"recoverWhenStart"`
@ -185,7 +186,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
} }
// collector // 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 { if s.collector == nil {
return fmt.Errorf("failed to initialize collector") return fmt.Errorf("failed to initialize collector")
} }