24 if (!bbo.has_bid || !bbo.has_ask) {
25 return std::numeric_limits<double>::quiet_NaN();
27 return bbo.ask_price.to_double() - bbo.bid_price.to_double();
36 if (!bbo.has_bid || !bbo.has_ask) {
37 return std::numeric_limits<double>::quiet_NaN();
39 return (bbo.bid_price.to_double() + bbo.ask_price.to_double()) / 2.0;
52 const double bid =
static_cast<double>(bbo.bid_shares);
53 const double ask =
static_cast<double>(bbo.ask_shares);
54 const double total = bid + ask;
56 return std::numeric_limits<double>::quiet_NaN();
58 return (bid - ask) / total;
70 std::uint64_t total = 0;
71 for (
const auto& level : book.depth(
side, levels)) {
72 total += level.shares;
89 const double prev_bid_price = previous.bid_price.to_double();
90 const double curr_bid_price = current.bid_price.to_double();
91 const double prev_ask_price = previous.ask_price.to_double();
92 const double curr_ask_price = current.ask_price.to_double();
93 const double prev_bid_size =
static_cast<double>(previous.bid_shares);
94 const double curr_bid_size =
static_cast<double>(current.bid_shares);
95 const double prev_ask_size =
static_cast<double>(previous.ask_shares);
96 const double curr_ask_size =
static_cast<double>(current.ask_shares);
98 double bid_flow = 0.0;
99 if (curr_bid_price > prev_bid_price) {
100 bid_flow = curr_bid_size;
101 }
else if (curr_bid_price == prev_bid_price) {
102 bid_flow = curr_bid_size - prev_bid_size;
104 bid_flow = -prev_bid_size;
107 double ask_flow = 0.0;
108 if (curr_ask_price > prev_ask_price) {
109 ask_flow = prev_ask_size;
110 }
else if (curr_ask_price == prev_ask_price) {
111 ask_flow = curr_ask_size - prev_ask_size;
113 ask_flow = -curr_ask_size;
116 return bid_flow - ask_flow;
A single-symbol, order-level (L3) limit order book with allocation-light internals.
Single-symbol, order-level (L3) limit order book with allocation-light internals.
auto queue_imbalance(const book::Bbo &bbo) -> double
Top-of-book queue imbalance in [-1, 1].
auto spread(const book::Bbo &bbo) -> double
The bid-ask spread in price units, or NaN if either side is empty.
auto depth_at_level(const book::L3Book &book, book::Side side, std::size_t levels) -> std::uint64_t
Total displayed shares within the best levels price levels of a side.
auto order_flow_imbalance(const book::Bbo &previous, const book::Bbo ¤t) -> double
The order-flow imbalance between two consecutive BBO observations.
auto mid_price(const book::Bbo &bbo) -> double
The mid price ((bid + ask) / 2), or NaN if either side is empty.
Side
Which side of the book an order rests on.
Best bid and offer of a single book.