Skip to content

[MDAPI-30] [C++] Add LastEventsConsole sample #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false
IndentAccessModifiers: false
AccessModifierOffset: 0

42 changes: 42 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2025 Devexperts LLC.
# SPDX-License-Identifier: MPL-2.0
root = true

[*]
charset = utf-8
indent_style = space
tab_width = 4
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 120

[*.{h,c,cpp,hpp}]
cpp_keep_blank_lines_in_declarations = 1
cpp_remove_blank_lines_near_braces_in_declarations = true
cpp_remove_blank_lines_near_braces_in_code = true
cpp_blank_lines_around_class_definition = 1
cpp_blank_lines_around_function_declaration = 1
cpp_blank_lines_around_function_declaration = 1
cpp_blank_lines_around_other_declaration = 0
cpp_blank_lines_before_access_specifier = 1
cpp_blank_lines_after_access_specifier = 0
cpp_brace_style = end_of_line
cpp_requires_expression_braces = end_of_line
cpp_simple_block_style = line_break
cpp_continuous_line_indent = single

[*.{yml,yaml}]
indent_size = 2

[*.{md,mdx}]
trim_trailing_whitespace = false

[*.{cmd,bat}]
end_of_line = crlf

[*.sh]
end_of_line = lf

[*.{json,json5,webmanifest}]
indent_size = 2
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ if (DXFCXX_BUILD_SAMPLES)
add_subdirectory(samples/cpp/PriceLevelBookSample)
add_subdirectory(samples/cpp/MarketDepthModelSample)
add_subdirectory(samples/cpp/OptionChainSample)
add_subdirectory(samples/cpp/Console/LastEventConsoleSample)
endif ()

add_subdirectory(docs)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Only x64 versions are supported.

### Linux

Only x64 versions are supported.
Only x64 versions are prebuilt.

#### libc compatibility

Expand Down Expand Up @@ -351,7 +351,7 @@ be downloaded from [Release](https://github.com/dxFeed/dxfeed-graal-cxx-api/rele

### Console

- [ ] [LastEventConsoleSample](samples/cpp/LastEventConsoleSample/src/main.cpp)
- [x] [LastEventConsoleSample](samples/cpp/Console/LastEventConsoleSample/src/main.cpp)
demonstrates how to subscribe to various market events with the dxFeed API, cache them in memory, and
take snapshots of these events based on user input

Expand Down Expand Up @@ -583,4 +583,4 @@ be downloaded from [Release](https://github.com/dxFeed/dxfeed-graal-cxx-api/rele
- [ ] dxFeed Graal C API
- [x] dxFeed Graal C++ API

<!-- 2024-11-21 20:25 -->
<!-- 2024-11-21 20:25 -->
1 change: 1 addition & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* **\[MDAPI-30]\[C++]** Added LastEventsConsole sample
* **\[MDAPI-27]\[C++]** Implemented OptionChain
* Added `OptionChain` class.
* Added `OptionSeries` class.
Expand Down
34 changes: 17 additions & 17 deletions include/dxfeed_graal_cpp_api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251 4996)
#include "internal/Common.hpp"
#include "internal/Enum.hpp"
#include "internal/EventClassList.hpp"
#include "internal/Handler.hpp"
#include "internal/Id.hpp"
#include "internal/Isolate.hpp"
#include "internal/JavaObjectHandle.hpp"
#include "internal/NonCopyable.hpp"
#include "internal/Platform.hpp"
#include "internal/RawListWrapper.hpp"
#include "internal/StopWatch.hpp"
#include "internal/Timer.hpp"
#include "internal/TimeFormat.hpp"
#include "internal/Handler.hpp"
#include "internal/Timer.hpp"

#include "internal/context/ApiContext.hpp"

Expand All @@ -42,53 +42,53 @@ DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251 4996)

#include "api/ApiModule.hpp"
#include "auth/AuthToken.hpp"
#include "ipf/IpfModule.hpp"
#include "entity/EntityModule.hpp"
#include "event/EventModule.hpp"
#include "ipf/IpfModule.hpp"
#include "model/IndexedTxModel.hpp"
#include "model/MarketDepthModel.hpp"
#include "model/MarketDepthModelListener.hpp"
#include "model/TimeSeriesTxModel.hpp"
#include "model/TxModelListener.hpp"
#include "schedule/ScheduleModule.hpp"
#include "symbols/StringSymbol.hpp"
#include "symbols/SymbolWrapper.hpp"
#include "system/System.hpp"
#include "model/TxModelListener.hpp"
#include "model/IndexedTxModel.hpp"
#include "model/TimeSeriesTxModel.hpp"
#include "model/MarketDepthModelListener.hpp"
#include "model/MarketDepthModel.hpp"

#include "exceptions/RuntimeException.hpp"
#include "exceptions/GraalException.hpp"
#include "exceptions/InvalidArgumentException.hpp"
#include "exceptions/JavaException.hpp"
#include "exceptions/GraalException.hpp"
#include "exceptions/RuntimeException.hpp"

#include "executors/InPlaceExecutor.hpp"

#include "isolated/api/IsolatedDXFeed.hpp"
#include "isolated/api/IsolatedDXEndpoint.hpp"
#include "isolated/api/IsolatedDXFeed.hpp"
#include "isolated/api/IsolatedDXFeedSubscription.hpp"
#include "isolated/api/IsolatedDXPublisher.hpp"
#include "isolated/api/IsolatedDXPublisherObservableSubscription.hpp"
#include "isolated/api/osub/IsolatedObservableSubscriptionChangeListener.hpp"
#include "isolated/auth/IsolatedAuthToken.hpp"
#include "isolated/event/IsolatedEventType.hpp"
#include "isolated/executors/IsolatedInPlaceExecutor.hpp"
#include "isolated/promise/IsolatedPromise.hpp"
#include "isolated/internal/IsolatedString.hpp"
#include "isolated/internal/IsolatedObject.hpp"
#include "isolated/internal/IsolatedString.hpp"
#include "isolated/internal/IsolatedTimeFormat.hpp"
#include "isolated/internal/IsolatedTools.hpp"
#include "isolated/ipf/IsolatedInstrumentProfile.hpp"
#include "isolated/ipf/IsolatedInstrumentProfileReader.hpp"
#include "isolated/ipf/live/IsolatedInstrumentProfileCollector.hpp"
#include "isolated/ipf/live/IsolatedInstrumentProfileConnection.hpp"
#include "isolated/ipf/IsolatedInstrumentProfileReader.hpp"
#include "isolated/logging/IsolatedLogging.hpp"
#include "isolated/model/IsolatedTxModelListener.hpp"
#include "isolated/model/IsolatedIndexedTxModel.hpp"
#include "isolated/model/IsolatedTimeSeriesTxModel.hpp"
#include "isolated/model/IsolatedTxModelListener.hpp"
#include "isolated/ondemand/IsolatedOnDemandService.hpp"
#include "isolated/util/IsolatedTimePeriod.hpp"
#include "isolated/promise/IsolatedPromise.hpp"
#include "isolated/schedule/IsolatedDay.hpp"
#include "isolated/schedule/IsolatedSession.hpp"
#include "isolated/schedule/IsolatedSchedule.hpp"
#include "isolated/schedule/IsolatedSession.hpp"
#include "isolated/util/IsolatedTimePeriod.hpp"

#include "logging/Logging.hpp"

Expand Down
2 changes: 1 addition & 1 deletion include/dxfeed_graal_cpp_api/api/ApiModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251)
#include "DXEndpoint.hpp"
#include "DXFeed.hpp"
#include "DXFeedSubscription.hpp"
#include "DXPublisherObservableSubscription.hpp"
#include "DXPublisher.hpp"
#include "DXPublisherObservableSubscription.hpp"
#include "FilteredSubscriptionSymbol.hpp"
#include "osub/OsubModule.hpp"

Expand Down
6 changes: 3 additions & 3 deletions include/dxfeed_graal_cpp_api/api/DXEndpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ struct DXFCPP_EXPORT DXEndpoint : public RequireMakeShared<DXEndpoint> {

static std::string stateToString(State state);

private:
private:
JavaObjectHandle<DXEndpoint> handle_;
Role role_ = Role::FEED;
std::string name_{};
Expand All @@ -494,7 +494,7 @@ struct DXFCPP_EXPORT DXEndpoint : public RequireMakeShared<DXEndpoint> {

std::unique_ptr<Impl> impl_;

public:
public:
explicit DXEndpoint(LockExternalConstructionTag);
DXEndpoint(LockExternalConstructionTag, JavaObjectHandle<DXEndpoint> &&handle, Role role, std::string name);

Expand Down Expand Up @@ -887,7 +887,7 @@ struct DXFCPP_EXPORT DXEndpoint : public RequireMakeShared<DXEndpoint> {
*/
void loadDefaultPropertiesImpl();

public:
public:
explicit Builder(LockExternalConstructionTag) noexcept;

/// Releases the GraalVM handle
Expand Down
6 changes: 3 additions & 3 deletions include/dxfeed_graal_cpp_api/api/DXFeed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct DXFCPP_EXPORT DXFeed : SharedEntity {
friend struct TimeSeriesTxModelImpl;
friend struct IndexedTxModelImpl;

private:
private:
JavaObjectHandle<DXFeed> handle_;
static std::shared_ptr<DXFeed> create(void *feedHandle);

Expand Down Expand Up @@ -152,10 +152,10 @@ struct DXFCPP_EXPORT DXFeed : SharedEntity {
JavaObjectHandle<DXFeedSubscription>
createTimeSeriesSubscriptionHandleFromEventClassList(const std::unique_ptr<EventClassList> &list);

protected:
protected:
DXFeed() noexcept;

public:
public:
~DXFeed() noexcept override;

/**
Expand Down
8 changes: 4 additions & 4 deletions include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct LastingEvent;
* Subscription for a set of symbols and event types.
*/
class DXFCPP_EXPORT DXFeedSubscription : public RequireMakeShared<DXFeedSubscription>, public ObservableSubscription {
public:
public:
static constexpr std::size_t FAKE_CHANGE_LISTENER_ID{static_cast<std::size_t>(-1)};

///
Expand All @@ -55,7 +55,7 @@ class DXFCPP_EXPORT DXFeedSubscription : public RequireMakeShared<DXFeedSubscrip
*/
static const std::int32_t MAX_BATCH_LIMIT = std::numeric_limits<std::int32_t>::max();

protected:
protected:
friend struct DXFeed;

inline static std::atomic<std::size_t> lastChangeListenerId_{};
Expand Down Expand Up @@ -126,7 +126,7 @@ class DXFCPP_EXPORT DXFeedSubscription : public RequireMakeShared<DXFeedSubscrip
handle_ = std::move(handle);
}

public:
public:
/// The alias to a type of shared pointer to the DXFeedSubscription object
using Ptr = std::shared_ptr<DXFeedSubscription>;

Expand Down Expand Up @@ -789,7 +789,7 @@ class DXFeedTimeSeriesSubscription : public RequireMakeShared<DXFeedTimeSeriesSu

static void registerEntity();

public:
public:
DXFeedTimeSeriesSubscription(RequireMakeShared<DXFeedTimeSeriesSubscription>::LockExternalConstructionTag lockTag);

DXFeedTimeSeriesSubscription(RequireMakeShared<DXFeedTimeSeriesSubscription>::LockExternalConstructionTag lockTag,
Expand Down
6 changes: 3 additions & 3 deletions include/dxfeed_graal_cpp_api/api/DXPublisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct DXFCPP_EXPORT DXPublisher : SharedEntity {

friend struct DXEndpoint;

private:
private:
mutable std::recursive_mutex mutex_{};
JavaObjectHandle<DXPublisher> handle_;
std::unordered_map<std::reference_wrapper<const dxfcpp::EventTypeEnum>, std::shared_ptr<ObservableSubscription>>
Expand All @@ -77,10 +77,10 @@ struct DXFCPP_EXPORT DXPublisher : SharedEntity {
static std::shared_ptr<DXPublisher> create(void *handle);
void publishEventsImpl(void *graalEventsList) const noexcept;

protected:
protected:
DXPublisher() noexcept;

public:
public:
~DXPublisher() noexcept override;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ struct DXFCPP_EXPORT DXPublisherObservableSubscription : RequireMakeShared<DXPub
ObservableSubscription {
static constexpr std::size_t FAKE_LISTENER_ID{static_cast<std::size_t>(-1)};

private:
private:
inline static std::atomic<std::size_t> lastListenerId_{};

JavaObjectHandle<DXPublisherObservableSubscription> handle_;
std::unordered_map<std::size_t, std::shared_ptr<ObservableSubscriptionChangeListener>> listeners_;
std::recursive_mutex listenersMutex_{};

public:
public:
DXPublisherObservableSubscription(LockExternalConstructionTag,
JavaObjectHandle<DXPublisherObservableSubscription> &&handle);
~DXPublisherObservableSubscription() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ struct SymbolWrapper;
class DXFCPP_EXPORT IndexedEventSubscriptionSymbol {
friend SymbolWrapper;

//struct Impl;
// struct Impl;

std::unique_ptr<SymbolWrapper> eventSymbol_;
std::unique_ptr<IndexedEventSource> source_;

protected:
protected:
/**
* Allocates memory for the dxFeed Graal SDK structure (recursively if necessary).
* Fills the dxFeed Graal SDK structure's fields by the data of the current entity (recursively if necessary).
Expand Down Expand Up @@ -73,7 +73,7 @@ class DXFCPP_EXPORT IndexedEventSubscriptionSymbol {
*/
static IndexedEventSubscriptionSymbol fromGraal(void *graalNative);

public:
public:
/**
* Creates indexed event subscription symbol with a specified event symbol and source.
*
Expand Down Expand Up @@ -121,7 +121,8 @@ class DXFCPP_EXPORT IndexedEventSubscriptionSymbol {
DXFCPP_END_NAMESPACE

template <> struct std::hash<dxfcpp::IndexedEventSubscriptionSymbol> {
std::size_t operator()(const dxfcpp::IndexedEventSubscriptionSymbol &indexedEventSubscriptionSymbol) const noexcept {
std::size_t
operator()(const dxfcpp::IndexedEventSubscriptionSymbol &indexedEventSubscriptionSymbol) const noexcept {
return std::hash<std::string>{}(indexedEventSubscriptionSymbol.toString());
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251)

#include "../../event/EventTypeEnum.hpp"
#include "../../event/IndexedEventSource.hpp"
#include "../../symbols/SymbolWrapper.hpp"
#include "../../event/EventTypeEnum.hpp"
#include "ObservableSubscriptionChangeListener.hpp"

#include <cstdint>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251)

#include "../../symbols/SymbolWrapper.hpp"
#include "../../entity/SharedEntity.hpp"
#include "../../symbols/SymbolWrapper.hpp"

#include <memory>
#include <unordered_set>
Expand All @@ -17,7 +17,7 @@ DXFCPP_BEGIN_NAMESPACE

struct DXFCPP_EXPORT ObservableSubscriptionChangeListener : RequireMakeShared<ObservableSubscriptionChangeListener> {
explicit ObservableSubscriptionChangeListener(LockExternalConstructionTag);
~ObservableSubscriptionChangeListener() noexcept override;
~ObservableSubscriptionChangeListener() noexcept override;

static std::shared_ptr<ObservableSubscriptionChangeListener>
create(std::function<void(const std::unordered_set<SymbolWrapper> &symbols)> onSymbolsAdded);
Expand All @@ -29,7 +29,7 @@ struct DXFCPP_EXPORT ObservableSubscriptionChangeListener : RequireMakeShared<Ob

const JavaObjectHandle<ObservableSubscriptionChangeListener> &getHandle() const;

private:
private:
mutable std::recursive_mutex mutex_{};
JavaObjectHandle<ObservableSubscriptionChangeListener> handle_;
SimpleHandler<void(const std::unordered_set<SymbolWrapper> &symbols)> onSymbolsAdded_{};
Expand Down
2 changes: 1 addition & 1 deletion include/dxfeed_graal_cpp_api/api/osub/OsubModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251)

#include "IndexedEventSubscriptionSymbol.hpp"
#include "ObservableSubscriptionChangeListener.hpp"
#include "ObservableSubscription.hpp"
#include "ObservableSubscriptionChangeListener.hpp"
#include "TimeSeriesSubscriptionSymbol.hpp"
#include "WildcardSymbol.hpp"

Expand Down
Loading