-
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-7411] Implement ConvertTapeFile sample
- Loading branch information
1 parent
99e72d9
commit c289f02
Showing
7 changed files
with
200 additions
and
1 deletion.
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
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(ConvertTapeFile 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 () | ||
|
||
target_include_directories(${PROJECT_NAME} PRIVATE ../../../include) | ||
|
||
if (DXFCXX_ENABLE_ASAN_UBSAN) | ||
target_compile_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined" "-fPIC") | ||
target_link_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined" "-fPIC") | ||
|
||
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> | ||
${CMAKE_CURRENT_SOURCE_DIR}/ConvertTapeFile.in | ||
$<TARGET_FILE:dxfcxx> | ||
$<TARGET_FILE_DIR:${PROJECT_NAME}>) | ||
else () | ||
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> | ||
${CMAKE_CURRENT_SOURCE_DIR}/ConvertTapeFile.in | ||
$<TARGET_FILE_DIR:${PROJECT_NAME}>) | ||
endif () | ||
|
||
if (DXFCXX_INSTALL AND DXFCXX_INSTALL_SAMPLES) | ||
install(TARGETS ${PROJECT_NAME}) | ||
install(FILES "ConvertTapeFile.in" 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,23 @@ | ||
==DXP3 type=tape version=QDS-3.315 time=field +STREAM_DATA | ||
==STREAM_DATA | ||
=Quote EventSymbol EventTime BidTime BidExchangeCode BidPrice BidSize AskTime AskExchangeCode AskPrice AskSize | ||
Quote AAPL 20230216-180402.785+0300 20230216-180402+0300 Q 153.94 2 20230216-180402+0300 Q 153.95 1 | ||
Quote AAPL 20230216-180402.805+0300 20230216-180402+0300 Q 153.94 2 20230216-180402+0300 Z 153.96 2 | ||
Quote AAPL 20230216-180402.871+0300 20230216-180402+0300 Q 153.94 2 20230216-180402+0300 Q 153.95 1 | ||
Quote AAPL 20230216-180402.878+0300 20230216-180402+0300 Q 153.94 2 20230216-180402+0300 Q 153.96 3 | ||
Quote AAPL 20230216-180402.922+0300 20230216-180402+0300 P 153.94 2 20230216-180402+0300 Q 153.96 4 | ||
Quote AAPL 20230216-180402.945+0300 20230216-180402+0300 P 153.94 2 20230216-180402+0300 Q 153.96 3 | ||
Quote AAPL 20230216-180402.954+0300 20230216-180402+0300 P 153.94 2 20230216-180402+0300 Q 153.96 2 | ||
Quote AAPL 20230216-180402.969+0300 20230216-180402+0300 P 153.94 2 20230216-180402+0300 Q 153.96 3 | ||
Quote AAPL 20230216-180402.989+0300 20230216-180402+0300 P 153.94 2 20230216-180402+0300 Q 153.95 1 | ||
Quote AAPL 20230216-180403.005+0300 20230216-180402+0300 P 153.94 2 20230216-180403+0300 Q 153.96 3 | ||
Quote AAPL 20230216-180403.010+0300 20230216-180402+0300 P 153.94 2 20230216-180403+0300 Q 153.96 4 | ||
Quote AAPL 20230216-180403.121+0300 20230216-180402+0300 P 153.94 2 20230216-180403+0300 Q 153.96 3 | ||
Quote AAPL 20230216-180403.149+0300 20230216-180402+0300 P 153.94 2 20230216-180403+0300 Q 153.95 1 | ||
Quote AAPL 20230216-180403.182+0300 20230216-180402+0300 P 153.94 2 20230216-180403+0300 Q 153.96 3 | ||
Quote AAPL 20230216-180403.245+0300 20230216-180402+0300 P 153.94 2 20230216-180403+0300 Q 153.96 4 | ||
Quote AAPL 20230216-180403.309+0300 20230216-180402+0300 P 153.94 2 20230216-180403+0300 Q 153.95 1 | ||
Quote AAPL 20230216-180403.353+0300 20230216-180402+0300 P 153.94 2 20230216-180403+0300 Z 153.96 3 | ||
Quote AAPL 20230216-180403.507+0300 20230216-180403+0300 Q 153.94 2 20230216-180403+0300 Q 153.96 3 | ||
Quote AAPL 20230216-180403.516+0300 20230216-180403+0300 Q 153.95 1 20230216-180403+0300 Z 153.96 1 | ||
Quote AAPL 20230216-180403.523+0300 20230216-180403+0300 Q 153.95 1 20230216-180403+0300 Q 153.96 1 |
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,72 @@ | ||
// Copyright (c) 2023 Devexperts LLC. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
#include <dxfeed_graal_cpp_api/api.hpp> | ||
|
||
using namespace dxfcpp; | ||
using namespace dxfcpp::literals; | ||
using namespace std::literals; | ||
|
||
/** | ||
* Converts one tape file into another tape file with optional intermediate processing or filtering. | ||
* This project contains sample tape file ConvertTapeFile.in. | ||
*/ | ||
int main(int argc, char *argv[]) { | ||
// Determine input and output tapes and specify appropriate configuration parameters. | ||
std::string inputAddress = argc > 1 ? argv[0] : "file:ConvertTapeFile.in[readAs=stream_data,speed=max]"; | ||
std::string outputAddress = argc > 2 ? argv[1] : "tape:ConvertTapeFile.out[saveAs=stream_data,format=text]"; | ||
|
||
// Create input endpoint configured for tape reading. | ||
auto inputEndpoint = | ||
DXEndpoint::newBuilder() | ||
->withRole(DXEndpoint::Role::STREAM_FEED) // Prevents event conflation and loss due to buffer overflow. | ||
->withProperty(DXEndpoint::DXFEED_WILDCARD_ENABLE_PROPERTY, "true") // Enables wildcard subscription. | ||
->withProperty(DXEndpoint::DXENDPOINT_EVENT_TIME_PROPERTY, "true") // Use provided event times. | ||
->build(); | ||
|
||
// Create output endpoint configured for tape writing. | ||
auto outputEndpoint = | ||
DXEndpoint::newBuilder() | ||
->withRole(DXEndpoint::Role::STREAM_PUBLISHER) // Prevents event conflation and loss due to buffer overflow. | ||
->withProperty(DXEndpoint::DXFEED_WILDCARD_ENABLE_PROPERTY, "true") // Enables wildcard subscription. | ||
->withProperty(DXEndpoint::DXENDPOINT_EVENT_TIME_PROPERTY, "true") // Use provided event times. | ||
->build(); | ||
|
||
// Create and link event processor for all types of events. | ||
// Note: Set of processed event types could be limited if needed. | ||
auto sub = inputEndpoint->getFeed()->createSubscription(EventTypeEnum::ALL); | ||
|
||
sub->addEventListener([outputEndpoint](auto events) { | ||
// Here event processing occurs. Events could be modified, removed, or new events added. | ||
// For example, the below code adds 1 hour to event times: | ||
// for (auto &e : events) { | ||
// if (auto event = e->template sharedAs<EventType>(); event) { | ||
// event->setEventTime(event->getEventTime() + 3600'000); | ||
// } | ||
// } | ||
|
||
// Publish processed events | ||
auto publisher = outputEndpoint->getPublisher(); | ||
|
||
publisher->publishEvents(events); | ||
}); | ||
|
||
// Subscribe to all symbols. | ||
// Note: Set of processed symbols could be limited if needed. | ||
sub->addSymbols(WildcardSymbol::ALL); | ||
|
||
// Connect output endpoint and start output tape writing BEFORE starting input tape reading. | ||
outputEndpoint->connect(outputAddress); | ||
// Connect input endpoint and start input tape reading AFTER starting output tape writing. | ||
inputEndpoint->connect(inputAddress); | ||
|
||
// Wait until all data is read and processed, and then gracefully close input endpoint. | ||
inputEndpoint->awaitNotConnected(); | ||
inputEndpoint->closeAndAwaitTermination(); | ||
|
||
// Wait until all data is processed and written, and then gracefully close output endpoint. | ||
outputEndpoint->awaitProcessed(); | ||
outputEndpoint->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