Skip to content

Commit

Permalink
sync position to redis
Browse files Browse the repository at this point in the history
  • Loading branch information
narumiruna committed May 3, 2024
1 parent b35cfbe commit aac2105
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/strategy/atrpin/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit aac2105

Please sign in to comment.