-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
85 lines (64 loc) · 2.74 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2024 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0
#include <dxfeed_graal_cpp_api/api.hpp>
#include <chrono>
#include <mutex>
#include <string>
#include <fmt/format.h>
#include "PriceLevel.hpp"
#include "PriceLevelBook.hpp"
using namespace dxfcpp;
using namespace dxfcpp::literals;
using namespace std::literals;
int main(int /*argc*/, char * /*argv*/[]) {
try {
const auto address = "demo.dxfeed.com:7300";
// Disable QD logging.
// Logging::init();
auto symbol = "MSFT";
auto source = OrderSource::NTV;
auto book =
PriceLevelBook<Order>::newBuilder()
->withFeed(DXFeed::getInstance())
->withSymbol(symbol)
->withSource(source)
->withDepthLimit(10)
->withAggregationPeriod(10s)
->withListener([](const std::vector<std::shared_ptr<PriceLevel>> &buyLevels,
const std::vector<std::shared_ptr<PriceLevel>> &sellLevels) {
if (buyLevels.empty() && sellLevels.empty()) {
return;
}
std::cout << fmt::format("{:=^66}\n", "");
std::cout << fmt::format("{:^31} || {:^31}\n", "ASK", "BID");
std::cout << fmt::format("{0:^15}|{1:^15} || {0:^15}|{1:^15}\n", "Price", "Size");
std::cout << fmt::format("{:-^66}\n", "");
for (auto buyIt = buyLevels.begin(), sellIt = sellLevels.begin();
buyIt != buyLevels.end() || sellIt != sellLevels.end();) {
std::string row{};
if (buyIt != buyLevels.end()) {
row += fmt::format("{:>14.4f} | {:<14.2f}", (*buyIt)->getPrice(), (*buyIt)->getSize());
++buyIt;
} else {
row += fmt::format("{:>14} | {:<14}", "", "");
}
row += " || ";
if (sellIt != sellLevels.end()) {
row += fmt::format("{:>14.4f} | {:<14.2f}", (*sellIt)->getPrice(), (*sellIt)->getSize());
++sellIt;
} else {
row += fmt::format("{:>14} | {:<14}", "", "");
}
std::cout << row << std::endl;
}
std::cout << fmt::format("{:=^66}\n", "");
})
->build();
DXEndpoint::getInstance()->connect(address);
std::cin.get();
} catch (const RuntimeException &e) {
std::cerr << e << '\n';
return 1;
}
return 0;
}