mirror of
https://github.com/c9s/bbgo.git
synced 2024-09-20 08:11:08 +00:00
fix f.loadDepthSnapshot timing
This commit is contained in:
parent
50fc1fd3ac
commit
cabc082713
|
@ -32,6 +32,10 @@ func (f *DepthFrame) Reset() {
|
|||
}
|
||||
|
||||
func (f *DepthFrame) loadDepthSnapshot() {
|
||||
if debugBinanceDepth {
|
||||
log.Infof("loading %s depth from the restful api", f.Symbol)
|
||||
}
|
||||
|
||||
depth, err := f.fetch(f.context)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -80,14 +84,14 @@ func (f *DepthFrame) PushEvent(e DepthEvent) {
|
|||
f.BufEvents = append(f.BufEvents, e)
|
||||
f.mu.Unlock()
|
||||
|
||||
f.loadDepthSnapshot()
|
||||
|
||||
// start a worker to update the snapshot periodically.
|
||||
go f.once.Do(func() {
|
||||
if debugBinanceDepth {
|
||||
log.Infof("starting depth snapshot updater for %s market", f.Symbol)
|
||||
}
|
||||
|
||||
f.loadDepthSnapshot()
|
||||
|
||||
ticker := time.NewTicker(1*time.Minute + time.Duration(rand.Intn(10))*time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
|
|
|
@ -78,9 +78,9 @@ func NewStream(client *binance.Client) *Stream {
|
|||
f, ok := stream.depthFrames[e.Symbol]
|
||||
if !ok {
|
||||
f = &DepthFrame{
|
||||
client: client,
|
||||
client: client,
|
||||
context: context.Background(),
|
||||
Symbol: e.Symbol,
|
||||
Symbol: e.Symbol,
|
||||
}
|
||||
|
||||
stream.depthFrames[e.Symbol] = f
|
||||
|
|
Loading…
Reference in New Issue
Block a user