exchange
Low-latency exchange in C++
Loading...
Searching...
No Matches
exchange::server::OrderBook Class Reference

#include <orderbook.hpp>

Classes

struct  AddOrderResult
struct  AmendOrderResult

Public Types

enum class  AmendOrderStatus : uint8_t { CANNOT_AMEND , AMENDED_IN_PLACE , AMENDED , REMOVED }

Public Member Functions

 OrderBook ()=default
 OrderBook (const OrderBook &)=delete
OrderBook & operator= (const OrderBook &)=delete
 OrderBook (OrderBook &&) noexcept=default
OrderBook & operator= (OrderBook &&) noexcept=default
AddOrderResult addOrder (OrderId orderId, Side side, std::optional< Price > price, Quantity totalQuantity, Quantity filledQuantity, TimeInForce timeInForce, OrderType orderType) noexcept
bool removeOrder (OrderId orderId) noexcept
AmendOrderStatus amendOrder (OrderId orderId, Quantity newQuantity) noexcept
AmendOrderResult amendOrder (OrderId orderId, Price newPrice) noexcept
AmendOrderResult amendOrder (OrderId orderId, Quantity newQuantity, Price newPrice) noexcept
const OrderBookMap & getBuyBook () const noexcept
const OrderBookMap & getSellBook () const noexcept
std::optional< Order > getOrder (OrderId orderId) const noexcept
std::size_t orderCount () const noexcept
std::size_t orderLookupSize () const noexcept

Member Enumeration Documentation

◆ AmendOrderStatus

enum class exchange::server::OrderBook::AmendOrderStatus : uint8_t
strong
Enumerator
CANNOT_AMEND 
AMENDED_IN_PLACE 
AMENDED 
REMOVED 

Constructor & Destructor Documentation

◆ OrderBook() [1/3]

exchange::server::OrderBook::OrderBook ( )
default
Here is the caller graph for this function:

◆ OrderBook() [2/3]

exchange::server::OrderBook::OrderBook ( const OrderBook & )
delete
Here is the call graph for this function:

◆ OrderBook() [3/3]

exchange::server::OrderBook::OrderBook ( OrderBook && )
defaultnoexcept
Here is the call graph for this function:

Member Function Documentation

◆ addOrder()

OrderBook::AddOrderResult exchange::server::OrderBook::addOrder ( OrderId orderId,
Side side,
std::optional< Price > price,
Quantity totalQuantity,
Quantity filledQuantity,
TimeInForce timeInForce,
OrderType orderType )
noexcept

Try to match an order to what currently exists on the book, if possible, and then potentially add it to the book in the case of GTC limit orders.

Parameters
orderIdThe id of the incoming order
sideThe side of the incoming order (BUY or SELL)
priceThe price of the incoming order, if it is a limit order
totalQuantityThe original quantity of the incoming order
filledQuantityThe quantity of the incoming order that was already filled
timeInForceThe time in force of the incoming order
orderTypeWhether the incoming order is a limit order or a market order
Returns
A list of matches performed between the incoming order and orders resting on the book, if any
Here is the call graph for this function:
Here is the caller graph for this function:

◆ amendOrder() [1/3]

OrderBook::AmendOrderResult exchange::server::OrderBook::amendOrder ( OrderId orderId,
Price newPrice )
noexcept

Modify the price of a GTC limit order that is currently resting on the book. Always resets time priority.

Parameters
orderIdThe id of the order to amend
newPriceThe new price of the order
Here is the call graph for this function:

◆ amendOrder() [2/3]

OrderBook::AmendOrderStatus exchange::server::OrderBook::amendOrder ( OrderId orderId,
Quantity newQuantity )
noexcept

Modify the quantity of a GTC limit order that is currently resting on the book. Specifying a quantity less than the original one does not reset time priority.

Parameters
orderIdThe id of the order to amend
newQuantityThe new total quantity of the order
Here is the call graph for this function:
Here is the caller graph for this function:

◆ amendOrder() [3/3]

OrderBook::AmendOrderResult exchange::server::OrderBook::amendOrder ( OrderId orderId,
Quantity newQuantity,
Price newPrice )
noexcept

Modify the quantity and price of a GTC limit order that is currently resting on the book. Resets time priority, unless the price is unchanged and the quantity only decreases, which is treated the same as amending the quantity on its own.

Parameters
orderIdThe id of the order to amend
newQuantityThe new total quantity of the order
newPriceThe new price of the order
Here is the call graph for this function:

◆ getBuyBook()

const OrderBookMap & exchange::server::OrderBook::getBuyBook ( ) const
nodiscardnoexcept

Getter for a read-only view of the buy book.

Returns
A read-only view of the buy book.
Here is the caller graph for this function:

◆ getOrder()

std::optional< Order > exchange::server::OrderBook::getOrder ( OrderId orderId) const
nodiscardnoexcept

Getter for a specific order in the orderbook by order id.

Parameters
orderIdThe id of the order to fetch.
Returns
A copy of the order with the given order id, if an order with the given order id exists.

◆ getSellBook()

const OrderBookMap & exchange::server::OrderBook::getSellBook ( ) const
nodiscardnoexcept

Getter for a read-only view of the sell book.

Returns
A read-only view of the sell book.
Here is the caller graph for this function:

◆ operator=() [1/2]

OrderBook & exchange::server::OrderBook::operator= ( const OrderBook & )
delete
Here is the call graph for this function:

◆ operator=() [2/2]

OrderBook & exchange::server::OrderBook::operator= ( OrderBook && )
defaultnoexcept
Here is the call graph for this function:

◆ orderCount()

std::size_t exchange::server::OrderBook::orderCount ( ) const
nodiscardnoexcept

Returns the number of orders in both the buy and the sell books.

Time complexity is O(number of price levels). Do not use on the hot path.

Returns
The number of orders in both the buy and the sell books.
Here is the caller graph for this function:

◆ orderLookupSize()

std::size_t exchange::server::OrderBook::orderLookupSize ( ) const
nodiscardnoexcept

Returns the size of the order lookup table.

Returns
The size of the lookup table. Should be equal to the result of orderCount().
Here is the caller graph for this function:

◆ removeOrder()

bool exchange::server::OrderBook::removeOrder ( OrderId orderId)
noexcept

Remove a GTC limit order that is currently resting on the book.

Parameters
orderIdThe id of the order to remove
Returns
True if the order is resting on the book, false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

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