mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo.sync when syncActiveOrders
This commit is contained in:
parent
dcff850c64
commit
c8becbe4f5
|
@ -30,7 +30,7 @@ func (s *Strategy) initializeRecoverC() bool {
|
|||
|
||||
if s.recoverC == nil {
|
||||
s.logger.Info("initializing recover channel")
|
||||
s.recoverC = make(chan struct{}, 1)
|
||||
s.recoverC = make(chan struct{}, 10)
|
||||
} else {
|
||||
s.logger.Info("recover channel is already initialized, trigger active orders recover")
|
||||
isInitialize = true
|
||||
|
@ -66,22 +66,26 @@ func (s *Strategy) recoverActiveOrdersPeriodically(ctx context.Context) {
|
|||
exchange: s.session.Exchange,
|
||||
}
|
||||
|
||||
var lastRecoverTime time.Time
|
||||
|
||||
for {
|
||||
select {
|
||||
|
||||
case <-ctx.Done():
|
||||
return
|
||||
|
||||
case <-ticker.C:
|
||||
if err := syncActiveOrders(ctx, opts); err != nil {
|
||||
log.WithError(err).Errorf("unable to sync active orders")
|
||||
}
|
||||
|
||||
s.recoverC <- struct{}{}
|
||||
bbgo.Sync(ctx, s)
|
||||
case <-s.recoverC:
|
||||
if err := syncActiveOrders(ctx, opts); err != nil {
|
||||
log.WithError(err).Errorf("unable to sync active orders")
|
||||
if !time.Now().After(lastRecoverTime.Add(10 * time.Minute)) {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := syncActiveOrders(ctx, opts); err != nil {
|
||||
log.WithError(err).Errorf("unable to sync active orders")
|
||||
} else {
|
||||
lastRecoverTime = time.Now()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user