Skip to content

Commit

Permalink
Merge pull request #1615 from c9s/kbearXD/dca2/fix-panic
Browse files Browse the repository at this point in the history
FIX: fix dca2 panic problem
  • Loading branch information
kbearXD committed Apr 11, 2024
2 parents ffb2b27 + 2d45b5c commit e3a4887
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/strategy/dca2/active_order_recover.go
Expand Up @@ -52,10 +52,11 @@ func (s *Strategy) recoverActiveOrders(ctx context.Context) error {
}

opts := common.SyncActiveOrdersOpts{
Logger: s.logger,
Exchange: s.ExchangeSession.Exchange,
ActiveOrderBook: activeOrders,
OpenOrders: openOrders,
Logger: s.logger,
Exchange: s.ExchangeSession.Exchange,
OrderQueryService: s.orderQueryService,
ActiveOrderBook: activeOrders,
OpenOrders: openOrders,
}

return common.SyncActiveOrders(ctx, opts)
Expand Down
8 changes: 8 additions & 0 deletions pkg/strategy/dca2/strategy.go
Expand Up @@ -94,6 +94,7 @@ type Strategy struct {
nextStateC chan State
state State
roundCollector *RoundCollector
orderQueryService types.ExchangeOrderQueryService
takeProfitPrice fixedpoint.Value
startTimeOfNextRound time.Time
nextRoundPaused bool
Expand Down Expand Up @@ -193,6 +194,13 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
s.OrderGroupID = util.FNV32(instanceID) % math.MaxInt32
}

// orderQueryService
if service, ok := s.ExchangeSession.Exchange.(types.ExchangeOrderQueryService); ok {
s.orderQueryService = service
} else {
return fmt.Errorf("exchange %s doesn't support ExchangeOrderQueryService", s.ExchangeSession.ExchangeName)
}

// round collector
s.roundCollector = NewRoundCollector(s.logger, s.Symbol, s.OrderGroupID, s.ExchangeSession.Exchange)
if s.roundCollector == nil {
Expand Down

0 comments on commit e3a4887

Please sign in to comment.