mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
grid2: only do active order update when grid is recovered
This commit is contained in:
parent
1600277ac3
commit
b6d0e3ef27
|
@ -9,6 +9,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
@ -205,6 +206,8 @@ type Strategy struct {
|
|||
tradingCtx, writeCtx context.Context
|
||||
cancelWrite context.CancelFunc
|
||||
|
||||
recovered int32
|
||||
|
||||
// this ensures that bbgo.Sync to lock the object
|
||||
sync.Mutex
|
||||
}
|
||||
|
@ -1982,11 +1985,16 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
|
|||
})
|
||||
}
|
||||
|
||||
session.UserDataStream.OnConnect(func() {
|
||||
session.UserDataStream.OnAuth(func() {
|
||||
if !bbgo.IsBackTesting {
|
||||
// callback may block the stream execution, so we spawn the recover function to the background
|
||||
// add (5 seconds + random <10 seconds jitter) delay
|
||||
go time.AfterFunc(util.MillisecondsJitter(5*time.Second, 1000*10), func() {
|
||||
recovered := atomic.LoadInt32(&s.recovered)
|
||||
if recovered == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
s.recoverActiveOrders(ctx, session)
|
||||
})
|
||||
}
|
||||
|
@ -2016,6 +2024,10 @@ func (s *Strategy) startProcess(ctx context.Context, session *bbgo.ExchangeSessi
|
|||
}
|
||||
|
||||
func (s *Strategy) recoverGrid(ctx context.Context, session *bbgo.ExchangeSession) error {
|
||||
defer func() {
|
||||
atomic.AddInt32(&s.recovered, 1)
|
||||
}()
|
||||
|
||||
if s.RecoverGridByScanningTrades {
|
||||
s.debugLog("recovering grid by scanning trades")
|
||||
return s.recoverByScanningTrades(ctx, session)
|
||||
|
|
Loading…
Reference in New Issue
Block a user