-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
102 lines (81 loc) · 3.15 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) 2024 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0
#include <dxfeed_graal_cpp_api/api.hpp>
#include <chrono>
#include <mutex>
#include <string>
DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()
using namespace dxfcpp;
using namespace dxfcpp::literals;
using namespace std::literals;
void printUsage() {
auto usageString = R"(
Usage:
DxFeedConnect <address> <types> <symbols> [<time>]
Where:
address - The address to connect to retrieve data (remote host or local tape file).
To pass an authorization token, add to the address: "[login=entitle:<token>]",
e.g.: demo.dxfeed.com:7300[login=entitle:<token>]
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").
for Candle event specify symbol with aggregation like in "AAPL{=d}"
time - Is from-time for history subscription in standard formats.
Same examples of valid from-time:
20070101-123456
20070101-123456.123
2005-12-31 21:00:00
2005-12-31 21:00:00.123+03:00
2005-12-31 21:00:00.123+0400
2007-11-02Z
123456789 - value-in-milliseconds
Examples:
DxFeedConnect demo.dxfeed.com:7300 Quote,Trade MSFT,IBM
DxFeedConnect demo.dxfeed.com:7300 TimeAndSale AAPL
DxFeedConnect demo.dxfeed.com:7300 Candle AAPL{=d} 20230901Z)";
std::cout << usageString << std::endl;
}
int main(int argc, char *argv[]) {
try {
if (argc < 4) {
printUsage();
return 0;
}
std::mutex ioMtx{};
// Parse args.
std::string address = argv[1];
auto types = CmdArgsUtils::parseTypes(argv[2]);
auto symbols = CmdArgsUtils::parseSymbols(argv[3]);
auto time = -1LL;
if (argc >= 5) {
time = TimeFormat::DEFAULT_WITH_MILLIS_WITH_TIMEZONE.parse(argv[4]);
}
// Create an endpoint and connect to specified address.
auto endpoint = DXEndpoint::create()->connect(address);
// Create a subscription with specified types attached to feed.
auto sub = endpoint->getFeed()->createSubscription(types.first);
// Add an event listener.
sub->addEventListener([&ioMtx](const auto &events) {
std::lock_guard lock{ioMtx};
for (auto &&e : events) {
std::cout << e << "\n";
}
});
// Add symbols.
if (time != -1) {
sub->addSymbols(symbols | ranges::views::transform([time](const auto &s) {
return TimeSeriesSubscriptionSymbol(s, time);
}));
} else {
sub->addSymbols(symbols);
}
std::cin.get();
} catch (const RuntimeException &e) {
std::cerr << e << '\n';
return 1;
}
return 0;
}