depth: add SetUpdateTimeout

This commit is contained in:
c9s 2022-01-12 14:49:01 +08:00
parent 0c7710c91b
commit b3b1161ecc

View File

@ -5,9 +5,10 @@ import (
"sync" "sync"
"time" "time"
log "github.com/sirupsen/logrus"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/util" "github.com/c9s/bbgo/pkg/util"
log "github.com/sirupsen/logrus"
) )
type SnapshotFetcher func() (snapshot types.SliceOrderBook, finalUpdateID int64, err error) type SnapshotFetcher func() (snapshot types.SliceOrderBook, finalUpdateID int64, err error)
@ -35,6 +36,10 @@ type Buffer struct {
mu sync.Mutex mu sync.Mutex
once util.Reonce once util.Reonce
// updateTimeout the timeout duration when not receiving update messages
updateTimeout time.Duration
// bufferingPeriod is used to buffer the update message before we get the full depth
bufferingPeriod time.Duration bufferingPeriod time.Duration
} }
@ -45,6 +50,10 @@ func NewBuffer(fetcher SnapshotFetcher) *Buffer {
} }
} }
func (b *Buffer) SetUpdateTimeout(d time.Duration) {
b.updateTimeout = d
}
func (b *Buffer) SetBufferingPeriod(d time.Duration) { func (b *Buffer) SetBufferingPeriod(d time.Duration) {
b.bufferingPeriod = d b.bufferingPeriod = d
} }