CppTrader  1.0.4.0
C++ Trader
Public Types | Public Member Functions | Friends | List of all members
CppTrader::Matching::MarketManager Class Reference

Market manager. More...

#include <market_manager.h>

Public Types

typedef std::vector< Symbol * > Symbols
 Symbols container. More...
 
typedef std::vector< OrderBook * > OrderBooks
 Order books container. More...
 
typedef CppCommon::HashMap< uint64_t, OrderNode *, FastHashOrders
 Orders container. More...
 

Public Member Functions

 MarketManager ()
 
 MarketManager (MarketHandler &market_handler)
 
 MarketManager (const MarketManager &)=delete
 
 MarketManager (MarketManager &&)=delete
 
 ~MarketManager ()
 
MarketManageroperator= (const MarketManager &)=delete
 
MarketManageroperator= (MarketManager &&)=delete
 
const Symbolssymbols () const noexcept
 Get the symbols container. More...
 
const OrderBooksorder_books () const noexcept
 Get the order books container. More...
 
const Ordersorders () const noexcept
 Get the orders container. More...
 
const SymbolGetSymbol (uint32_t id) const noexcept
 Get the symbol with the given Id. More...
 
const OrderBookGetOrderBook (uint32_t id) const noexcept
 Get the order book for the given symbol Id. More...
 
const OrderGetOrder (uint64_t id) const noexcept
 Get the order with the given Id. More...
 
ErrorCode AddSymbol (const Symbol &symbol)
 Add a new symbol. More...
 
ErrorCode DeleteSymbol (uint32_t id)
 Delete the symbol. More...
 
ErrorCode AddOrderBook (const Symbol &symbol)
 Add a new order book. More...
 
ErrorCode DeleteOrderBook (uint32_t id)
 Delete the order book. More...
 
ErrorCode AddOrder (const Order &order)
 Add a new order. More...
 
ErrorCode ReduceOrder (uint64_t id, uint64_t quantity)
 Reduce the order by the given quantity. More...
 
ErrorCode ModifyOrder (uint64_t id, uint64_t new_price, uint64_t new_quantity)
 Modify the order. More...
 
ErrorCode MitigateOrder (uint64_t id, uint64_t new_price, uint64_t new_quantity)
 Mitigate the order. More...
 
ErrorCode ReplaceOrder (uint64_t id, uint64_t new_id, uint64_t new_price, uint64_t new_quantity)
 Replace the order with a similar order but different Id, price and quantity. More...
 
ErrorCode ReplaceOrder (uint64_t id, const Order &new_order)
 Replace the order with a new one. More...
 
ErrorCode DeleteOrder (uint64_t id)
 Delete the order. More...
 
ErrorCode ExecuteOrder (uint64_t id, uint64_t quantity)
 Execute the order. More...
 
ErrorCode ExecuteOrder (uint64_t id, uint64_t price, uint64_t quantity)
 Execute the order. More...
 
bool IsMatchingEnabled () const noexcept
 Is automatic matching enabled? More...
 
void EnableMatching ()
 Enable automatic matching. More...
 
void DisableMatching ()
 Disable automatic matching. More...
 
void Match ()
 Match crossed orders in all order books. More...
 

Friends

class OrderBook
 

Detailed Description

Market manager.

Market manager is used to manage the market with symbols, orders and order books.

Automatic orders matching can be enabled with EnableMatching() method or can be manually performed with Match() method.

Not thread-safe.

Definition at line 38 of file market_manager.h.

Member Typedef Documentation

◆ OrderBooks

Order books container.

Definition at line 46 of file market_manager.h.

◆ Orders

typedef CppCommon::HashMap<uint64_t, OrderNode*, FastHash> CppTrader::Matching::MarketManager::Orders

Orders container.

Definition at line 48 of file market_manager.h.

◆ Symbols

Symbols container.

Definition at line 44 of file market_manager.h.

Constructor & Destructor Documentation

◆ MarketManager() [1/4]

CppTrader::Matching::MarketManager::MarketManager ( )
inline

Definition at line 12 of file market_manager.inl.

◆ MarketManager() [2/4]

CppTrader::Matching::MarketManager::MarketManager ( MarketHandler market_handler)
inline

Definition at line 17 of file market_manager.inl.

◆ MarketManager() [3/4]

CppTrader::Matching::MarketManager::MarketManager ( const MarketManager )
delete

◆ MarketManager() [4/4]

CppTrader::Matching::MarketManager::MarketManager ( MarketManager &&  )
delete

◆ ~MarketManager()

CppTrader::Matching::MarketManager::~MarketManager ( )

Definition at line 16 of file market_manager.cpp.

Member Function Documentation

◆ AddOrder()

ErrorCode CppTrader::Matching::MarketManager::AddOrder ( const Order order)

Add a new order.

Parameters
order- Order to add
Returns
Error code

Definition at line 135 of file market_manager.cpp.

◆ AddOrderBook()

ErrorCode CppTrader::Matching::MarketManager::AddOrderBook ( const Symbol symbol)

Add a new order book.

Parameters
symbol- Symbol of the order book to add
Returns
Error code

Definition at line 82 of file market_manager.cpp.

◆ AddSymbol()

ErrorCode CppTrader::Matching::MarketManager::AddSymbol ( const Symbol symbol)

Add a new symbol.

Parameters
symbol- Symbol to add
Returns
Error code

Definition at line 36 of file market_manager.cpp.

◆ DeleteOrder()

ErrorCode CppTrader::Matching::MarketManager::DeleteOrder ( uint64_t  id)

Delete the order.

Parameters
id- Order Id
Returns
Error code

Definition at line 815 of file market_manager.cpp.

◆ DeleteOrderBook()

ErrorCode CppTrader::Matching::MarketManager::DeleteOrderBook ( uint32_t  id)

Delete the order book.

Parameters
id- Symbol Id of the order book
Returns
Error code

Definition at line 114 of file market_manager.cpp.

◆ DeleteSymbol()

ErrorCode CppTrader::Matching::MarketManager::DeleteSymbol ( uint32_t  id)

Delete the symbol.

Parameters
id- Symbol Id
Returns
Error code

Definition at line 61 of file market_manager.cpp.

◆ DisableMatching()

void CppTrader::Matching::MarketManager::DisableMatching ( )
inline

Disable automatic matching.

Definition at line 214 of file market_manager.h.

◆ EnableMatching()

void CppTrader::Matching::MarketManager::EnableMatching ( )
inline

Enable automatic matching.

Definition at line 212 of file market_manager.h.

◆ ExecuteOrder() [1/2]

ErrorCode CppTrader::Matching::MarketManager::ExecuteOrder ( uint64_t  id,
uint64_t  price,
uint64_t  quantity 
)

Execute the order.

Parameters
id- Order Id
price- Order executed price
quantity- Order executed quantity
Returns
Error code

Definition at line 968 of file market_manager.cpp.

◆ ExecuteOrder() [2/2]

ErrorCode CppTrader::Matching::MarketManager::ExecuteOrder ( uint64_t  id,
uint64_t  quantity 
)

Execute the order.

Parameters
id- Order Id
quantity- Order executed quantity
Returns
Error code

Definition at line 877 of file market_manager.cpp.

◆ GetOrder()

const Order * CppTrader::Matching::MarketManager::GetOrder ( uint64_t  id) const
inlinenoexcept

Get the order with the given Id.

Parameters
id- Order Id
Returns
Pointer to the order with the given Id or nullptr

Definition at line 44 of file market_manager.inl.

◆ GetOrderBook()

const OrderBook * CppTrader::Matching::MarketManager::GetOrderBook ( uint32_t  id) const
inlinenoexcept

Get the order book for the given symbol Id.

Parameters
id- Symbol Id of the order book
Returns
Pointer to the order book with the given symbol Id or nullptr

Definition at line 39 of file market_manager.inl.

◆ GetSymbol()

const Symbol * CppTrader::Matching::MarketManager::GetSymbol ( uint32_t  id) const
inlinenoexcept

Get the symbol with the given Id.

Parameters
id- Symbol Id
Returns
Pointer to the symobl with the given Id or nullptr

Definition at line 34 of file market_manager.inl.

◆ IsMatchingEnabled()

bool CppTrader::Matching::MarketManager::IsMatchingEnabled ( ) const
inlinenoexcept

Is automatic matching enabled?

Definition at line 210 of file market_manager.h.

◆ Match()

void CppTrader::Matching::MarketManager::Match ( )

Match crossed orders in all order books.

Method will match all crossed orders in each order book. Buy orders will be matched with sell orders at arbitrage price starting from the top of the book. Matched orders will be executed with deleted form the order book. After the matching operation each order book will have the best bid price guarantied less than the best ask price!

Definition at line 1059 of file market_manager.cpp.

◆ MitigateOrder()

ErrorCode CppTrader::Matching::MarketManager::MitigateOrder ( uint64_t  id,
uint64_t  new_price,
uint64_t  new_quantity 
)

Mitigate the order.

The in-flight mitigation functionality prevents an order from being filled for a quantity greater than the quantity requested by the user. It protects from the risk of a resting order being filled between the time an order modification is submitted and the time the order modification is processed and applied to the order.

Order new quantity will be calculated in a following way:

if (new_quantity > oder.ExecutedQuantity)
{
oder.Quantity = new_quantity;
oder.LeavesQuantity = new_quantity - oder.ExecutedQuantity;
// Order will be modified...
}
else
{
oder.Quantity = new_quantity;
oder.LeavesQuantity = 0;
// Order will be canceled...
}
Parameters
id- Order Id
new_price- Order price to mitigate
new_quantity- Order quantity to mitigate
Returns
Error code

Definition at line 562 of file market_manager.cpp.

◆ ModifyOrder()

ErrorCode CppTrader::Matching::MarketManager::ModifyOrder ( uint64_t  id,
uint64_t  new_price,
uint64_t  new_quantity 
)

Modify the order.

Order new quantity will be calculated in a following way:

oder.Quantity = new_quantity;
oder.LeavesQuantity = new_quantity;
Parameters
id- Order Id
new_price- Order price to modify
new_quantity- Order quantity to modify
Returns
Error code

Definition at line 557 of file market_manager.cpp.

◆ operator=() [1/2]

MarketManager& CppTrader::Matching::MarketManager::operator= ( const MarketManager )
delete

◆ operator=() [2/2]

MarketManager& CppTrader::Matching::MarketManager::operator= ( MarketManager &&  )
delete

◆ order_books()

const OrderBooks& CppTrader::Matching::MarketManager::order_books ( ) const
inlinenoexcept

Get the order books container.

Definition at line 62 of file market_manager.h.

◆ orders()

const Orders& CppTrader::Matching::MarketManager::orders ( ) const
inlinenoexcept

Get the orders container.

Definition at line 64 of file market_manager.h.

◆ ReduceOrder()

ErrorCode CppTrader::Matching::MarketManager::ReduceOrder ( uint64_t  id,
uint64_t  quantity 
)

Reduce the order by the given quantity.

Parameters
id- Order Id
quantity- Order quantity to reduce
Returns
Error code

Definition at line 452 of file market_manager.cpp.

◆ ReplaceOrder() [1/2]

ErrorCode CppTrader::Matching::MarketManager::ReplaceOrder ( uint64_t  id,
const Order new_order 
)

Replace the order with a new one.

Parameters
id- Order Id
new_order- Order to replace
Returns
Error code

Definition at line 804 of file market_manager.cpp.

◆ ReplaceOrder() [2/2]

ErrorCode CppTrader::Matching::MarketManager::ReplaceOrder ( uint64_t  id,
uint64_t  new_id,
uint64_t  new_price,
uint64_t  new_quantity 
)

Replace the order with a similar order but different Id, price and quantity.

Parameters
id- Order Id
new_id- Order Id to replace
new_price- Order price to replace
new_quantity- Order quantity to replace
Returns
Error code

Definition at line 680 of file market_manager.cpp.

◆ symbols()

const Symbols& CppTrader::Matching::MarketManager::symbols ( ) const
inlinenoexcept

Get the symbols container.

Definition at line 60 of file market_manager.h.

Friends And Related Function Documentation

◆ OrderBook

friend class OrderBook
friend

Definition at line 40 of file market_manager.h.


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