Merge pull request #1479 from c9s/narumi/xgap/fix

This commit is contained in:
c9s 2024-01-04 20:03:07 +08:00 committed by GitHub
commit f2d5731acf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,8 +18,6 @@ import (
const ID = "xgap"
const stateKey = "state-v1"
var log = logrus.WithField("strategy", ID)
var StepPercentageGap = fixedpoint.NewFromFloat(0.05)
@ -77,6 +75,8 @@ type Strategy struct {
sourceBook, tradingBook *types.StreamOrderBook
groupID uint32
activeOrderBook *bbgo.ActiveOrderBook
stopC chan struct{}
}
@ -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),
@ -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")
}
}