Leka
A low-latency C++20 price-time-priority limit order book and matching engine
▶ Replay viewer
Loading...
Searching...
No Matches
order_event.cpp
Go to the documentation of this file.
2
3#include <stdexcept>
4#include <utility>
5
6namespace lob {
7
8/**
9 * @file
10 * @brief Implements type-safe NEW, CANCEL, and REDUCE event payload access.
11 */
12
13/** Constructs a NEW event from its payload. */
14OrderEvent::OrderEvent(NewOrder order) : payload(std::move(order)) {}
15
16/** Constructs a CANCEL event from its payload. */
17OrderEvent::OrderEvent(CancelOrder order) : payload(order) {}
18
19/** Constructs a REDUCE event from its payload. */
20OrderEvent::OrderEvent(ReduceOrder order) : payload(order) {}
21
22/** Returns the variant index corresponding to the event operation. */
24 return static_cast<OrderEventType>(payload.index());
25}
26
27/**
28 * @details The accessors test the active alternative once through get_if
29 * rather than pairing holds_alternative with get, which would discriminate
30 * the variant twice on every dispatched event.
31 */
33 const NewOrder* order = std::get_if<NewOrder>(&payload);
34 if (order == nullptr) {
35 throw std::logic_error("Order event is not NEW");
36 }
37 return *order;
38}
39
40/** Returns the CANCEL payload after checking the active event type. */
42 const CancelOrder* order = std::get_if<CancelOrder>(&payload);
43 if (order == nullptr) {
44 throw std::logic_error("Order event is not CANCEL");
45 }
46 return *order;
47}
48
49/** Returns the REDUCE payload after checking the active event type. */
51 const ReduceOrder* order = std::get_if<ReduceOrder>(&payload);
52 if (order == nullptr) {
53 throw std::logic_error("Order event is not REDUCE");
54 }
55 return *order;
56}
57
58} // namespace lob
const NewOrder & getNewOrder() const
Returns the NEW payload or throws when this is not a NEW event.
OrderEvent(NewOrder order)
Creates a NEW event.
const CancelOrder & getCancelOrder() const
Returns the CANCEL payload or throws when this is not a CANCEL event.
const ReduceOrder & getReduceOrder() const
Returns the REDUCE payload or throws when this is not a REDUCE event.
OrderEventType getEventType() const
Returns the operation represented by the active payload.
Defines event-first order command payloads and dispatch types.
OrderEventType
Operation selected before an event payload is interpreted.
Payload for removing an existing resting order.
Payload for accepting a new order.
Payload for shrinking a resting order without losing priority.