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

Classes

class  CandlestickPublisher
struct  Candle
class  ActionSpmcReceiver
class  ActionSpmcSender
class  EventMpscQueue
class  SharedMemory
struct  L1Data
struct  L2Data
struct  Order
class  OrderBook
struct  Trade
struct  Action
struct  OrderAddedAction
struct  OrderDownsizedAction
struct  OrderRemovedAction
struct  OrderUpsizedAction
struct  TradeAction
struct  AmendLimitOrderEvent
struct  CancelLimitOrderEvent
struct  Event
struct  NewLimitOrderEvent
struct  NewMarketOrderEvent
struct  AccountId
struct  OrderId
struct  Price
struct  Quantity
struct  SecurityId
class  Gateway
class  EventGenerator
class  MatchingEngine
class  OrderbookPublisher

Typedefs

using OrderBookMap = std::map<Price, std::list<Order>, std::function<bool(const Price &, const Price &)>>
using OrderLookupValue = std::pair<std::list<Order> *, std::list<Order>::iterator>
using TimestampNs = std::chrono::sys_time<std::chrono::nanoseconds>

Enumerations

enum class  OrderType : uint8_t { LIMIT , MARKET }
enum class  Side : uint8_t { BUY , SELL }
enum class  TimeInForce : uint8_t { GTC , IOC , FOK }

Functions

int archiverProcessMain () noexcept
int candlestickPublisherMain () noexcept
void assertOrderBookInvariants (const OrderBook &orderBook, bool onlyOrderBookAsserts=false)
void assertRestingOrderInvariants (const Order &order, Side bookSide, Price priceLevel)
void assertMatchingInvariants (const Order &aggressor, Quantity aggressorFilledQuantity, std::vector< std::pair< Trade, Order > > tradeRestingPairs)
int executionPublisherMain () noexcept
int gatewayMain () noexcept
std::vector< Event > decodeEvents (std::span< const uint8_t > bytes, std::span< const SecurityId > securities)
std::vector< uint8_t > encodeEvents (std::span< const Event > events, std::span< const SecurityId > securities)
void serializeEventsIntoSeedsDirectory (const std::unordered_map< std::string, std::span< const Event > > &seeds)
void fuzzMatchingEngine (std::span< const uint8_t > bytes)
void runBinarySeed (const std::filesystem::path &path)
OrderId makeOrderId (uint64_t seed)
int matchingEngineMain () noexcept
int orderManagerMain () noexcept
int orderbookPublisherMain () noexcept

Variables

constexpr std::array FUZZING_SECURITY_IDS {SecurityId{1}, SecurityId{2}}
constexpr EventGenerator::Config EVENT_GENERATOR_CONFIG_FOR_DIFFERENTIAL_TESTING

Typedef Documentation

◆ OrderBookMap

using exchange::server::OrderBookMap = std::map<Price, std::list<Order>, std::function<bool(const Price &, const Price &)>>

◆ OrderLookupValue

using exchange::server::OrderLookupValue = std::pair<std::list<Order> *, std::list<Order>::iterator>

◆ TimestampNs

using exchange::server::TimestampNs = std::chrono::sys_time<std::chrono::nanoseconds>

Enumeration Type Documentation

◆ OrderType

enum class exchange::server::OrderType : uint8_t
strong
Enumerator
LIMIT 
MARKET 

◆ Side

enum class exchange::server::Side : uint8_t
strong
Enumerator
BUY 
SELL 

◆ TimeInForce

enum class exchange::server::TimeInForce : uint8_t
strong
Enumerator
GTC 
IOC 
FOK 

Function Documentation

◆ archiverProcessMain()

int exchange::server::archiverProcessMain ( )
noexcept

The starting point of the exchange archiver process.

Returns
The exit code of the program.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ assertMatchingInvariants()

void exchange::server::assertMatchingInvariants ( const Order & aggressor,
Quantity aggressorFilledQuantity,
std::vector< std::pair< Trade, Order > > tradeRestingPairs )

Calls assert() to check for these invariants:

  • Trade prices are non-decreasing for buys and non-increasing for sells, and are never worse than the price of the aggressor.
  • The quantity of trades is less than or equal to the remaining quantity of the aggressor (before any trades).
  • The quantity of trades is equal to the increase in the filledQuantity of the aggressor.
  • Every trade executes at the resting order's price.
  • At most one resting order ends partially filled, and its trade is the last one in the list.
Parameters
aggressorThe newly arrived order that matches with resting orders (before any trades are performed).
aggressorFilledQuantityHow much the filled quantity of the aggressor is after all trades are performed.
tradeRestingPairsPairs of the trade and the corresponding matching order (before the trade is made).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ assertOrderBookInvariants()

void exchange::server::assertOrderBookInvariants ( const OrderBook & orderBook,
bool onlyOrderBookAsserts = false )

Calls assert() to check for these invariants:

  • The best buy price is less than the best sell price.
  • The size of the order lookup table is equal to the number of orders.
Parameters
orderBookThe orderbook to perform the assertions on.
onlyOrderBookAssertsIf true, it only performs the aforementioned asserts. Otherwise, it also runs the asserts to check the invariants of every resting order, described by assertRestingOrderInvariants.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ assertRestingOrderInvariants()

void exchange::server::assertRestingOrderInvariants ( const Order & order,
Side bookSide,
Price priceLevel )

Calls assert() to check for these invariants:

  • Every resting order has less filled quantity than total quantity.
  • Every resting order is resting in the correct book and at the correct price level.
Parameters
orderThe order to perform the assertions on.
bookSideThe actual book the order rests on (buy book or sell book).
priceLevelThe price level in the orderbook at which the order rests.
Here is the caller graph for this function:

◆ candlestickPublisherMain()

int exchange::server::candlestickPublisherMain ( )
noexcept

The starting point of the exchange candlestick data publisher.

Returns
The exit code of the program.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decodeEvents()

std::vector< Event > exchange::server::decodeEvents ( std::span< const uint8_t > bytes,
std::span< const SecurityId > securities )

Decode a list of domain events from an array of bytes.

Parameters
bytesThe serialized bytes.
securitiesThe set of valid security ids.
Returns
A list of events decoded from the bytes.
Here is the caller graph for this function:

◆ encodeEvents()

std::vector< uint8_t > exchange::server::encodeEvents ( std::span< const Event > events,
std::span< const SecurityId > securities )

Encode a list of domain events into an array of bytes.

Parameters
eventsThe events to encode.
securitiesThe set of valid security ids.
Returns
A list of events encoded into bytes.
Here is the caller graph for this function:

◆ executionPublisherMain()

int exchange::server::executionPublisherMain ( )
noexcept

The starting point of the execution data publisher.

Returns
The exit code of the program.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fuzzMatchingEngine()

void exchange::server::fuzzMatchingEngine ( std::span< const uint8_t > bytes)

A lower-level function called indirectly by the fuzzer that decodes the array of bytes into events and runs the matching engine on them.

Parameters
bytesThe encoded events to run on the matching engine.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gatewayMain()

int exchange::server::gatewayMain ( )
noexcept

The starting point of the exchange server gateway.

Returns
The exit code of the program.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeOrderId()

OrderId exchange::server::makeOrderId ( uint64_t seed)
Here is the caller graph for this function:

◆ matchingEngineMain()

int exchange::server::matchingEngineMain ( )
noexcept

The starting point of the matching engine.

Returns
The exit code of the program.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ orderbookPublisherMain()

int exchange::server::orderbookPublisherMain ( )
noexcept

The starting point of the Orderbook data publisher.

Returns
The exit code of the program.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ orderManagerMain()

int exchange::server::orderManagerMain ( )
noexcept

The starting point of the Order Manager.

Returns
The exit code of the program.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ runBinarySeed()

void exchange::server::runBinarySeed ( const std::filesystem::path & path)

Read the binary file and call fuzzMatchingEngine with its contents;

Parameters
pathThe path of the binary file.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ serializeEventsIntoSeedsDirectory()

void exchange::server::serializeEventsIntoSeedsDirectory ( const std::unordered_map< std::string, std::span< const Event > > & seeds)

For each file name-list of events pair, it writes the file with the serialized list of events into the ./seeds directory.

Parameters
seedsA mapping of file name to list of events.
Here is the call graph for this function:

Variable Documentation

◆ EVENT_GENERATOR_CONFIG_FOR_DIFFERENTIAL_TESTING

EventGenerator::Config exchange::server::EVENT_GENERATOR_CONFIG_FOR_DIFFERENTIAL_TESTING
inlineconstexpr
Initial value:
{
.orderIdPool = 16,
.minPrice = 98,
.priceCount = 5,
.sidePriceOffset = 0,
.newLimitWeight = 90,
.marketWeight = 20,
.amendWeight = 60,
.cancelWeightPerLiveOrder = 6,
}

◆ FUZZING_SECURITY_IDS

std::array exchange::server::FUZZING_SECURITY_IDS {SecurityId{1}, SecurityId{2}}
inlineconstexpr