Skip to content

Commit

Permalink
Merge pull request #11703 from vegaprotocol/fix-missing-candles
Browse files Browse the repository at this point in the history
fix: include most recent candles in the API response
  • Loading branch information
jeremyletang authored Sep 24, 2024
2 parents 7887a8a + 285b0d5 commit d7e4fde
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions datanode/candlesv2/candle_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,16 @@ func (s *CandleUpdates) getCandleUpdates(ctx context.Context, lastCandle *entiti
return nil, fmt.Errorf("getting candle updates:%w", err)
}

// allocate slice rather than doubling cap as we go.
updates = make([]entities.Candle, 0, len(candles))
for _, candle := range candles {
if candle.LastUpdateInPeriod.After(lastCandle.LastUpdateInPeriod) || candle.PeriodStart.After(lastCandle.PeriodStart) {
// not before so either newer, or the same (last) candle should be returned.
if !candle.LastUpdateInPeriod.Before(lastCandle.LastUpdateInPeriod) || !candle.PeriodStart.Before(lastCandle.PeriodStart) {
updates = append(updates, candle)
}
}
} else {
last := int32(1)
pagination, err := entities.NewCursorPagination(nil, nil, &last, nil, false)
if err != nil {
return nil, err
}
updates, _, err = s.candleSource.GetCandleDataForTimeSpan(ctx, s.candleID, nil, &now, pagination)
updates, _, err = s.candleSource.GetCandleDataForTimeSpan(ctx, s.candleID, nil, &now, entities.CursorPagination{})

if err != nil {
return nil, fmt.Errorf("getting candle updates:%w", err)
Expand Down

0 comments on commit d7e4fde

Please sign in to comment.