Skip to content

Commit

Permalink
[EN-7412] Implement DXFeedConnect sample
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyKalin committed Sep 4, 2023
1 parent cb6c947 commit 5da8d45
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 28 deletions.
61 changes: 35 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,26 @@ add_subdirectory(third_party/fmt-10.0.0)
# find_package(utf8cpp)
# find_package(fmt)

set(dxFeedNativeAPIInternalSources
src/internal/CEntryPointErrors.cpp
src/internal/Isolate.cpp
src/internal/JavaObjectHandler.cpp
src/internal/EventClassList.cpp
src/internal/SymbolList.cpp
src/internal/Common.cpp
)

set(dxFeedNativeAPIInternalUtilsSources
src/internal/utils/StringUtils.cpp
src/internal/utils/EnumUtils.cpp
src/internal/utils/CmdArgsUtils.cpp
)

set(dxFeedNativeAPIInternalUtilsDebugSources
src/internal/utils/debug/Debug.cpp
)
#set(dxFeedNativeAPIInternalSources
# src/internal/CEntryPointErrors.cpp
# src/internal/Isolate.cpp
# src/internal/JavaObjectHandler.cpp
# src/internal/EventClassList.cpp
# src/internal/SymbolList.cpp
# src/internal/Common.cpp
#)
#
#set(dxFeedNativeAPIInternalUtilsSources
# src/internal/utils/StringUtils.cpp
# src/internal/utils/EnumUtils.cpp
# src/internal/utils/CmdArgsUtils.cpp
#)
#
#set(dxFeedNativeAPIInternalUtilsDebugSources
# src/internal/utils/debug/Debug.cpp
#)

add_subdirectory(src/internal)

set(dxFeedNativeAPIAPISources
src/api/DXEndpoint.cpp
Expand Down Expand Up @@ -208,9 +210,12 @@ elseif (UNIX)
endif ()

add_library(${PROJECT_NAME}_static STATIC
${dxFeedNativeAPIInternalSources}
${dxFeedNativeAPIInternalUtilsSources}
${dxFeedNativeAPIInternalUtilsDebugSources}
# ${dxFeedNativeAPIInternalSources}
# ${dxFeedNativeAPIInternalUtilsSources}
# ${dxFeedNativeAPIInternalUtilsDebugSources}

# $<TARGET_OBJECTS:dxFeedGraalCxxApi_Internal>

${dxFeedNativeAPIAPISources}
${dxFeedNativeAPIAPIOsubSources}
${dxFeedNativeAPISymbolsSources}
Expand All @@ -224,9 +229,12 @@ add_library(${PROJECT_NAME}_static STATIC
)

add_library(${PROJECT_NAME} SHARED
${dxFeedNativeAPIInternalSources}
${dxFeedNativeAPIInternalUtilsSources}
${dxFeedNativeAPIInternalUtilsDebugSources}
# ${dxFeedNativeAPIInternalSources}
# ${dxFeedNativeAPIInternalUtilsSources}
# ${dxFeedNativeAPIInternalUtilsDebugSources}

# $<TARGET_OBJECTS:dxFeedGraalCxxApi_Internal>

${dxFeedNativeAPIAPISources}
${dxFeedNativeAPIAPIOsubSources}
${dxFeedNativeAPISymbolsSources}
Expand Down Expand Up @@ -305,8 +313,8 @@ if (DXFCXX_USE_PRECOMPILED_HEADERS)
target_precompile_headers(${PROJECT_NAME}_static PRIVATE include/dxfeed_graal_cpp_api/internal/PrecompiledHeaders.hpp)
endif ()

target_link_libraries(${PROJECT_NAME}_static PUBLIC DxFeedGraalNativeSdk utf8cpp fmt::fmt-header-only)
target_link_libraries(${PROJECT_NAME} PUBLIC DxFeedGraalNativeSdk utf8cpp fmt::fmt-header-only)
target_link_libraries(${PROJECT_NAME}_static PUBLIC DxFeedGraalNativeSdk dxfcxx::internal utf8cpp fmt::fmt-header-only)
target_link_libraries(${PROJECT_NAME} PUBLIC DxFeedGraalNativeSdk dxfcxx::internal utf8cpp fmt::fmt-header-only)

if (DXFCXX_ENABLE_ASAN_UBSAN)
target_compile_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined")
Expand All @@ -330,6 +338,7 @@ if (DXFCXX_BUILD_SAMPLES)
add_subdirectory(samples/cpp/WriteTapeFile)
add_subdirectory(samples/cpp/ConvertTapeFile)
add_subdirectory(samples/cpp/DxFeedFileParser)
add_subdirectory(samples/cpp/DxFeedConnect)
endif ()

if (DXFCXX_BUILD_TOOLS)
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,8 @@ be downloaded from [Release](https://github.com/dxFeed/dxfeed-graal-cxx-api/rele
## Samples
* [ConvertTapeFile](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/ConvertTapeFile/src/main.cpp)
demonstrates how to convert one tape file to another tape file with optional intermediate processing or filtering
<!--
* [DxFeedConnect](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/DxFeedConnect/src/main.cpp)
demonstrates how to subscribe various market events for the specified symbols
-->
* [DxFeedFileParser](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/DxFeedFileParser/src/main.cpp)
is a simple demonstration of how events are read form a tape file
* [DxFeedSample](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/DxFeedSample/src/main.cpp)
Expand Down
81 changes: 81 additions & 0 deletions samples/cpp/DxFeedConnect/CMakeLists.txt
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 ()
70 changes: 70 additions & 0 deletions samples/cpp/DxFeedConnect/src/main.cpp
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;
}
52 changes: 52 additions & 0 deletions src/internal/CMakeLists.txt
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)
2 changes: 2 additions & 0 deletions src/internal/utils/CmdArgsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <fmt/ostream.h>
#include <fmt/std.h>

#include <range/v3/all.hpp>


namespace dxfcpp {

Expand Down

0 comments on commit 5da8d45

Please sign in to comment.