-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
77 lines (58 loc) · 2.18 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
// Copyright (c) 2024 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0
#include <dxfeed_graal_cpp_api/api.hpp>
#include <atomic>
#include <mutex>
using namespace dxfcpp;
using namespace dxfcpp::literals;
using namespace std::literals;
void printUsage() {
auto usageString = R"(
Usage:
DxFeedFileParser <file> <type> <symbol>
Where:
file - Is a file name.
types - Is comma-separated list of dxfeed event types ()" +
dxfcpp::enum_utils::getEventTypeEnumNamesList() + " or " +
dxfcpp::enum_utils::getEventTypeEnumClassNamesList() + R"().
symbols - Is comma-separated list of symbol names to get events for (e.g. "IBM,AAPL,MSFT").)";
std::cout << usageString << std::endl;
}
int main(int argc, char *argv[]) {
try {
if (argc < 4) {
printUsage();
return 0;
}
std::atomic<std::size_t> eventCounter{};
std::mutex ioMtx{};
// Parse args.
std::string fileName = argv[1];
auto types = CmdArgsUtils::parseTypes(argv[2]);
auto symbols = CmdArgsUtils::parseSymbols(argv[3]);
// Create endpoint specifically for file parsing.
auto endpoint = DXEndpoint::create(DXEndpoint::Role::STREAM_FEED);
auto feed = endpoint->getFeed();
// Subscribe to a specified event and symbol.
auto sub = feed->createSubscription(types.first);
sub->addEventListener([&eventCounter, &ioMtx](const auto &events) {
std::lock_guard lock{ioMtx};
for (auto &&e : events) {
std::cout << (++eventCounter) << ": " << e << "\n";
}
});
// Add symbols.
sub->addSymbols(symbols);
// Connect endpoint to a file.
endpoint->connect("file:" + fileName + "[speed=max]");
// Wait until file is completely parsed.
endpoint->awaitNotConnected();
// Close endpoint when we're done.
// This method will gracefully close endpoint, waiting while data processing completes.
endpoint->closeAndAwaitTermination();
} catch (const RuntimeException &e) {
std::cerr << e << '\n';
return 1;
}
return 0;
}