Represents a model for market depth, tracking buy and sell orders and notifies listener of changes in the order book.
More...
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)
->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
-