algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algotradelib/core>
4
5#include <array>
6#include <chrono>
7#include <cstddef>
8#include <cstdint>
9#include <optional>
10#include <ratio>
11#include <string>
12#include <utility>
13#include <vector>
14
15namespace algotradelib {
16namespace strategy {
17
25
33enum class MarketPhase {
38 UNKNOWN,
40 CLOSED,
46 OPEN,
52};
53
62
68inline constexpr std::string_view market_phase_name(MarketPhase phase) noexcept {
69 switch (phase) {
71 return "unknown";
73 return "closed";
75 return "pre_open";
77 return "open";
79 return "post_close";
80 }
81 return "";
82}
83
90inline constexpr bool market_phase_session_ended(MarketPhase phase) noexcept {
91 switch (phase) {
94 return true;
98 return false;
99 }
100 return false;
101}
102
103static_assert(
106 [](MarketPhase phase) {
107 return !market_phase_name(phase).empty();
108 }
109 ),
110 "all_market_phases must list every MarketPhase"
111);
112
124 std::chrono::minutes open_{std::chrono::hours(9)};
126 std::chrono::minutes close_{std::chrono::hours(15) + std::chrono::minutes(30)};
128 std::chrono::minutes utc_offset_{std::chrono::hours(9)};
130 std::string source_{"KRX regular session, 09:00-15:30 KST (library default)"};
131
137 return SessionWindow{};
138 }
139
149 MarketPhase phase(std::chrono::system_clock::time_point now, std::optional<bool> trading_day) const {
150 if (!trading_day) {
152 }
153 if (!*trading_day) {
154 return MarketPhase::CLOSED;
155 }
156 const auto local = now + utc_offset_;
157 const auto since_midnight = std::chrono::duration_cast<std::chrono::minutes>(local - local_midnight(now));
158 if (since_midnight < open_) {
160 }
161 if (close_ <= since_midnight) {
163 }
164 return MarketPhase::OPEN;
165 }
166
176 Date local_date(std::chrono::system_clock::time_point now) const {
177 using Days = std::chrono::duration<std::int64_t, std::ratio<86400>>;
178 return date_from_epoch_days(std::chrono::duration_cast<Days>(local_midnight(now).time_since_epoch()).count());
179 }
180
187 std::chrono::system_clock::time_point opens_at(std::chrono::system_clock::time_point now) const {
188 return local_midnight(now) - utc_offset_ + open_;
189 }
190
197 std::chrono::system_clock::time_point closes_at(std::chrono::system_clock::time_point now) const {
198 return local_midnight(now) - utc_offset_ + close_;
199 }
200
201private:
202 // The market's local midnight before `now`, as a UTC-shifted instant. floor rounds toward
203 // negative infinity, so instants before the epoch work too. phase() and local_date() share it so
204 // they always agree on the day.
205 std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> local_midnight(
206 std::chrono::system_clock::time_point now
207 ) const {
208 using Days = std::chrono::duration<std::int64_t, std::ratio<86400>>;
209 return std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::floor<Days>(now + utc_offset_));
210 }
211};
212
238inline MarketPhase stated_session_phase(const TradingCalendar& calendar, std::chrono::system_clock::time_point now) {
239 const auto has_hours = [](const TradingDay& day) {
240 return day.open_ && day.regular_ && day.regular_->opens_at_ < day.regular_->closes_at_;
241 };
242 const auto span_of = [](const TradingDay& day) {
243 const auto& regular = *day.regular_;
244 if (
245 day.extended_ && day.extended_->opens_at_ <= regular.opens_at_ && regular.closes_at_ <= day.extended_->closes_at_
246 ) {
247 return *day.extended_;
248 }
249 return regular;
250 };
251 const auto& days = calendar.days_;
252 for (std::size_t i = 0; i < days.size(); ++i) {
253 if (!has_hours(days[i])) {
254 continue;
255 }
256 const auto first = span_of(days[i]);
257 for (std::size_t j = i + 1; j < days.size(); ++j) {
258 if (!has_hours(days[j])) {
259 continue;
260 }
261 const auto second = span_of(days[j]);
262 if (first.opens_at_ < second.closes_at_ && second.opens_at_ < first.closes_at_) {
264 }
265 }
266 }
267 const TradingDay* previous = nullptr;
268 const TradingDay* next = nullptr;
269 for (const auto& day : days) {
270 if (!has_hours(day)) {
271 continue;
272 }
273 const auto& regular = *day.regular_;
274 const auto span = span_of(day);
275 if (regular.opens_at_ <= now && now < regular.closes_at_) {
276 return MarketPhase::OPEN;
277 }
278 if (span.opens_at_ <= now && now < span.closes_at_) {
279 return now < regular.opens_at_ ? MarketPhase::PRE_OPEN : MarketPhase::POST_CLOSE;
280 }
281 if (span.closes_at_ <= now && (previous == nullptr || span_of(*previous).closes_at_ < span.closes_at_)) {
282 previous = &day;
283 }
284 if (now < span.opens_at_ && (next == nullptr || span.opens_at_ < span_of(*next).opens_at_)) {
285 next = &day;
286 }
287 }
288 if (previous == nullptr || next == nullptr || !(previous->date_ < next->date_)) {
290 }
291 bool closed_between = false;
292 for (const auto& day : days) {
293 if (previous->date_ < day.date_ && day.date_ < next->date_) {
294 if (day.open_) {
296 }
297 closed_between = true;
298 }
299 }
300 if (calendar.unreadable_days_ > 0) {
302 }
303 return closed_between ? MarketPhase::CLOSED : MarketPhase::POST_CLOSE;
304}
305
313struct BarEvent {
317 BarInterval interval_{BarInterval::ONE_DAY};
329 std::chrono::system_clock::time_point period_end_{};
330};
331
343inline std::chrono::system_clock::time_point bar_period_end(const Bar& bar, BarInterval interval, BarStamp stamp) {
344 if (stamp == BarStamp::CLOSE) {
345 return bar.timestamp_;
346 }
347 switch (interval) {
348 case BarInterval::ONE_MINUTE:
349 return bar.timestamp_ + std::chrono::minutes(1);
351 return bar.timestamp_ + std::chrono::minutes(5);
353 return bar.timestamp_ + std::chrono::minutes(15);
355 return bar.timestamp_ + std::chrono::minutes(30);
357 return bar.timestamp_ + std::chrono::hours(1);
358 case BarInterval::ONE_DAY:
359 return bar.timestamp_ + std::chrono::hours(24);
360 case BarInterval::ONE_WEEK:
361 return bar.timestamp_ + std::chrono::hours(24 * 7);
362 case BarInterval::ONE_MONTH:
363 // Nominal: a month has no fixed length. Documented on the function.
364 return bar.timestamp_ + std::chrono::hours(24 * 31);
365 case BarInterval::ONE_YEAR:
366 return bar.timestamp_ + std::chrono::hours(24 * 366);
367 }
368 return bar.timestamp_;
369}
370
380inline BarEvent make_bar_event(InstrumentId instrument, BarInterval interval, BarStamp stamp, Bar bar) {
381 BarEvent event;
382 event.instrument_ = std::move(instrument);
383 event.interval_ = interval;
384 event.stamp_ = stamp;
385 event.period_end_ = bar_period_end(bar, interval, stamp);
386 event.bar_ = std::move(bar);
387 return event;
388}
389
401inline std::optional<std::chrono::system_clock::time_point> bar_period_start(
402 const BarEvent& event, const SessionWindow& session
403) {
404 if (event.stamp_ == BarStamp::OPEN) {
405 return event.bar_.timestamp_;
406 }
407 if (const auto duration = bar_interval_length(event.interval_)) {
408 return event.period_end_ - *duration;
409 }
410 if (event.interval_ == BarInterval::ONE_DAY) {
411 return session.opens_at(event.period_end_);
412 }
413 return std::nullopt;
414}
415
422 bool opens_{false};
427 bool closes_{false};
429 bool point_{false};
430};
431
451public:
458 SessionEdge next(const BarEvent& event, const SessionWindow& session) {
459 SessionEdge edge;
460 const auto end = event.period_end_;
461 const auto start = bar_period_start(event, session).value_or(end);
462 const auto date = session.local_date(start);
463 const auto open = session.opens_at(start);
464 const auto close = session.closes_at(start);
465 edge.point_ = start == end;
466 const bool reaches = start < close && (open < end || (edge.point_ && end == open));
467 const bool holds_close = start <= close && close <= end;
468 if (!reaches && !holds_close) {
469 // Before the open or after the close: pre-market or after-hours data, which still enters a strategy's series.
470 ++outside_count_;
471 }
472 if (reaches && !(opened_ && *opened_ == date)) {
473 edge.opens_ = true;
474 opened_ = date;
475 ++opened_count_;
476 }
477 if (holds_close && !(closed_ && *closed_ == date)) {
478 edge.closes_ = true;
479 closed_ = date;
480 ++closed_count_;
481 }
482 return edge;
483 }
484
489 std::size_t opened() const noexcept {
490 return opened_count_;
491 }
492
497 std::size_t closed() const noexcept {
498 return closed_count_;
499 }
500
505 std::size_t outside() const noexcept {
506 return outside_count_;
507 }
508
509private:
510 std::optional<Date> opened_;
511 std::optional<Date> closed_;
512 std::size_t opened_count_{0};
513 std::size_t closed_count_{0};
514 std::size_t outside_count_{0};
515};
516
517struct BarSlice;
518
520namespace slice_detail {
521
522// Where each bar of a delivered slice is, by instrument, and the bars it was built over (their storage and
523// count). Only the period bucket fills it, on the slice it delivers; **a copy or a move of a slice starts with
524// none**, so the only slice that can use it is the one the library built and hands on only as a const reference
525// (to a handler, and from `live::SessionSource` to a runner), whose bars nobody changes. A copy, a move, or a slice
526// built by its holder has no table and is scanned.
527class SliceIndex {
528public:
529 SliceIndex() = default;
530 SliceIndex(const SliceIndex&) noexcept {}
531 SliceIndex(SliceIndex&&) noexcept {}
532 SliceIndex& operator=(const SliceIndex&) noexcept {
533 forget();
534 return *this;
535 }
536 SliceIndex& operator=(SliceIndex&&) noexcept {
537 forget();
538 return *this;
539 }
540
541private:
542 friend struct strategy::BarSlice;
543 friend class Bucket;
544
545 void forget() noexcept {
546 table_.reset();
547 built_over_ = nullptr;
548 count_ = 0;
549 }
550
551 id_detail::PositionTable table_;
552 const void* built_over_{nullptr};
553 std::size_t count_{0};
554};
555
556} // namespace slice_detail
558
569struct BarSlice {
571 std::chrono::system_clock::time_point period_end_{};
573 BarInterval interval_{BarInterval::ONE_DAY};
575 std::vector<BarEvent> bars_;
576
586 const BarEvent* find(const InstrumentId& id) const noexcept {
587 if (!index_.table_.empty() && index_.built_over_ == bars_.data() && index_.count_ == bars_.size()) {
588 const auto at = index_.table_.find(id, Ids{&bars_});
589 return at ? &bars_[*at] : nullptr;
590 }
591 for (const auto& event : bars_) {
592 if (event.instrument_ == id) {
593 return &event;
594 }
595 }
596 return nullptr;
597 }
598
600 // The bucket's table of where each bar is, on the slice it delivers only (`slice_detail::SliceIndex`). The
601 // storage and count are checked too, which catches bars reallocated or resized since; it cannot catch bars
602 // changed in place, which is why only a slice handed on as const carries the table.
603 slice_detail::SliceIndex index_;
604
605 // The instrument at a position of `bars_`, for the table.
606 struct Ids {
607 const std::vector<BarEvent>* bars_;
608 const InstrumentId& operator()(std::size_t at) const noexcept {
609 return (*bars_)[at].instrument_;
610 }
611 };
613};
614
616namespace slice_detail {
617
622class Bucket {
623 // The id at a position of a slice, for its table.
624 struct SliceIds {
625 const BarSlice* slice_;
626 const InstrumentId& operator()(std::size_t at) const noexcept {
627 return slice_->bars_[at].instrument_;
628 }
629 };
630 static SliceIds ids_of(const BarSlice& slice) noexcept {
631 return SliceIds{&slice};
632 }
633
634public:
635 Bucket() = default;
636 Bucket(const Bucket&) = default;
637 Bucket(Bucket&&) = default;
638 Bucket& operator=(Bucket&&) = default;
639
641 Bucket& operator=(const Bucket& other) {
642 if (this != &other) {
643 Bucket copy(other);
644 *this = std::move(copy);
645 }
646 return *this;
647 }
648
650 bool empty() const noexcept {
651 return slices_.empty();
652 }
653
655 std::chrono::system_clock::time_point period_end() const noexcept {
656 return period_end_;
657 }
658
660 bool holds(const BarEvent& event) const noexcept {
661 for (const auto& slice : slices_) {
662 if (slice.interval_ == event.interval_) {
663 if (slice.bars_.size() > id_detail::scan_limit) {
664 if (const auto* entry = wide(event.interval_)) {
665 return entry->table_.find(event.instrument_, ids_of(slice)).has_value();
666 }
667 }
668 return slice.find(event.instrument_) != nullptr;
669 }
670 }
671 return false;
672 }
673
680 void add_checked(const BarEvent& event) {
681 if (slices_.empty()) {
682 period_end_ = event.period_end_;
683 }
684 for (auto& slice : slices_) {
685 if (slice.interval_ == event.interval_) {
686 slice.bars_.push_back(event);
687 return;
688 }
689 }
690 BarSlice slice;
691 slice.period_end_ = event.period_end_;
692 slice.interval_ = event.interval_;
693 slice.bars_.push_back(event);
694 slices_.push_back(std::move(slice));
695 }
696
698 void add(const BarEvent& event) {
699 if (slices_.empty()) {
700 period_end_ = event.period_end_;
701 }
702 for (auto& slice : slices_) {
703 if (slice.interval_ == event.interval_) {
704 slice.bars_.push_back(event);
705 // If the table cannot grow, the bar comes out again, so the two never disagree.
706 try {
707 if (slice.bars_.size() == id_detail::scan_limit + 1) {
708 widen(slice);
709 } else if (slice.bars_.size() > id_detail::scan_limit) {
710 if (auto* entry = wide(slice.interval_)) {
711 entry->table_.insert(event.instrument_, slice.bars_.size() - 1, ids_of(slice));
712 entry->count_ = slice.bars_.size();
713 }
714 }
715 } catch (...) {
716 slice.bars_.pop_back();
717 throw;
718 }
719 return;
720 }
721 }
722 BarSlice slice;
723 slice.period_end_ = event.period_end_;
724 slice.interval_ = event.interval_;
725 slice.bars_.push_back(event);
726 slices_.push_back(std::move(slice));
727 }
728
730 BarSlice take_first() {
731 // Moved out first, since a move does not carry the table (`SliceIndex`); the bars keep their storage.
732 BarSlice slice = std::move(slices_.front());
733 hand_index_to(slice);
734 slices_.erase(slices_.begin());
735 return slice;
736 }
737
739 std::vector<BarSlice> take() {
740 for (auto& slice : slices_) {
741 hand_index_to(slice);
742 }
743 std::vector<BarSlice> slices = std::move(slices_);
744 slices_.clear();
745 return slices;
746 }
747
749 void clear() noexcept {
750 slices_.clear();
751 }
752
753private:
754 // An interval's table, which describes that interval's slice only while the slice holds more than
755 // `id_detail::scan_limit` bars: `widen` refills it when a slice passes that size and `add` extends it after,
756 // and nothing reads it while the slice is narrower. It outlives the slice, so the next wide slice of the
757 // interval reuses its storage; a bucket that never holds a wide slice has none.
758 struct Wide {
759 BarInterval interval_;
760 id_detail::PositionTable table_;
761 // How many of the slice's bars the table holds: all of them after `add` or `widen`, fewer after
762 // `add_checked`.
763 std::size_t count_{0};
764 };
765
766 const Wide* wide(BarInterval interval) const noexcept {
767 for (const auto& entry : wide_) {
768 if (entry.interval_ == interval) {
769 return &entry;
770 }
771 }
772 return nullptr;
773 }
774
775 Wide* wide(BarInterval interval) noexcept {
776 for (auto& entry : wide_) {
777 if (entry.interval_ == interval) {
778 return &entry;
779 }
780 }
781 return nullptr;
782 }
783
784 // Moves the table of a wide slice into it, with the bars it describes, so `BarSlice::find` can use it after
785 // the slice is delivered. Moving a slice keeps its bars' storage, so the table stays valid for it; the bucket's
786 // own table is rebuilt (`widen`) when a later period's slice grows wide again.
787 void hand_index_to(BarSlice& slice) noexcept {
788 if (slice.bars_.size() <= id_detail::scan_limit) {
789 return;
790 }
791 // Built now if `add_checked` left it unbuilt (or behind); a failed allocation only leaves the slice scanned.
792 const auto* built = wide(slice.interval_);
793 if (built == nullptr || built->count_ != slice.bars_.size() || built->table_.empty()) {
794 try {
795 widen(slice);
796 } catch (...) {
797 return;
798 }
799 }
800 if (auto* entry = wide(slice.interval_)) {
801 slice.index_.table_ = std::move(entry->table_);
802 entry->table_.reset();
803 entry->count_ = 0;
804 slice.index_.built_over_ = slice.bars_.data();
805 slice.index_.count_ = slice.bars_.size();
806 }
807 }
808
809 // Refills the interval's table from its slice, which has just passed `id_detail::scan_limit` bars (or is being
810 // delivered). On a failure the table is left empty, and the caller takes the bar back out or scans, so nothing
811 // reads it.
812 void widen(const BarSlice& slice) {
813 Wide* entry = wide(slice.interval_);
814 if (entry == nullptr) {
815 wide_.push_back(Wide{slice.interval_, {}});
816 entry = &wide_.back();
817 }
818 entry->table_.reset();
819 entry->count_ = 0;
820 try {
821 for (std::size_t at = 0; at < slice.bars_.size(); ++at) {
822 entry->table_.insert(slice.bars_[at].instrument_, at, ids_of(slice));
823 }
824 } catch (...) {
825 entry->table_.reset();
826 throw;
827 }
828 entry->count_ = slice.bars_.size();
829 }
830
831 std::chrono::system_clock::time_point period_end_{};
832 std::vector<BarSlice> slices_;
833 // At most one entry per interval that has had a wide slice.
834 std::vector<Wide> wide_;
835};
836
837} // namespace slice_detail
839
845
855template <typename T>
856struct DataEvent {
864 std::chrono::system_clock::time_point known_at_{};
867};
868
886struct Fill {
888 std::string order_id_;
892 OrderSide side_{OrderSide::BUY};
898 std::string tag_;
900 std::chrono::system_clock::time_point at_{};
901};
902
903} // namespace strategy
904} // namespace algotradelib
An exact signed decimal: an int64 coefficient times 10^-scale.
Definition types.hpp:443
Follows a strategy's bars and says which bar opens its session and which closes it,...
Definition event.hpp:450
SessionEdge next(const BarEvent &event, const SessionWindow &session)
Decides whether the next bar opens or closes its session.
Definition event.hpp:458
std::size_t opened() const noexcept
Returns how many sessions a bar has opened so far.
Definition event.hpp:489
std::size_t outside() const noexcept
Returns how many bars lay wholly outside their session (before its open or after its close).
Definition event.hpp:505
std::size_t closed() const noexcept
Returns how many sessions a bar has closed so far.
Definition event.hpp:497
What a strategy sees and emits: events, intents, the portfolio, reconciliation and risk limits.
Definition concept.hpp:16
BarEvent make_bar_event(InstrumentId instrument, BarInterval interval, BarStamp stamp, Bar bar)
Makes a bar event, computing its period_end_ with bar_period_end.
Definition event.hpp:380
MarketPhase
Where the clock stands relative to the trading session.
Definition event.hpp:33
@ CLOSED
A date the market does not trade.
Definition event.hpp:40
@ PRE_OPEN
A trading day, before the session opens; under filled session hours, the day's earlier stated session...
Definition event.hpp:44
@ UNKNOWN
Nothing is known about this instant: the calendar does not cover its date, or the filled session hour...
Definition event.hpp:38
@ POST_CLOSE
A trading day, after the session closed; under filled session hours, until the next day's first sessi...
Definition event.hpp:51
@ OPEN
Inside the session.
Definition event.hpp:46
constexpr std::array< MarketPhase, 5 > all_market_phases
Every MarketPhase, in declaration order.
Definition event.hpp:55
constexpr std::string_view market_phase_name(MarketPhase phase) noexcept
Returns a lowercase name for a phase, such as "pre_open", for logs and display.
Definition event.hpp:68
std::chrono::system_clock::time_point bar_period_end(const Bar &bar, BarInterval interval, BarStamp stamp)
Computes the instant a bar's period ended.
Definition event.hpp:343
constexpr bool market_phase_session_ended(MarketPhase phase) noexcept
Tests whether a phase means the day's session is over (or never opened), so a day order no longer wor...
Definition event.hpp:90
std::optional< std::chrono::system_clock::time_point > bar_period_start(const BarEvent &event, const SessionWindow &session)
Returns when a bar's period began, where the bar says so.
Definition event.hpp:401
MarketPhase stated_session_phase(const TradingCalendar &calendar, std::chrono::system_clock::time_point now)
Returns the market phase at an instant from the session hours filled in a calendar.
Definition event.hpp:238
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.
@ OPEN
The timestamp is the first instant of the period.
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.
Date date_from_epoch_days(std::int64_t days)
Converts a day count since 1970-01-01 to a Gregorian date.
Definition types.hpp:1456
BarInterval
The period one bar covers.
@ FIVE_MINUTES
Five minutes.
@ THIRTY_MINUTES
Thirty minutes.
@ FIFTEEN_MINUTES
Fifteen minutes.
OrderSide
The side of an order: its economic direction, buy or sell.
Definition types.hpp:1974
One bar: the prices and volume of one period, as exact decimals.
A calendar date with no time of day or time zone.
Definition types.hpp:1412
Identifies an instrument: its country, venue and symbol.
Definition types.hpp:85
A quote: the last traded price of an instrument at a point in time.
Definition types.hpp:1143
The trading days a broker reported for one market, ascending by date.
Definition calendar.hpp:72
std::size_t unreadable_days_
How many rows from the broker had a date that could not be read.
Definition calendar.hpp:88
std::vector< TradingDay > days_
The days the broker reported, ascending. A date outside them is uncovered, not closed.
Definition calendar.hpp:76
One calendar date and whether the market opens on it.
Definition calendar.hpp:31
Date date_
The market's local calendar date, as the broker reports it.
Definition calendar.hpp:38
One bar, delivered to on_bar.
Definition event.hpp:313
BarStamp stamp_
Whether bar_.timestamp_ marks the period's open or close.
Definition event.hpp:319
std::chrono::system_clock::time_point period_end_
When the bar's period ended: the earliest moment the bar could be known.
Definition event.hpp:329
InstrumentId instrument_
The instrument the bar is for.
Definition event.hpp:315
BarInterval interval_
The period length the bar covers.
Definition event.hpp:317
Every instrument's bar of one interval for one period end, delivered to on_bars.
Definition event.hpp:569
std::chrono::system_clock::time_point period_end_
When the period ended, shared by every bar in bars_.
Definition event.hpp:571
const BarEvent * find(const InstrumentId &id) const noexcept
Finds an instrument's bar.
Definition event.hpp:586
std::vector< BarEvent > bars_
The bars, one per instrument, in the order they were fed.
Definition event.hpp:575
BarInterval interval_
The period length every bar in bars_ covers.
Definition event.hpp:573
A record of data from outside the broker, delivered to on_data.
Definition event.hpp:856
std::chrono::system_clock::time_point known_at_
When the record became known: the earliest moment a strategy may see it, as BarEvent::period_end_ is ...
Definition event.hpp:864
One execution of an order the strategy placed, delivered to on_fill.
Definition event.hpp:886
std::chrono::system_clock::time_point at_
When the execution happened.
Definition event.hpp:900
InstrumentId instrument_
The instrument traded.
Definition event.hpp:890
std::string tag_
The tag of the intent that produced the order.
Definition event.hpp:898
OrderSide side_
The side of the order.
Definition event.hpp:892
std::string order_id_
The id of the order that traded: the broker's, or in a backtest the replay's.
Definition event.hpp:888
Decimal64 price_
The execution price.
Definition event.hpp:896
Decimal64 quantity_
The quantity of this execution, not the order's running total.
Definition event.hpp:894
A quote the runner has just read, delivered to on_quote.
Definition event.hpp:841
QuoteSnapshot quote_
The quote, as the broker reported it.
Definition event.hpp:843
Whether a bar opens or closes its session, as SessionEdges::next decided it.
Definition event.hpp:417
bool opens_
The bar opens its session: the first bar of its market-local date that reaches into the session,...
Definition event.hpp:422
bool closes_
The bar closes its session: the first bar of its date whose period holds the close,...
Definition event.hpp:427
bool point_
The bar's period is empty: it is one price at one instant, such as a daily bar stamped at the open.
Definition event.hpp:429
The intraday session of a market, as the operator states it.
Definition event.hpp:122
std::chrono::minutes open_
The session open, in minutes from local midnight.
Definition event.hpp:124
std::string source_
A description of where the window came from, for reports.
Definition event.hpp:130
std::chrono::minutes utc_offset_
The market's offset from UTC.
Definition event.hpp:128
MarketPhase phase(std::chrono::system_clock::time_point now, std::optional< bool > trading_day) const
Returns the market phase at an instant.
Definition event.hpp:149
std::chrono::system_clock::time_point opens_at(std::chrono::system_clock::time_point now) const
Returns the instant the session opens on the local date of an instant.
Definition event.hpp:187
std::chrono::minutes close_
The session close, in minutes from local midnight.
Definition event.hpp:126
Date local_date(std::chrono::system_clock::time_point now) const
Returns the market's local date at an instant.
Definition event.hpp:176
static SessionWindow krx()
Returns the KRX regular session, 09:00-15:30 KST.
Definition event.hpp:136
std::chrono::system_clock::time_point closes_at(std::chrono::system_clock::time_point now) const
Returns the instant the session closes on the local date of an instant.
Definition event.hpp:197