mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #1479 from c9s/narumi/xgap/fix
This commit is contained in:
commit
f2d5731acf
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user