-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
56 lines (42 loc) · 1.64 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
// Copyright (c) 2024 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0
#include <dxfeed_graal_cpp_api/api.hpp>
#include <chrono>
#include <iostream>
void fetchAndPrint(const dxfcpp::CandleSymbol &candleSymbol, std::int64_t toTime, std::int64_t fromTime) {
// Use default DXFeed instance for that data feed address is defined by dxfeed.properties file
auto result = dxfcpp::DXFeed::getInstance()
->getTimeSeriesPromise<dxfcpp::Candle>(candleSymbol, fromTime, toTime)
->await(std::chrono::seconds(5));
for (const auto &candle : result) {
std::cout << candle->toString() << "\n";
}
}
// Fetches last 20 days of candles for a specified symbol, prints them, and exits.
int main(int argc, char *argv[]) {
static const auto DAYS = 20;
using namespace dxfcpp;
using namespace std::string_literals;
try {
if (argc < 2) {
std::cout << R"(
Usage:
FetchDailyCandles <baseSymbol>
Where:
baseSymbol - Is security symbol (e.g. IBM, AAPL, SPX etc.)
)";
return 0;
}
// Specified instrument name, for example AAPL, IBM, MSFT, etc.
auto baseSymbol = argv[1];
auto candleSymbol = CandleSymbol::valueOf(baseSymbol, CandlePeriod::DAY);
auto toTime = dxfcpp::now();
auto fromTime = (std::chrono::milliseconds(toTime) - std::chrono::days(DAYS)).count();
std::cout << "Fetching last " << DAYS << " days of candles for " << baseSymbol << "\n";
fetchAndPrint(candleSymbol, toTime, fromTime);
} catch (const RuntimeException &e) {
std::cerr << e << '\n';
return 1;
}
return 0;
}