46 [[nodiscard]]
auto bucket(
const Trade& trade, std::uint64_t, std::uint64_t)
const noexcept
60 [[nodiscard]]
auto bucket(
const Trade&, std::uint64_t, std::uint64_t tick_index)
const noexcept
74 [[nodiscard]]
auto bucket(
const Trade&, std::uint64_t cumulative_volume, std::uint64_t)
75 const noexcept -> std::uint64_t {
86template <
typename Clock>
95 : m_clock {std::move(clock)}, m_callback {std::move(callback)} {}
101 const std::uint64_t bucket = m_clock.bucket(trade, m_cumulative_volume, m_tick_index);
102 if (m_has_bar && bucket != m_bar.
bucket) {
109 m_bar.
open = trade.price;
110 m_bar.
high = trade.price;
111 m_bar.
low = trade.price;
114 m_bar.
high = std::max(m_bar.
high, trade.price);
115 m_bar.
low = std::min(m_bar.
low, trade.price);
116 m_bar.
close = trade.price;
118 m_bar.
volume += trade.shares;
121 m_cumulative_volume += trade.shares;
134 auto emit() ->
void {
144 bool m_has_bar {
false};
145 std::uint64_t m_cumulative_volume {0};
146 std::uint64_t m_tick_index {0};
Builds OHLCV bars from a trade stream under a configurable clock.
auto add(const Trade &trade) -> void
Adds one trade, emitting the previous bar when the bucket changes.
auto flush() -> void
Emits the current partial bar, if any, and clears it.
BarBuilder(Clock clock, BarCallback callback)
Constructs a builder with the given clock policy and completion callback.
std::function< void(const Bar &)> BarCallback
Callback invoked with each completed bar.
Strongly typed, fixed-point price representation for ITCH price fields.
A single execution extracted from the feed (the "trade tape").
One OHLCV bar aggregated from the trade tape.
StandardPrice close
Last trade price.
std::uint64_t trade_count
Number of trades in the bar.
StandardPrice open
First trade price.
std::uint64_t start_timestamp
Timestamp of the first trade in the bar.
std::uint64_t bucket
Clock bucket id this bar covers.
StandardPrice low
Lowest trade price.
std::uint64_t end_timestamp
Timestamp of the last trade in the bar.
std::uint64_t volume
Total shares traded in the bar.
StandardPrice high
Highest trade price.
A clock that buckets a fixed number of trades into each bar.
auto bucket(const Trade &, std::uint64_t, std::uint64_t tick_index) const noexcept -> std::uint64_t
Computes the bucket id for the current trade from its tick position.
std::uint64_t ticks_per_bar
A clock that buckets trades by wall-clock time (nanoseconds).
std::uint64_t interval_ns
auto bucket(const Trade &trade, std::uint64_t, std::uint64_t) const noexcept -> std::uint64_t
Computes the bucket id for trade from its wall-clock timestamp.
A clock that buckets a fixed amount of traded volume into each bar.
std::uint64_t volume_per_bar
auto bucket(const Trade &, std::uint64_t cumulative_volume, std::uint64_t) const noexcept -> std::uint64_t
Computes the bucket id for the current trade from cumulative volume.
A normalized trade record and callback type for consuming the ITCH trade tape.