Skip to content

Commit

Permalink
EN-7588: a project skeleton.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyKalin committed Apr 22, 2024
1 parent 26a2794 commit 30d1ab6
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ endif ()

if (DXFCXX_BUILD_SAMPLES)
add_subdirectory(samples/cpp/PrintQuoteEvents)
add_subdirectory(samples/cpp/PublishProfiles)
add_subdirectory(samples/cpp/DxFeedSample)
add_subdirectory(samples/cpp/WriteTapeFile)
add_subdirectory(samples/cpp/ConvertTapeFile)
Expand Down
56 changes: 56 additions & 0 deletions samples/cpp/PublishProfiles/CMakeLists.txt
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 ()
107 changes: 107 additions & 0 deletions samples/cpp/PublishProfiles/src/main.cpp
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;
}

0 comments on commit 30d1ab6

Please sign in to comment.