dxFeed Graal CXX API v4.0.0
Loading...
Searching...
No Matches
MarketDepthModel< O > Struct Template Referencefinal

Represents a model for market depth, tracking buy and sell orders and notifies listener of changes in the order book. More...

#include <MarketDepthModel.hpp>

+ Inheritance diagram for MarketDepthModel< O >:

Classes

struct  SortedOrderSet
 Represents a set of orders, sorted by a comparator. More...
 

Public Member Functions

std::size_t getDepthLimit () const
 
void setDepthLimit (std::size_t depthLimit)
 Sets the depth limit of the book.
 
std::int64_t getAggregationPeriod () const
 
void setAggregationPeriod (std::int64_t aggregationPeriodMillis)
 Sets the aggregation period in milliseconds.
 
void setAggregationPeriod (std::chrono::milliseconds aggregationPeriod)
 Sets the aggregation period.
 
void close () const
 Closes this model and makes it permanently detached.
 
- Public Member Functions inherited from SharedEntity
template<typename T >
bool is () const noexcept
 Checks that pointer to the current type could be converted to type T* In other words: whether type T belongs to the type hierarchy in which the current type resides.
 
template<typename T >
std::shared_ptr< T > sharedAs () noexcept
 Returns a pointer to the current object wrapped in a smart pointer to type T.
 
template<typename T >
std::shared_ptr< T > sharedAs () const noexcept
 Returns a pointer to the current object wrapped in a smart pointer to type T.
 
virtual std::string toString () const
 Returns a string representation of the current object.
 
- Public Member Functions inherited from Entity
virtual ~Entity () noexcept=default
 The default virtual d-tor.
 

Static Public Member Functions

static std::shared_ptr< Builder > newBuilder ()
 Creates a new builder instance for constructing a MarketDepthModel.
 
- Static Public Member Functions inherited from RequireMakeShared< MarketDepthModel< O > >
static auto createShared (Args &&...args)
 Creates smart pointer to object.
 

Additional Inherited Members

- Public Types inherited from SharedEntity
using Ptr = std::shared_ptr<SharedEntity>
 The alias to a type of shared pointer to the SharedEntity object.
 

Detailed Description

template<Derived< OrderBase > O>
struct MarketDepthModel< O >

Represents a model for market depth, tracking buy and sell orders and notifies listener of changes in the order book.

This model can set depth limit and aggregation period. This model notifies the user of received transactions through an installed MarketDepthModelListener.

The depth limit specifies the maximum number of buy or sell orders to maintain in the order book. For example, if the depth limit is set to 10, the model will only keep track of the top 10 buy orders and the top 10 sell orders. This helps in managing the size of the order book.

The aggregation period, specified in milliseconds, determines the frequency at which the model aggregates and notifies changes in the order book to the listeners. For instance, if the aggregation period is set to 1000 milliseconds the model will aggregate changes and notify listeners every second. A value of 0 means that changes are notified immediately.

Configuration

This model must be configured using the Builder class, as most configuration settings cannot be changed once the model is built. This model requires configuration MarketDepthModel::Builder::withSymbol() and it must be MarketDepthModel::Builder::withFeed() attached to a DXFeed instance to begin operation.

This model only supports single symbol subscriptions; multiple symbols cannot be configured.

The convenient way to detach model from the feed is to call its MarketDepthModel::close() method. Closed model becomes permanently detached from all feeds, removes all its listeners.

This class is thread-safe and can be used concurrently from multiple threads without external synchronization.

Sample:

using namespace std::literals;
auto feed = ep->getFeed();
auto model =
->withFeed(feed)
->withSources({OrderSource::NTV})
->withSymbol("AAPL")
->withDepthLimit(10)
->withAggregationPeriod(5s)
->withListener([](const std::vector<std::shared_ptr<Order>> &buy,
const std::vector<std::shared_ptr<Order>> &sell) {
if (buy.empty() && sell.empty()) {
return;
}
std::cout << std::format("{:=^66}\n", "");
std::cout << std::format("{:^31} || {:^31}\n", "ASK", "BID");
std::cout << std::format("{0:^15}|{1:^15} || {0:^15}|{1:^15}\n", "Price", "Size");
std::cout << std::format("{:-^66}\n", "");
for (auto buyIt = buy.begin(), sellIt = sell.begin(); buyIt != buy.end() && sellIt != sell.end();) {
std::string row{};
if (buyIt != buy.end()) {
row += std::format("{:>14.4f} | {:<14.2f}", (*buyIt)->getPrice(), (*buyIt)->getSize());
++buyIt;
} else {
row += std::format("{:>14} | {:<14}", "", "");
}
row += " || ";
if (sellIt != sell.end()) {
row += std::format("{:>14.4f} | {:<14.2f}", (*sellIt)->getPrice(), (*sellIt)->getSize());
++sellIt;
} else {
row += std::format("{:>14} | {:<14}", "", "");
}
std::cout << row << std::endl;
}
std::cout << std::format("{:=^66}\n", "");
})
->build();
ep->connect("demo.dxfeed.com:7300");
static const OrderSource NTV
NASDAQ Total View.
Definition OrderSource.hpp:138
static std::shared_ptr< DXEndpoint > getInstance()
Returns a default application-wide singleton instance of DXEndpoint with a FEED role.
Definition DXEndpoint.cpp:426
static std::shared_ptr< Builder > newBuilder()
Creates a new builder instance for constructing a MarketDepthModel.
Definition MarketDepthModel.hpp:720
Template Parameters
OThe type of order derived from OrderBase.

Member Function Documentation

◆ getAggregationPeriod()

template<Derived< OrderBase > O>
std::int64_t MarketDepthModel< O >::getAggregationPeriod ( ) const
inline
Returns
The aggregation period of the book.

◆ getDepthLimit()

template<Derived< OrderBase > O>
std::size_t MarketDepthModel< O >::getDepthLimit ( ) const
inline
Returns
The depth limit of the book.

◆ newBuilder()

template<Derived< OrderBase > O>
static std::shared_ptr< Builder > MarketDepthModel< O >::newBuilder ( )
inlinestatic

Creates a new builder instance for constructing a MarketDepthModel.

Returns
A new instance of the builder.

◆ setAggregationPeriod() [1/2]

template<Derived< OrderBase > O>
void MarketDepthModel< O >::setAggregationPeriod ( std::chrono::milliseconds aggregationPeriod)
inline

Sets the aggregation period.

Parameters
aggregationPeriodThe new aggregation period value.

◆ setAggregationPeriod() [2/2]

template<Derived< OrderBase > O>
void MarketDepthModel< O >::setAggregationPeriod ( std::int64_t aggregationPeriodMillis)
inline

Sets the aggregation period in milliseconds.

Parameters
aggregationPeriodMillisThe new aggregation period value.

◆ setDepthLimit()

template<Derived< OrderBase > O>
void MarketDepthModel< O >::setDepthLimit ( std::size_t depthLimit)
inline

Sets the depth limit of the book.

Parameters
depthLimitThe new depth limit value.