Skip to content

Commit b213671

Browse files
authored
Fix update_bar aggregation function (#2430)
1 parent 3f0277b commit b213671

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

crates/data/src/aggregation.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ impl BarBuilder {
233233
self.close = self.last_close;
234234
}
235235

236+
if let (Some(close), Some(low)) = (self.close, self.low) {
237+
if close < low {
238+
self.low = Some(close);
239+
}
240+
}
241+
242+
if let (Some(close), Some(high)) = (self.close, self.high) {
243+
if close > high {
244+
self.high = Some(close);
245+
}
246+
}
247+
236248
// SAFETY: The open was checked, so we can assume all prices are Some
237249
let bar = Bar::new(
238250
self.bar_type,

nautilus_trader/data/aggregation.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ cdef class BarBuilder:
245245
self._low = self._last_close
246246
self._close = self._last_close
247247

248+
249+
self._low._mem.raw = min(self._close._mem.raw, self._low._mem.raw)
250+
self._high._mem.raw = max(self._close._mem.raw, self._high._mem.raw)
251+
248252
cdef Bar bar = Bar(
249253
bar_type=self._bar_type,
250254
open=self._open,

0 commit comments

Comments
 (0)