From 095ca8566903c279a4a011aa380e3bc990f01409 Mon Sep 17 00:00:00 2001 From: narumi Date: Tue, 14 May 2024 18:54:24 +0800 Subject: [PATCH] disable bbgo.sync in common strategy --- pkg/strategy/autobuy/strategy.go | 1 + pkg/strategy/common/strategy.go | 3 --- pkg/strategy/emacross/strategy.go | 1 + pkg/strategy/fixedmaker/strategy.go | 1 + pkg/strategy/liquiditymaker/strategy.go | 2 ++ pkg/strategy/random/strategy.go | 1 + pkg/strategy/rebalance/strategy.go | 1 + pkg/strategy/rsicross/strategy.go | 1 + pkg/strategy/scmaker/strategy.go | 2 ++ pkg/strategy/wall/strategy.go | 2 ++ pkg/strategy/xfixedmaker/strategy.go | 1 + pkg/strategy/xgap/strategy.go | 2 +- 12 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/strategy/autobuy/strategy.go b/pkg/strategy/autobuy/strategy.go index 87e0bb1eb..ba66b924b 100644 --- a/pkg/strategy/autobuy/strategy.go +++ b/pkg/strategy/autobuy/strategy.go @@ -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() diff --git a/pkg/strategy/common/strategy.go b/pkg/strategy/common/strategy.go index 257334df7..5828ee38d 100644 --- a/pkg/strategy/common/strategy.go +++ b/pkg/strategy/common/strategy.go @@ -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...") diff --git a/pkg/strategy/emacross/strategy.go b/pkg/strategy/emacross/strategy.go index 1f0dda77d..d22585b71 100644 --- a/pkg/strategy/emacross/strategy.go +++ b/pkg/strategy/emacross/strategy.go @@ -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 diff --git a/pkg/strategy/fixedmaker/strategy.go b/pkg/strategy/fixedmaker/strategy.go index 8046636a8..fd665ec16 100644 --- a/pkg/strategy/fixedmaker/strategy.go +++ b/pkg/strategy/fixedmaker/strategy.go @@ -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 diff --git a/pkg/strategy/liquiditymaker/strategy.go b/pkg/strategy/liquiditymaker/strategy.go index 9f1d68d06..7c273dcbc 100644 --- a/pkg/strategy/liquiditymaker/strategy.go +++ b/pkg/strategy/liquiditymaker/strategy.go @@ -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 diff --git a/pkg/strategy/random/strategy.go b/pkg/strategy/random/strategy.go index 686be9112..cb62667af 100644 --- a/pkg/strategy/random/strategy.go +++ b/pkg/strategy/random/strategy.go @@ -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() diff --git a/pkg/strategy/rebalance/strategy.go b/pkg/strategy/rebalance/strategy.go index decbffde1..0b0ccef4c 100644 --- a/pkg/strategy/rebalance/strategy.go +++ b/pkg/strategy/rebalance/strategy.go @@ -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() diff --git a/pkg/strategy/rsicross/strategy.go b/pkg/strategy/rsicross/strategy.go index b0249d924..8807e06dd 100644 --- a/pkg/strategy/rsicross/strategy.go +++ b/pkg/strategy/rsicross/strategy.go @@ -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 diff --git a/pkg/strategy/scmaker/strategy.go b/pkg/strategy/scmaker/strategy.go index ec7ee55a7..1039c3431 100644 --- a/pkg/strategy/scmaker/strategy.go +++ b/pkg/strategy/scmaker/strategy.go @@ -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 diff --git a/pkg/strategy/wall/strategy.go b/pkg/strategy/wall/strategy.go index b097c9b42..39ef033f9 100644 --- a/pkg/strategy/wall/strategy.go +++ b/pkg/strategy/wall/strategy.go @@ -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 diff --git a/pkg/strategy/xfixedmaker/strategy.go b/pkg/strategy/xfixedmaker/strategy.go index 45d1bd78a..01b10b8c4 100644 --- a/pkg/strategy/xfixedmaker/strategy.go +++ b/pkg/strategy/xfixedmaker/strategy.go @@ -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 } diff --git a/pkg/strategy/xgap/strategy.go b/pkg/strategy/xgap/strategy.go index bd076b5f7..95e7faee1 100644 --- a/pkg/strategy/xgap/strategy.go +++ b/pkg/strategy/xgap/strategy.go @@ -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