|
Leka
A low-latency C++20 price-time-priority limit order book and matching engine
|
Represents a resting or incoming order and its lifecycle state. More...
#include <order.hpp>
Public Member Functions | |
| Order (OrderId orderId, Price price, Quantity originalQuantity, Timestamp timestamp, OrderSide orderSide, OrderType orderType, SequenceNumber sequenceNumber) | |
| Constructs an order with remaining quantity equal to the original quantity. | |
| Order (OrderId orderId, Price price, Quantity originalQuantity, Quantity remainingQuantity, Timestamp timestamp, OrderSide orderSide, OrderType orderType, SequenceNumber sequenceNumber) | |
| Constructs an order with explicit original and remaining quantities. | |
| OrderId | getOrderId () const |
| Returns the unique order identifier. | |
| Price | getPrice () const |
| Returns the limit or reference price. | |
| Quantity | getOriginalQuantity () const |
| Returns the quantity submitted when the order was created. | |
| Quantity | getRemainingQuantity () const |
| Returns the quantity that has not yet executed. | |
| Timestamp | getTimestamp () const |
| Returns the order timestamp. | |
| OrderSide | getOrderSide () const |
| Returns whether this is a buy or sell order. | |
| OrderType | getOrderType () const |
| Returns the order type. | |
| SequenceNumber | getSequenceNumber () const |
| Returns the deterministic processing sequence. | |
| void | reduceRemainingQuantity (Quantity quantity) |
| Decreases remaining quantity; throws if the reduction would underflow. | |
| bool | isFullyFilled () const |
| Returns true when remaining quantity is zero. | |
| bool | isValid () const |
| Returns whether the order state satisfies its structural invariants. | |
| void | setRemainingQuantity (Quantity quantity) |
| Updates quantity while the order remains at its current price level. | |
| bool | isBuy () const |
| Returns true for a buy order. | |
| bool | isSell () const |
| Returns true for a sell order. | |
| bool | isLimit () const |
| Returns true for a limit order. | |
| bool | isMarket () const |
| Returns true for a market order. | |
Intrusive FIFO links | |
The next/previous pointers live inside Order itself rather than in a separate list node, so joining or leaving a PriceLevel's queue allocates nothing and unlinking a known order is O(1). The priceLevel back-pointer is what makes cancellation O(1) end to end: OrderIndex resolves an OrderId to this Order, and the order already knows which level to unlink itself from, with no search. These are maintained by PriceLevel and OrderBook; callers outside the book should treat them as read-only. | |
| Order * | getNextOrder () const |
| Returns the next order in this price level's FIFO, or nullptr at the tail. | |
| void | setNextOrder (Order *nextOrder) |
| Sets the next order in the FIFO. | |
| Order * | getPreviousOrder () const |
| Returns the previous order in this price level's FIFO, or nullptr at the head. | |
| void | setPreviousOrder (Order *previousOrder) |
| Sets the previous order in the FIFO. | |
| PriceLevel * | getPriceLevel () const |
| Returns the price level this order rests on, or nullptr when unlinked. | |
| void | setPriceLevel (PriceLevel *priceLevel) |
| Sets the owning price level; nullptr marks the order as unlinked. | |
Represents a resting or incoming order and its lifecycle state.
| lob::Order::Order | ( | OrderId | orderId, |
| Price | price, | ||
| Quantity | originalQuantity, | ||
| Timestamp | timestamp, | ||
| OrderSide | orderSide, | ||
| OrderType | orderType, | ||
| SequenceNumber | sequenceNumber ) |
Constructs an order with remaining quantity equal to the original quantity.
Constructs a new order with all submitted quantity initially remaining.
Definition at line 8 of file order.cpp.
References Order().
Referenced by getNextOrder(), getPreviousOrder(), Order(), setNextOrder(), and setPreviousOrder().
| OrderId lob::Order::getOrderId | ( | ) | const |
Returns the unique order identifier.
Definition at line 23 of file order.cpp.
Referenced by lob::OrderIndex::addOrder(), lob::OrderBook::removeOrder(), and lob::OrderIndex::removeOrder().
| Price lob::Order::getPrice | ( | ) | const |
Returns the limit or reference price.
Definition at line 24 of file order.cpp.
Referenced by lob::PriceLevel::addOrder(), and lob::OrderBook::removeOrder().
| Quantity lob::Order::getOriginalQuantity | ( | ) | const |
| Quantity lob::Order::getRemainingQuantity | ( | ) | const |
Returns the quantity that has not yet executed.
Definition at line 26 of file order.cpp.
Referenced by lob::PriceLevel::addOrder(), lob::OrderBook::reduceOrder(), and lob::PriceLevel::removeOrder().
| Timestamp lob::Order::getTimestamp | ( | ) | const |
| OrderSide lob::Order::getOrderSide | ( | ) | const |
| OrderType lob::Order::getOrderType | ( | ) | const |
| SequenceNumber lob::Order::getSequenceNumber | ( | ) | const |
| Order * lob::Order::getNextOrder | ( | ) | const |
Returns the next order in this price level's FIFO, or nullptr at the tail.
Definition at line 32 of file order.cpp.
References Order().
Referenced by lob::PriceLevel::removeOrder().
| void lob::Order::setNextOrder | ( | Order * | nextOrder | ) |
Sets the next order in the FIFO.
Called by PriceLevel during linking.
Definition at line 33 of file order.cpp.
References Order().
Referenced by lob::PriceLevel::addOrder(), and lob::PriceLevel::removeOrder().
| Order * lob::Order::getPreviousOrder | ( | ) | const |
Returns the previous order in this price level's FIFO, or nullptr at the head.
Definition at line 34 of file order.cpp.
References Order().
Referenced by lob::PriceLevel::removeOrder().
| void lob::Order::setPreviousOrder | ( | Order * | previousOrder | ) |
Sets the previous order in the FIFO.
Called by PriceLevel during linking.
Definition at line 35 of file order.cpp.
References Order().
Referenced by lob::PriceLevel::addOrder(), and lob::PriceLevel::removeOrder().
| PriceLevel * lob::Order::getPriceLevel | ( | ) | const |
Returns the price level this order rests on, or nullptr when unlinked.
Definition at line 36 of file order.cpp.
Referenced by lob::PriceLevel::addOrder(), lob::OrderBook::reduceOrder(), lob::OrderBook::removeOrder(), and lob::PriceLevel::removeOrder().
| void lob::Order::setPriceLevel | ( | PriceLevel * | priceLevel | ) |
Sets the owning price level; nullptr marks the order as unlinked.
Definition at line 37 of file order.cpp.
Referenced by lob::PriceLevel::addOrder(), and lob::PriceLevel::removeOrder().
| void lob::Order::reduceRemainingQuantity | ( | Quantity | quantity | ) |
Decreases remaining quantity; throws if the reduction would underflow.
Reduces remaining quantity and rejects underflow.
Definition at line 40 of file order.cpp.
References lob::Quantity::getQuantity().
| bool lob::Order::isFullyFilled | ( | ) | const |
Returns true when remaining quantity is zero.
An order is fully filled when no quantity remains.
Definition at line 49 of file order.cpp.
References lob::Quantity::getQuantity().
Referenced by lob::PriceLevel::addOrder().
| bool lob::Order::isValid | ( | ) | const |
| void lob::Order::setRemainingQuantity | ( | Quantity | quantity | ) |
Updates quantity while the order remains at its current price level.
Definition at line 62 of file order.cpp.
References lob::Quantity::isValid().
Referenced by lob::OrderBook::reduceOrder().
| bool lob::Order::isBuy | ( | ) | const |
Returns true for a buy order.
Definition at line 72 of file order.cpp.
Referenced by isValid(), and lob::OrderBook::removeOrder().
| bool lob::Order::isSell | ( | ) | const |
| bool lob::Order::isLimit | ( | ) | const |
| bool lob::Order::isMarket | ( | ) | const |