mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
new flag DisableOrderGroupIDFilter to only query order group id
This commit is contained in:
parent
1d0b4e5cb8
commit
60160cd7b4
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user