eighth version

This commit is contained in:
2026-06-08 11:55:36 +00:00
parent ebea17b411
commit e8b7d8e27c
15 changed files with 431 additions and 42 deletions
+11 -3
View File
@@ -86,16 +86,24 @@ func (l Loader) LatestQuote(ctx context.Context, instrumentUID string, depth int
if err != nil {
return domain.OrderBook{}, err
}
if book.ReceivedAt.IsZero() {
return domain.OrderBook{}, fmt.Errorf("quote received timestamp is missing")
quoteTs := quoteTimestamp(book)
if quoteTs.IsZero() {
return domain.OrderBook{}, fmt.Errorf("quote timestamp is missing")
}
age := l.nowUTC().Sub(book.ReceivedAt)
age := l.nowUTC().Sub(quoteTs)
if maxAge > 0 && age > maxAge {
return domain.OrderBook{}, fmt.Errorf("quote age %s exceeds %s", age, maxAge)
}
return book, nil
}
func quoteTimestamp(book domain.OrderBook) time.Time {
if !book.Time.IsZero() {
return book.Time.UTC()
}
return book.ReceivedAt.UTC()
}
func (l Loader) nowUTC() time.Time {
if l.clock == nil {
return time.Now().UTC()