-
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.
[EN-7412] Implement DXFeedConnect sample
- Loading branch information
1 parent
cb6c947
commit 5da8d45
Showing
6 changed files
with
240 additions
and
28 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
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,81 @@ | ||
# Copyright (c) 2023 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(DxFeedConnect 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) | ||
|
||
if (DXFCXX_ENABLE_VS_ASAN) | ||
target_compile_options(${PROJECT_NAME} PRIVATE "/fsanitize=address") | ||
target_link_options(${PROJECT_NAME} PRIVATE "/fsanitize=address") | ||
|
||
target_compile_definitions(${PROJECT_NAME} | ||
PUBLIC | ||
$<$<COMPILE_LANG_AND_ID:CXX,MSVC>: | ||
_DISABLE_VECTOR_ANNOTATION | ||
_DISABLE_STRING_ANNOTATION | ||
> | ||
) | ||
endif () | ||
|
||
if (DXFCXX_ENABLE_ASAN_UBSAN) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE dxfcxx) | ||
target_compile_definitions(${PROJECT_NAME} PRIVATE DXFCPP_USE_DLLS) | ||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
$<TARGET_FILE:dxfcxx::graal> | ||
$<TARGET_FILE:dxfcxx> | ||
$<TARGET_FILE_DIR:${PROJECT_NAME}>) | ||
|
||
target_compile_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined") | ||
target_link_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined") | ||
else () | ||
target_link_libraries(${PROJECT_NAME} PRIVATE dxfcxx) | ||
target_compile_definitions(${PROJECT_NAME} PRIVATE DXFCPP_USE_DLLS) | ||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
$<TARGET_FILE:dxfcxx::graal> | ||
$<TARGET_FILE:dxfcxx> | ||
$<TARGET_FILE_DIR:${PROJECT_NAME}>) | ||
# target_link_libraries(${PROJECT_NAME} PRIVATE dxfcxx::static) | ||
# | ||
# add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
# $<TARGET_FILE:dxfcxx::graal> | ||
# $<TARGET_FILE_DIR:${PROJECT_NAME}>) | ||
endif () | ||
|
||
if (DXFCXX_INSTALL AND DXFCXX_INSTALL_SAMPLES) | ||
install(TARGETS ${PROJECT_NAME}) | ||
|
||
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,70 @@ | ||
// Copyright (c) 2023 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. | ||
type - Is comma-separated list of dxfeed event types ()" + | ||
dxfcpp::enum_utils::getEventTypeEnumNamesList() + R"(). | ||
symbol - 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[]) { | ||
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); | ||
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(); | ||
|
||
return 0; | ||
} |
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,52 @@ | ||
# Copyright (c) 2023 Devexperts LLC. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.21) | ||
|
||
project(dxFeedGraalCxxApi_Internal) | ||
|
||
if (POLICY CMP0092) | ||
cmake_policy(SET CMP0092 NEW) | ||
endif () | ||
|
||
if (POLICY CMP0135) | ||
cmake_policy(SET CMP0135 NEW) | ||
endif () | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_C_STANDARD 11) | ||
set(CMAKE_C_STANDARD_REQUIRED ON) | ||
set(CXX_EXTENSIONS OFF) | ||
set(C_EXTENSIONS OFF) | ||
|
||
set(dxFeedGraalCxxApi_Internal_Sources | ||
CEntryPointErrors.cpp | ||
Isolate.cpp | ||
JavaObjectHandler.cpp | ||
EventClassList.cpp | ||
SymbolList.cpp | ||
Common.cpp | ||
) | ||
|
||
set(dxFeedGraalCxxApi_Internal_Utils_Sources | ||
utils/StringUtils.cpp | ||
utils/EnumUtils.cpp | ||
utils/CmdArgsUtils.cpp | ||
) | ||
|
||
set(dxFeedGraalCxxApi_Internal_UtilsDebug_Sources | ||
utils/debug/Debug.cpp | ||
) | ||
|
||
|
||
add_library(dxFeedGraalCxxApi_Internal OBJECT | ||
${dxFeedGraalCxxApi_Internal_Sources} | ||
${dxFeedGraalCxxApi_Internal_Utils_Sources} | ||
${dxFeedGraalCxxApi_Internal_UtilsDebug_Sources} | ||
) | ||
|
||
add_library(dxfcxx::internal ALIAS dxFeedGraalCxxApi_Internal) | ||
|
||
target_include_directories(dxFeedGraalCxxApi_Internal PRIVATE ../../include ../../third_party/range-v3-0.12/include) | ||
target_link_libraries(dxFeedGraalCxxApi_Internal PRIVATE DxFeedGraalNativeSdk utf8cpp fmt::fmt-header-only) |
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 |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
#include <fmt/ostream.h> | ||
#include <fmt/std.h> | ||
|
||
#include <range/v3/all.hpp> | ||
|
||
|
||
namespace dxfcpp { | ||
|
||
|