Skip to content

Commit

Permalink
[EN-7412] Implement DxFeedConnect sample (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyKalin authored Sep 6, 2023
1 parent 559056d commit b6cb0d8
Show file tree
Hide file tree
Showing 156 changed files with 40,359 additions and 94 deletions.
80 changes: 41 additions & 39 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ if (POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif ()

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

project(dxFeedGraalCxxApi)

set(DXFCXX_VERSION "0.1.4" CACHE STRING "The dxFeed Graal CXX API package version")
Expand Down Expand Up @@ -89,11 +91,14 @@ FetchContent_MakeAvailable(DxFeedGraalNativeSdk)
add_subdirectory(third_party/utfcpp-3.2.3)
set(FMT_INSTALL OFF)
add_subdirectory(third_party/fmt-10.0.0)
#set(BUILD_TZ_LIB ON)
#set(USE_SYSTEM_TZ_DB ON)
add_subdirectory(third_party/date-3.0.1)

# find_package(utf8cpp)
# find_package(fmt)

set(dxFeedNativeAPIInternalSources
set(dxFeedGraalCxxApi_Internal_Sources
src/internal/CEntryPointErrors.cpp
src/internal/Isolate.cpp
src/internal/JavaObjectHandler.cpp
Expand All @@ -102,46 +107,48 @@ set(dxFeedNativeAPIInternalSources
src/internal/Common.cpp
)

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

set(dxFeedNativeAPIInternalUtilsDebugSources
set(dxFeedGraalCxxApi_InternalUtilsDebug_Sources
src/internal/utils/debug/Debug.cpp
)

set(dxFeedNativeAPIAPISources
set(dxFeedGraalCxxApi_API_Sources
src/api/DXEndpoint.cpp
src/api/DXFeed.cpp
src/api/DXFeedSubscription.cpp
src/api/DXPublisher.cpp
)

set(dxFeedNativeAPIAPIOsubSources
set(dxFeedGraalCxxApi_APIOsub_Sources
src/api/osub/WildcardSymbol.cpp
src/api/osub/TimeSeriesSubscriptionSymbol.cpp
src/api/osub/IndexedEventSubscriptionSymbol.cpp
)

set(dxFeedNativeAPISymbolsSources
set(dxFeedGraalCxxApi_Symbols_Sources
src/symbols/StringSymbol.cpp
src/symbols/SymbolWrapper.cpp
)

set(dxFeedNativeAPISystemSources
set(dxFeedGraalCxxApi_System_Sources
src/system/System.cpp
)

set(dxFeedNativeAPIEventSources
set(dxFeedGraalCxxApi_Event_Sources
src/event/EventTypeEnum.cpp
src/event/IndexedEventSource.cpp
src/event/EventFlag.cpp
src/event/IndexedEvent.cpp
src/event/EventMapper.cpp
)

set(dxFeedNativeAPIEventCandleSources
set(dxFeedGraalCxxApi_EventCandle_Sources
src/event/candle/Candle.cpp
src/event/candle/CandleAlignment.cpp
src/event/candle/CandleExchange.cpp
Expand All @@ -153,7 +160,7 @@ set(dxFeedNativeAPIEventCandleSources
src/event/candle/CandleSymbol.cpp
)

set(dxFeedNativeAPIEventMarketSources
set(dxFeedGraalCxxApi_EventMarket_Sources
src/event/market/AnalyticOrder.cpp
src/event/market/Direction.cpp
src/event/market/IcebergType.cpp
Expand All @@ -179,18 +186,34 @@ set(dxFeedNativeAPIEventMarketSources
src/event/market/TradingStatus.cpp
)

set(dxFeedNativeAPIEventOptionSources
set(dxFeedGraalCxxApi_EventOption_Sources
src/event/option/Greeks.cpp
src/event/option/Underlying.cpp
src/event/option/TheoPrice.cpp
src/event/option/Series.cpp
)

set(dxFeedNativeAPIScheduleSources
set(dxFeedGraalCxxApi_Schedule_Sources
src/schedule/SessionFilter.cpp
src/schedule/SessionType.cpp
)

set(dxFeedGraalCxxApi_Sources
${dxFeedGraalCxxApi_Internal_Sources}
${dxFeedGraalCxxApi_InternalUtils_Sources}
${dxFeedGraalCxxApi_InternalUtilsDebug_Sources}
${dxFeedGraalCxxApi_API_Sources}
${dxFeedGraalCxxApi_APIOsub_Sources}
${dxFeedGraalCxxApi_Symbols_Sources}
${dxFeedGraalCxxApi_System_Sources}
${dxFeedGraalCxxApi_Event_Sources}
${dxFeedGraalCxxApi_EventCandle_Sources}
${dxFeedGraalCxxApi_EventMarket_Sources}
${dxFeedGraalCxxApi_EventOption_Sources}
${dxFeedGraalCxxApi_EventOption_Sources}
${dxFeedGraalCxxApi_Schedule_Sources}
)

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_SKIP_BUILD_RPATH ON)
Expand All @@ -207,34 +230,12 @@ elseif (UNIX)
endif ()

add_library(${PROJECT_NAME}_static STATIC
${dxFeedNativeAPIInternalSources}
${dxFeedNativeAPIInternalUtilsSources}
${dxFeedNativeAPIInternalUtilsDebugSources}
${dxFeedNativeAPIAPISources}
${dxFeedNativeAPIAPIOsubSources}
${dxFeedNativeAPISymbolsSources}
${dxFeedNativeAPISystemSources}
${dxFeedNativeAPIEventSources}
${dxFeedNativeAPIEventCandleSources}
${dxFeedNativeAPIEventMarketSources}
${dxFeedNativeAPIEventOptionSources}
${dxFeedNativeAPIScheduleSources}
${dxFeedGraalCxxApi_Sources}
src/api.cpp
)

add_library(${PROJECT_NAME} SHARED
${dxFeedNativeAPIInternalSources}
${dxFeedNativeAPIInternalUtilsSources}
${dxFeedNativeAPIInternalUtilsDebugSources}
${dxFeedNativeAPIAPISources}
${dxFeedNativeAPIAPIOsubSources}
${dxFeedNativeAPISymbolsSources}
${dxFeedNativeAPISystemSources}
${dxFeedNativeAPIEventSources}
${dxFeedNativeAPIEventCandleSources}
${dxFeedNativeAPIEventMarketSources}
${dxFeedNativeAPIEventOptionSources}
${dxFeedNativeAPIScheduleSources}
${dxFeedGraalCxxApi_Sources}
src/api.cpp
)

Expand Down Expand Up @@ -304,8 +305,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 utf8cpp fmt::fmt-header-only date::date)
target_link_libraries(${PROJECT_NAME} PUBLIC DxFeedGraalNativeSdk utf8cpp fmt::fmt-header-only date::date)

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

if (DXFCXX_BUILD_TOOLS)
Expand Down
3 changes: 2 additions & 1 deletion DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
- [utfcpp](https://github.com/nemtrif/utfcpp) v3.2.3
- [fmt](https://github.com/fmtlib/fmt) v10.0.0
- [doctest](https://github.com/doctest/doctest) v2.4.11 (Tests)
- [range-v3](https://github.com/ericniebler/range-v3) v0.12 (Code & Samples)
- [range-v3](https://github.com/ericniebler/range-v3) v0.12
- [date] (https://github.com/HowardHinnant/date) v3.0.1

## Run-time

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,9 @@ 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)
* [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)
is a simple demonstration of how to create multiple event listeners and subscribe to `Quote` and `Trade` events
Expand Down
5 changes: 4 additions & 1 deletion THIRD_PARTY_LICENSES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
3. doctest - https://github.com/doctest/doctest/blob/master/LICENSE.txt
SPDX-License-Identifier: MIT
4. range-v3 - https://github.com/ericniebler/range-v3/blob/master/LICENSE.txt
SPDX-License-Identifier: BSL-1.0
SPDX-License-Identifier: BSL-1.0
5. date - https://github.com/HowardHinnant/date/blob/master/LICENSE.txt
SPDX-License-Identifier: MIT

2 changes: 2 additions & 0 deletions include/dxfeed_graal_cpp_api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "internal/managers/ErrorHandlingManager.hpp"
#include "internal/utils/StringUtils.hpp"
#include "internal/utils/CmdArgsUtils.hpp"
#include "internal/utils/EnumUtils.hpp"
#include "internal/utils/TimeFormat.hpp"
#include "internal/utils/debug/Debug.hpp"

#include "api/ApiModule.hpp"
Expand Down
22 changes: 17 additions & 5 deletions include/dxfeed_graal_cpp_api/event/EventTypeEnum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class DXFCPP_EXPORT EventTypeEnum {

const std::string name_;

const std::string className_;

// A flag that indicates that the current enum element is characterizing the Lasting (TICKER) event.
const bool isLasting_;

Expand All @@ -34,10 +36,11 @@ class DXFCPP_EXPORT EventTypeEnum {
// TimeSeries) event.
const bool isOnlyIndexed_;

EventTypeEnum(std::uint32_t id, std::string name, bool isLasting, bool isIndexed = false,
EventTypeEnum(std::uint32_t id, std::string name, std::string className, bool isLasting, bool isIndexed = false,
bool isTimeSeries = false) noexcept
: id_{id}, name_{std::move(name)}, isLasting_{isLasting}, isIndexed_{isIndexed || isTimeSeries},
isTimeSeries_{isTimeSeries}, isOnlyIndexed_{isIndexed && !isTimeSeries} {
: id_{id}, name_{std::move(name)}, className_{std::move(className)}, isLasting_{isLasting},
isIndexed_{isIndexed || isTimeSeries}, isTimeSeries_{isTimeSeries},
isOnlyIndexed_{isIndexed && !isTimeSeries} {
}

public:
Expand Down Expand Up @@ -69,7 +72,9 @@ class DXFCPP_EXPORT EventTypeEnum {

static const std::unordered_map<std::string, std::reference_wrapper<const EventTypeEnum>> ALL_BY_NAME;

explicit EventTypeEnum() noexcept : EventTypeEnum{static_cast<std::uint32_t>(-1), "INVALID", false} {
static const std::unordered_map<std::string, std::reference_wrapper<const EventTypeEnum>> ALL_BY_CLASS_NAME;

explicit EventTypeEnum() noexcept : EventTypeEnum{static_cast<std::uint32_t>(-1), "INVALID", "Invalid", false} {
}

/**
Expand All @@ -82,10 +87,17 @@ class DXFCPP_EXPORT EventTypeEnum {
/**
* @return The current enum element name
*/
const std::string &getName() const noexcept {
const std::string &getName() const & noexcept {
return name_;
}

/**
* @return The current enum element class name
*/
const std::string &getClassName() const & noexcept {
return className_;
}

bool operator==(const EventTypeEnum &eventTypeEnum) const noexcept {
return id_ == eventTypeEnum.id_;
}
Expand Down
8 changes: 8 additions & 0 deletions include/dxfeed_graal_cpp_api/internal/utils/CmdArgsUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ struct DXFCPP_EXPORT CmdArgsUtils final {
*/
static std::unordered_set<std::reference_wrapper<const EventTypeEnum>> parseTypes(const std::string &types);
};

/**
* Parses Date+Time string and converts to timestamp
*
* @param string Date+Time string
* @return UTC timestamp
*/
DXFCPP_EXPORT std::int64_t parseDateTime(const std::string& string);
} // namespace dxfcpp
29 changes: 29 additions & 0 deletions include/dxfeed_graal_cpp_api/internal/utils/EnumUtils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2023 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0

#pragma once

#include "../Conf.hpp"

#include <string>

namespace dxfcpp::enum_utils {

/**
* Returns a separated list of names of EventTypeEnum elements (CANDLE, QUOTE, TIME_AND_SALE etc).
*
* @param separator The list separator
* @return A separated list of names
*/
DXFCPP_EXPORT std::string getEventTypeEnumNamesList(std::string separator = std::string(",")) noexcept;

/**
* Returns a separated list of class names of EventTypeEnum elements (Candle, Quote, TimeAndSale etc).
*
* @param separator The list separator
* @return A separated list of class names
*/
DXFCPP_EXPORT std::string getEventTypeEnumClassNamesList(std::string separator = std::string(",")) noexcept;

}

Loading

0 comments on commit b6cb0d8

Please sign in to comment.