-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (61 loc) · 2.31 KB
/
main.cpp
File metadata and controls
80 lines (61 loc) · 2.31 KB
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
// Copyright (c) 2025 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0
#include <atomic>
#include <dxfeed_graal_cpp_api/api.hpp>
#include <iostream>
#include <mutex>
using namespace dxfcpp;
using namespace dxfcpp::literals;
using namespace std::literals;
void printUsage() {
const auto usageString = R"(
Usage:
FileParserSample <file> <type> <symbol>
Where:
file - Is a file name.
types - Is comma-separated list of dxfeed event types ()" +
enum_utils::getEventTypeEnumNamesList() + " or " +
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;
}
// Disable QD logging.
// Logging::init();
std::atomic<std::size_t> eventCounter{};
std::mutex ioMtx{};
// Parse args.
const std::string fileName = argv[1];
auto [parsedTypes, unknownTypes] = CmdArgsUtils::parseTypes(argv[2]);
const auto symbols = CmdArgsUtils::parseSymbols(argv[3]);
// Create an endpoint specifically for file parsing.
const auto endpoint = DXEndpoint::create(DXEndpoint::Role::STREAM_FEED);
const auto feed = endpoint->getFeed();
// Subscribe to a specified event and symbol.
const auto sub = feed->createSubscription(parsedTypes);
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 an endpoint to a file.
endpoint->connect("file:" + fileName + "[speed=max]");
// Wait until a file is completely parsed.
endpoint->awaitNotConnected();
// Close the endpoint when we're done.
// This method will gracefully close the endpoint, waiting while data processing completes.
endpoint->closeAndAwaitTermination();
} catch (const RuntimeException &e) {
std::cerr << e << '\n';
return 1;
}
return 0;
}