Skip to content

Commit

Permalink
Merge pull request #1632 from c9s/narumi/bbgo-sync-common-strategy
Browse files Browse the repository at this point in the history
FIX: disable bbgo.sync in common strategy to fix xgap
  • Loading branch information
c9s authored May 15, 2024
2 parents 1d35be8 + 095ca85 commit 62e236e
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/strategy/autobuy/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
s.cancelOrders(ctx)
bbgo.Sync(ctx, s)
})

s.cron = cron.New()
Expand Down
3 changes: 0 additions & 3 deletions pkg/strategy/common/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ func (s *Strategy) Initialize(ctx context.Context, environ *bbgo.Environment, se
s.OrderExecutor.BindEnvironment(environ)
s.OrderExecutor.BindProfitStats(s.ProfitStats)
s.OrderExecutor.Bind()
s.OrderExecutor.TradeCollector().OnPositionUpdate(func(position *types.Position) {
bbgo.Sync(ctx, s)
})

if !s.PositionHardLimit.IsZero() && !s.MaxPositionQuantity.IsZero() {
log.Infof("positionHardLimit and maxPositionQuantity are configured, setting up PositionRiskControl...")
Expand Down
1 change: 1 addition & 0 deletions pkg/strategy/emacross/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.

bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
bbgo.Sync(ctx, s)
})

return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/strategy/fixedmaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
_ = s.OrderExecutor.GracefulCancel(ctx)
bbgo.Sync(ctx, s)
})

return nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/strategy/liquiditymaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
if err := tradingutil.UniversalCancelAllOrders(ctx, s.Session.Exchange, nil); err != nil {
util.LogErr(err, "unable to cancel all orders")
}

bbgo.Sync(ctx, s)
})

return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/strategy/random/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
_ = s.OrderExecutor.GracefulCancel(ctx)
bbgo.Sync(ctx, s)
})

s.cron = cron.New()
Expand Down
1 change: 1 addition & 0 deletions pkg/strategy/rebalance/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
_ = s.OrderExecutorMap.GracefulCancel(ctx)
bbgo.Sync(ctx, s)
})

s.cron = cron.New()
Expand Down
1 change: 1 addition & 0 deletions pkg/strategy/rsicross/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se

bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
bbgo.Sync(ctx, s)
})

return nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/strategy/scmaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.

err = s.adjustmentOrderBook.GracefulCancel(ctx, s.Session.Exchange)
util.LogErr(err, "unable to cancel adjustment orders")

bbgo.Sync(ctx, s)
})

return nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/strategy/wall/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.

// check if there is a canceled order had partially filled.
s.OrderExecutor.TradeCollector().Process()

bbgo.Sync(ctx, s)
})

return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/strategy/xfixedmaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
_ = s.OrderExecutor.GracefulCancel(ctx)
bbgo.Sync(ctx, s)
})
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/strategy/xgap/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
close(s.stopC)
bbgo.Sync(context.Background(), s)
bbgo.Sync(ctx, s)
})

// from here, set data binding
Expand Down

0 comments on commit 62e236e

Please sign in to comment.