38 BarInterval::ONE_MINUTE,
40 BarInterval::ONE_WEEK,
41 BarInterval::ONE_MONTH,
42 BarInterval::ONE_YEAR,
56 case BarInterval::ONE_MINUTE:
58 case BarInterval::ONE_DAY:
60 case BarInterval::ONE_WEEK:
62 case BarInterval::ONE_MONTH:
64 case BarInterval::ONE_YEAR:
86 case BarInterval::ONE_MINUTE:
87 return std::chrono::seconds(60);
89 return std::chrono::seconds(300);
91 return std::chrono::seconds(900);
93 return std::chrono::seconds(1800);
95 return std::chrono::seconds(3600);
96 case BarInterval::ONE_DAY:
97 case BarInterval::ONE_WEEK:
98 case BarInterval::ONE_MONTH:
99 case BarInterval::ONE_YEAR:
107 "all_bar_intervals must list every BarInterval"
183 for (std::size_t index = 1; index <
bars_.size(); ++index) {
184 if (!(
bars_[index - 1].timestamp_ <
bars_[index].timestamp_)) {
225 return bids_.empty() ? std::nullopt : std::optional<DepthLevel>(
bids_.front());
233 return asks_.empty() ? std::nullopt : std::optional<DepthLevel>(
asks_.front());
240 std::optional<Decimal64>
spread()
const {
256 std::optional<Decimal64>
mid()
const {
262 const auto sum =
decimal_add(bid->price_, ask->price_);
278 std::sort(book.
asks_.begin(), book.
asks_.end(), by_price);
279 std::sort(book.
bids_.begin(), book.
bids_.end(), [&by_price](
const auto& l,
const auto& r) {
280 return by_price(r, l);
332 std::optional<std::chrono::system_clock::time_point>
before_;
A three-letter currency code, such as KRW or USD (ISO 4217 style).
An exact signed decimal: an int64 coefficient times 10^-scale.
The library: broker-neutral types (core), and the modules below.
BarStamp
Which edge of its period a bar's timestamp marks.
@ CLOSE
The timestamp is the instant the period ended.
constexpr std::optional< std::chrono::seconds > bar_interval_length(BarInterval interval) noexcept
Returns an interval's fixed length, for an intraday interval.
constexpr bool lists_every_value(const std::array< Enum, N > &values, IsEnumerator is_enumerator) noexcept
Tests whether a list holds every value of an enum exactly once, in any order.
std::optional< Decimal64 > decimal_add(const Decimal64 &lhs, const Decimal64 &rhs)
Adds two decimals exactly.
std::optional< Decimal64 > decimal_halve(const Decimal64 &value)
Halves a decimal exactly, adding a decimal place when needed.
constexpr std::string_view bar_interval_name(BarInterval interval) noexcept
Returns a short name for an interval, such as "1m", "5m", "1h" or "1d".
constexpr std::array< BarInterval, 9 > all_bar_intervals
Every BarInterval, in declaration order.
std::optional< Decimal64 > decimal_subtract(const Decimal64 &lhs, const Decimal64 &rhs)
Subtracts two decimals exactly.
bool decimal_less(const Decimal64 &lhs, const Decimal64 &rhs)
Compares two decimals numerically, whatever their scales.
BarInterval
The period one bar covers.
@ FIVE_MINUTES
Five minutes.
@ THIRTY_MINUTES
Thirty minutes.
@ FIFTEEN_MINUTES
Fifteen minutes.
void order_depth(DepthSnapshot &book)
Sorts a book's levels best first: bids descending, asks ascending.
InstrumentId instrument_
The instrument.
BarInterval interval_
The period of each bar; an interval the broker does not publish is refused.
int count_
How many bars to return in total, across pages.
std::optional< std::chrono::system_clock::time_point > before_
The newest bar time to return, inclusive; pass the oldest timestamp seen to page backwards.
bool adjusted_
Whether to ask for prices adjusted for corporate actions.
The bars of one instrument and interval, oldest first.
bool ascending() const
Tests whether the bars are strictly ascending in time.
std::optional< std::string > next_cursor_
A cursor to continue from, if the broker has more.
std::chrono::system_clock::time_point received_at_
When the series was received, on this machine's clock.
BarInterval interval_
The period each bar covers.
Currency currency_
The currency of the prices.
bool adjusted_
Whether the prices are adjusted for corporate actions.
BarStamp stamp_
Which edge of its period each bar's timestamp marks.
InstrumentId instrument_
The instrument.
std::vector< Bar > bars_
The bars, oldest first.
One bar: the prices and volume of one period, as exact decimals.
Decimal64 volume_
The shares traded.
Decimal64 high_
The highest trade price.
Decimal64 close_
The last trade price.
std::chrono::system_clock::time_point timestamp_
The instant marking the period; BarSeries::stamp_ says which edge.
std::optional< Decimal64 > open_
The first trade's price; empty if nothing traded in the period (never zero or the previous close).
std::optional< Decimal64 > traded_value_
The value traded, if the broker publishes it.
Decimal64 low_
The lowest trade price.
One price level of an order book.
Decimal64 quantity_
The quantity resting at it.
Decimal64 price_
The price.
An instrument's order book: resting bids and offers.
std::optional< DepthLevel > best_ask() const
Returns the best offer.
Currency currency_
The currency of the prices.
std::optional< Decimal64 > spread() const
Returns the spread, best offer minus best bid, exactly.
std::chrono::system_clock::time_point received_at_
When the book was received, on this machine's clock.
InstrumentId instrument_
The instrument.
std::vector< DepthLevel > bids_
The bids, descending by price.
std::vector< DepthLevel > asks_
The offers, ascending by price.
std::optional< Decimal64 > mid() const
Returns the midpoint of the best bid and offer, exactly (one more decimal place if needed).
std::optional< std::chrono::system_clock::time_point > exchange_time_
When the exchange says the book was true, if the broker gave a time.
std::optional< DepthLevel > best_bid() const
Returns the best bid.
Identifies an instrument: its country, venue and symbol.
The highest and lowest price an instrument may trade at today.
std::optional< Decimal64 > lower_
The lowest price allowed today; empty means the same as for upper_.
std::optional< std::chrono::system_clock::time_point > exchange_time_
When the exchange set the bounds, if the broker gave a time.
std::optional< Decimal64 > upper_
The highest price allowed today.
Currency currency_
The currency of the bounds.
One executed trade, as the broker reported it.
Currency currency_
The currency of price_.
Decimal64 price_
The trade price.
Decimal64 quantity_
The quantity traded.
std::optional< std::chrono::system_clock::time_point > exchange_time_
When the exchange says it executed, if the broker gave a time.