Skip to content

Commit

Permalink
Merge pull request #1479 from c9s/narumi/xgap/fix
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s authored Jan 4, 2024
2 parents 3dca9aa + 94fb883 commit f2d5731
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/strategy/xgap/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (

const ID = "xgap"

const stateKey = "state-v1"

var log = logrus.WithField("strategy", ID)

var StepPercentageGap = fixedpoint.NewFromFloat(0.05)
Expand Down Expand Up @@ -77,6 +75,8 @@ type Strategy struct {
sourceBook, tradingBook *types.StreamOrderBook
groupID uint32

activeOrderBook *bbgo.ActiveOrderBook

stopC chan struct{}
}

Expand Down Expand Up @@ -213,6 +213,9 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
s.groupID = util.FNV32(instanceID) % math.MaxInt32
log.Infof("using group id %d from fnv32(%s)", s.groupID, instanceID)

s.activeOrderBook = bbgo.NewActiveOrderBook(s.Symbol)
s.activeOrderBook.BindStream(s.tradingSession.UserDataStream)

go func() {
ticker := time.NewTicker(
util.MillisecondsJitter(s.UpdateInterval.Duration(), 1000),
Expand Down Expand Up @@ -355,9 +358,11 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
log.WithError(err).Error("order submit error")
}

s.activeOrderBook.Add(createdOrders...)

time.Sleep(time.Second)

if err := tradingSession.Exchange.CancelOrders(ctx, createdOrders...); err != nil {
if err := s.activeOrderBook.GracefulCancel(ctx, s.tradingSession.Exchange); err != nil {
log.WithError(err).Error("cancel order error")
}
}
Expand Down

0 comments on commit f2d5731

Please sign in to comment.