-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26a2794
commit 30d1ab6
Showing
3 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright (c) 2024 Devexperts LLC. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.21) | ||
|
||
if (POLICY CMP0092) | ||
cmake_policy(SET CMP0092 NEW) | ||
endif () | ||
|
||
if (POLICY CMP0135) | ||
cmake_policy(SET CMP0135 NEW) | ||
endif () | ||
|
||
project(PublishProfiles LANGUAGES CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_C_STANDARD 11) | ||
set(CXX_EXTENSIONS OFF) | ||
set(C_EXTENSIONS OFF) | ||
|
||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | ||
set(CMAKE_MACOSX_RPATH ON) | ||
set(CMAKE_SKIP_BUILD_RPATH ON) | ||
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) | ||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH OFF) | ||
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) | ||
set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path;@executable_path;@executable_path/../Frameworks") | ||
elseif (UNIX) | ||
set(CMAKE_SKIP_BUILD_RPATH ON) | ||
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) | ||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH OFF) | ||
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) | ||
set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/../lib64:$ORIGIN/../lib:$ORIGIN") | ||
endif () | ||
|
||
add_executable(${PROJECT_NAME} src/main.cpp) | ||
|
||
target_include_directories(${PROJECT_NAME} PRIVATE ../../../third_party/range-v3-0.12/include) | ||
|
||
target_link_libraries(${PROJECT_NAME} PRIVATE dxfcxx::static) | ||
|
||
if (DXFCXX_FEATURE_STACKTRACE) | ||
LinkStacktrace(${PROJECT_NAME}) | ||
endif () | ||
|
||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
$<TARGET_FILE:dxfcxx::graal> | ||
$<TARGET_FILE_DIR:${PROJECT_NAME}>) | ||
|
||
if (DXFCXX_INSTALL AND DXFCXX_INSTALL_SAMPLES) | ||
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
|
||
if (WIN32) | ||
install(FILES $<TARGET_FILE:dxfcxx::graal> DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
endif () | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright (c) 2024 Devexperts LLC. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
#include <dxfeed_graal_cpp_api/api.hpp> | ||
|
||
#include <atomic> | ||
#include <chrono> | ||
#include <mutex> | ||
#include <string> | ||
|
||
#include <range/v3/all.hpp> | ||
|
||
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; | ||
} | ||
|
||
/* | ||
* Using address like ":7700" it starts a server on a specified port where it provides Profile | ||
* event for any symbol ending with ":TEST" suffix. | ||
*/ | ||
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); | ||
|
||
// 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 JavaException &e) { | ||
std::cerr << e.what() << '\n'; | ||
std::cerr << e.getStackTrace() << '\n'; | ||
} catch (const GraalException &e) { | ||
std::cerr << e.what() << '\n'; | ||
std::cerr << e.getStackTrace() << '\n'; | ||
} | ||
|
||
return 0; | ||
} |