Leka
A low-latency C++20 price-time-priority limit order book and matching engine
▶ Replay viewer
Loading...
Searching...
No Matches
lob::Order Class Reference

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.

OrdergetNextOrder () 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.
OrdergetPreviousOrder () 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.
PriceLevelgetPriceLevel () 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.

Detailed Description

Represents a resting or incoming order and its lifecycle state.

Definition at line 17 of file order.hpp.

Constructor & Destructor Documentation

◆ Order() [1/2]

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().

◆ Order() [2/2]

lob::Order::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.

Constructs an order with explicit submitted and remaining quantities.

Definition at line 15 of file order.cpp.

Member Function Documentation

◆ getOrderId()

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().

◆ getPrice()

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().

◆ getOriginalQuantity()

Quantity lob::Order::getOriginalQuantity ( ) const

Returns the quantity submitted when the order was created.

Definition at line 25 of file order.cpp.

◆ getRemainingQuantity()

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().

◆ getTimestamp()

Timestamp lob::Order::getTimestamp ( ) const

Returns the order timestamp.

Definition at line 27 of file order.cpp.

◆ getOrderSide()

OrderSide lob::Order::getOrderSide ( ) const

Returns whether this is a buy or sell order.

Definition at line 28 of file order.cpp.

◆ getOrderType()

OrderType lob::Order::getOrderType ( ) const

Returns the order type.

Definition at line 29 of file order.cpp.

◆ getSequenceNumber()

SequenceNumber lob::Order::getSequenceNumber ( ) const

Returns the deterministic processing sequence.

Definition at line 30 of file order.cpp.

◆ getNextOrder()

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().

◆ setNextOrder()

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().

◆ getPreviousOrder()

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().

◆ setPreviousOrder()

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().

◆ getPriceLevel()

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().

◆ setPriceLevel()

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().

◆ reduceRemainingQuantity()

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().

◆ isFullyFilled()

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().

◆ isValid()

bool lob::Order::isValid ( ) const

Returns whether the order state satisfies its structural invariants.

Validates identity, quantities, temporal fields, side, type, and price.

Definition at line 52 of file order.cpp.

References isBuy(), isLimit(), isMarket(), and isSell().

◆ setRemainingQuantity()

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().

◆ isBuy()

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().

◆ isSell()

bool lob::Order::isSell ( ) const

Returns true for a sell order.

Definition at line 73 of file order.cpp.

Referenced by isValid().

◆ isLimit()

bool lob::Order::isLimit ( ) const

Returns true for a limit order.

Definition at line 74 of file order.cpp.

Referenced by isValid().

◆ isMarket()

bool lob::Order::isMarket ( ) const

Returns true for a market order.

Definition at line 75 of file order.cpp.

Referenced by isValid().


The documentation for this class was generated from the following files: