xmaker: check book before copying

This commit is contained in:
c9s 2021-06-07 17:02:24 +08:00
parent f5a241a1a8
commit 3fd170a4ff

View File

@ -194,9 +194,14 @@ func (s *Strategy) updateQuote(ctx context.Context, orderExecutionRouter bbgo.Or
return
}
sourceBook := s.book.Copy()
bestBid, bestAsk, hasPrice := s.book.BestBidAndAsk()
if !hasPrice {
return
}
sourceBook := s.book.CopyDepth(20)
if valid, err := sourceBook.IsValid(); !valid {
log.WithError(err).Errorf("%s invalid order book, skip quoting: %v", s.Symbol, err)
log.WithError(err).Errorf("%s invalid copied order book, skip quoting: %v", s.Symbol, err)
return
}
@ -281,12 +286,6 @@ func (s *Strategy) updateQuote(ctx context.Context, orderExecutionRouter bbgo.Or
return
}
bestBid, hasBid := sourceBook.BestBid()
bestAsk, hasAsk := sourceBook.BestAsk()
if !hasBid || !hasAsk {
return
}
bestBidPrice := bestBid.Price
bestAskPrice := bestAsk.Price
log.Infof("%s book ticker: best ask / best bid = %f / %f", s.Symbol, bestAskPrice.Float64(), bestBidPrice.Float64())