diff --git a/pkg/strategy/atrpin/strategy.go b/pkg/strategy/atrpin/strategy.go index 52d235677..8821d79a0 100644 --- a/pkg/strategy/atrpin/strategy.go +++ b/pkg/strategy/atrpin/strategy.go @@ -69,6 +69,9 @@ func (s *Strategy) Defaults() error { func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error { s.Strategy.Initialize(ctx, s.Environment, session, s.Market, ID, s.InstanceID()) + s.Strategy.OrderExecutor.TradeCollector().OnPositionUpdate(func(position *types.Position) { + bbgo.Sync(ctx, s) + }) atr := session.Indicators(s.Symbol).ATR(s.Interval, s.Window) @@ -87,10 +90,12 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se baseBalance, ok := account.Balance(s.Market.BaseCurrency) if !ok { log.Errorf("%s balance not found", s.Market.BaseCurrency) + return } quoteBalance, ok := account.Balance(s.Market.QuoteCurrency) if !ok { log.Errorf("%s balance not found", s.Market.QuoteCurrency) + return } lastAtr := atr.Last(0) @@ -203,6 +208,8 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se if err := s.Strategy.OrderExecutor.GracefulCancel(ctx); err != nil { log.WithError(err).Error("unable to cancel open orders...") } + + bbgo.Sync(ctx, s) }) return nil