disable bbgo.sync in common strategy

This commit is contained in:
narumi 2024-05-14 18:54:24 +08:00
parent 1d35be8d2a
commit 095ca85669
12 changed files with 14 additions and 4 deletions

View File

@ -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) { bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
s.cancelOrders(ctx) s.cancelOrders(ctx)
bbgo.Sync(ctx, s)
}) })
s.cron = cron.New() s.cron = cron.New()

View File

@ -69,9 +69,6 @@ func (s *Strategy) Initialize(ctx context.Context, environ *bbgo.Environment, se
s.OrderExecutor.BindEnvironment(environ) s.OrderExecutor.BindEnvironment(environ)
s.OrderExecutor.BindProfitStats(s.ProfitStats) s.OrderExecutor.BindProfitStats(s.ProfitStats)
s.OrderExecutor.Bind() s.OrderExecutor.Bind()
s.OrderExecutor.TradeCollector().OnPositionUpdate(func(position *types.Position) {
bbgo.Sync(ctx, s)
})
if !s.PositionHardLimit.IsZero() && !s.MaxPositionQuantity.IsZero() { if !s.PositionHardLimit.IsZero() && !s.MaxPositionQuantity.IsZero() {
log.Infof("positionHardLimit and maxPositionQuantity are configured, setting up PositionRiskControl...") log.Infof("positionHardLimit and maxPositionQuantity are configured, setting up PositionRiskControl...")

View File

@ -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) { bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
bbgo.Sync(ctx, s)
}) })
return nil return nil

View File

@ -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) { bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
_ = s.OrderExecutor.GracefulCancel(ctx) _ = s.OrderExecutor.GracefulCancel(ctx)
bbgo.Sync(ctx, s)
}) })
return nil return nil

View File

@ -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 { if err := tradingutil.UniversalCancelAllOrders(ctx, s.Session.Exchange, nil); err != nil {
util.LogErr(err, "unable to cancel all orders") util.LogErr(err, "unable to cancel all orders")
} }
bbgo.Sync(ctx, s)
}) })
return nil return nil

View File

@ -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) { bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
_ = s.OrderExecutor.GracefulCancel(ctx) _ = s.OrderExecutor.GracefulCancel(ctx)
bbgo.Sync(ctx, s)
}) })
s.cron = cron.New() s.cron = cron.New()

View File

@ -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) { bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
_ = s.OrderExecutorMap.GracefulCancel(ctx) _ = s.OrderExecutorMap.GracefulCancel(ctx)
bbgo.Sync(ctx, s)
}) })
s.cron = cron.New() s.cron = cron.New()

View File

@ -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) { bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
bbgo.Sync(ctx, s)
}) })
return nil return nil

View File

@ -148,6 +148,8 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
err = s.adjustmentOrderBook.GracefulCancel(ctx, s.Session.Exchange) err = s.adjustmentOrderBook.GracefulCancel(ctx, s.Session.Exchange)
util.LogErr(err, "unable to cancel adjustment orders") util.LogErr(err, "unable to cancel adjustment orders")
bbgo.Sync(ctx, s)
}) })
return nil return nil

View File

@ -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. // check if there is a canceled order had partially filled.
s.OrderExecutor.TradeCollector().Process() s.OrderExecutor.TradeCollector().Process()
bbgo.Sync(ctx, s)
}) })
return nil return nil

View File

@ -156,6 +156,7 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) { bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
_ = s.OrderExecutor.GracefulCancel(ctx) _ = s.OrderExecutor.GracefulCancel(ctx)
bbgo.Sync(ctx, s)
}) })
return nil return nil
} }

View File

@ -205,7 +205,7 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) { bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
close(s.stopC) close(s.stopC)
bbgo.Sync(context.Background(), s) bbgo.Sync(ctx, s)
}) })
// from here, set data binding // from here, set data binding