Skip to content

Commit

Permalink
[EN-7021] Add *Order events (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyKalin committed Jul 30, 2023
1 parent 2dfe4b0 commit 0d64853
Show file tree
Hide file tree
Showing 96 changed files with 3,582 additions and 771 deletions.
5 changes: 5 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ IndentPPDirectives: AfterHash
TabWidth: 4
IndentWidth: 4
UseTab: Never
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false
27 changes: 18 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,29 @@ set(dxFeedNativeAPIEventSources
)

set(dxFeedNativeAPIEventMarketSources
src/event/market/AnalyticOrder.cpp
src/event/market/Direction.cpp
src/event/market/IcebergType.cpp
src/event/market/MarketEvent.cpp
src/event/market/OptionSale.cpp
src/event/market/Order.cpp
src/event/market/OrderAction.cpp
src/event/market/OrderBase.cpp
src/event/market/OrderSource.cpp
src/event/market/PriceType.cpp
src/event/market/Profile.cpp
src/event/market/Quote.cpp
src/event/market/Scope.cpp
src/event/market/ShortSaleRestriction.cpp
src/event/market/TradingStatus.cpp
src/event/market/Profile.cpp
src/event/market/PriceType.cpp
src/event/market/Side.cpp
src/event/market/SpreadOrder.cpp
src/event/market/Summary.cpp
src/event/market/Direction.cpp
src/event/market/TradeBase.cpp
src/event/market/TimeAndSale.cpp
src/event/market/TimeAndSaleType.cpp
src/event/market/Trade.cpp
src/event/market/TradeBase.cpp
src/event/market/TradeETH.cpp
src/event/market/Side.cpp
src/event/market/TimeAndSaleType.cpp
src/event/market/TimeAndSale.cpp
src/event/market/OptionSale.cpp
src/event/market/TradingStatus.cpp
)

set(dxFeedNativeAPIEventOptionSources
Expand Down
196 changes: 146 additions & 50 deletions README.md

Large diffs are not rendered by default.

31 changes: 23 additions & 8 deletions include/dxfeed_graal_cpp_api/api/DXEndpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,9 @@ struct DXFCPP_EXPORT DXEndpoint : SharedEntity {
*
* @see DXEndpoint
*/
Role getRole() const { return role_; }
Role getRole() const {
return role_;
}

/**
* Returns the state of this endpoint.
Expand All @@ -601,12 +603,16 @@ struct DXFCPP_EXPORT DXEndpoint : SharedEntity {
State getState() const;

/// @return `true` if the endpoint is closed
bool isClosed() const { return getState() == State::CLOSED; }
bool isClosed() const {
return getState() == State::CLOSED;
}

/**
* @return The user defined endpoint's name
*/
const std::string &getName() const & { return name_; }
const std::string &getName() const & {
return name_;
}

/**
* Adds listener that is notified about changes in @ref ::getState() "state" property.
Expand Down Expand Up @@ -635,18 +641,23 @@ struct DXFCPP_EXPORT DXEndpoint : SharedEntity {
*
* @param listenerId The listener id to remove
*/
void removeStateChangeListener(std::size_t listenerId) noexcept { onStateChange_ -= listenerId; }
void removeStateChangeListener(std::size_t listenerId) noexcept {
onStateChange_ -= listenerId;
}

/**
* Returns the onStateChange @ref Handler<void(ArgTypes...)> "handler" that can be used to add or remove
* listeners.
*
* @return onStateChange handler with `void(State, State)` signature
*/
auto &onStateChange() noexcept { return onStateChange_; }
auto &onStateChange() noexcept {
return onStateChange_;
}

// TODO: implement
template <typename Executor> void executor(Executor &&) {}
template <typename Executor> void executor(Executor &&) {
}

/**
* Changes user name for this endpoint.
Expand Down Expand Up @@ -794,15 +805,19 @@ struct DXFCPP_EXPORT DXEndpoint : SharedEntity {
void closeAndAwaitTermination();

// TODO: implement
std::unordered_set<EventTypeEnum> getEventTypes() { return {}; }
std::unordered_set<EventTypeEnum> getEventTypes() {
return {};
}

/**
* @return The feed that is associated with this endpoint.
*/
std::shared_ptr<DXFeed> getFeed();

// TODO: implement
std::shared_ptr<DXPublisher> getPublisher() { return {}; }
std::shared_ptr<DXPublisher> getPublisher() {
return {};
}

/**
* Builder class for DXEndpoint that supports additional configuration properties.
Expand Down
32 changes: 22 additions & 10 deletions include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class DXFCPP_EXPORT DXFeedSubscription : public SharedEntity {
}

DXFeedSubscription(std::initializer_list<EventTypeEnum> eventTypes) noexcept
: DXFeedSubscription(eventTypes.begin(), eventTypes.end()) {}
: DXFeedSubscription(eventTypes.begin(), eventTypes.end()) {
}

template <typename EventTypesCollection>
explicit DXFeedSubscription(EventTypesCollection &&eventTypes) noexcept
Expand Down Expand Up @@ -106,7 +107,9 @@ class DXFCPP_EXPORT DXFeedSubscription : public SharedEntity {
Debugger::debug("DXFeedSubscription{" + handler_.toString() + "}::~DXFeedSubscription()");
}

tryCallWithLock(mtx_, [this] { closeImpl(); });
tryCallWithLock(mtx_, [this] {
closeImpl();
});
}

/**
Expand Down Expand Up @@ -328,7 +331,8 @@ class DXFCPP_EXPORT DXFeedSubscription : public SharedEntity {
#endif
{
if (!containsEventType(EventT::TYPE)) {
return onEvent_ += [](auto) {};
return onEvent_ += [](auto) {
};
}

return onEvent_ += [l = listener](auto &&events) {
Expand Down Expand Up @@ -358,7 +362,9 @@ class DXFCPP_EXPORT DXFeedSubscription : public SharedEntity {
*
* @param listenerId The listener id
*/
void removeEventListener(std::size_t listenerId) noexcept { onEvent_ -= listenerId; }
void removeEventListener(std::size_t listenerId) noexcept {
onEvent_ -= listenerId;
}

/**
* Returns a reference to an incoming events' handler (delegate), to which listeners can be added and removed.
Expand All @@ -383,7 +389,9 @@ class DXFCPP_EXPORT DXFeedSubscription : public SharedEntity {
*
* @return The incoming events' handler (delegate)
*/
auto &onEvent() noexcept { return onEvent_; }
auto &onEvent() noexcept {
return onEvent_;
}

/**
* Adds the specified symbol to the set of subscribed symbols.
Expand Down Expand Up @@ -454,7 +462,7 @@ class DXFCPP_EXPORT DXFeedSubscription : public SharedEntity {
Debugger::debug(toString() + "::addSymbols(symbols = " + elementsToString(begin, end) + ")");
}

auto* list = SymbolWrapper::toGraalList(begin, end);
auto *list = SymbolWrapper::toGraalList(begin, end);

addSymbolsImpl(list);
SymbolWrapper::freeGraalList(list);
Expand Down Expand Up @@ -512,7 +520,7 @@ class DXFCPP_EXPORT DXFeedSubscription : public SharedEntity {
Debugger::debug(toString() + "::removeSymbols(symbols = " + elementsToString(begin, end) + ")");
}

auto* list = SymbolWrapper::toGraalList(begin, end);
auto *list = SymbolWrapper::toGraalList(begin, end);

removeSymbolsImpl(list);
SymbolWrapper::freeGraalList(list);
Expand Down Expand Up @@ -571,7 +579,7 @@ class DXFCPP_EXPORT DXFeedSubscription : public SharedEntity {
Debugger::debug(toString() + "::setSymbols(symbols = " + elementsToString(begin, end) + ")");
}

auto* list = SymbolWrapper::toGraalList(begin, end);
auto *list = SymbolWrapper::toGraalList(begin, end);

setSymbolsImpl(list);
SymbolWrapper::freeGraalList(list);
Expand Down Expand Up @@ -642,7 +650,9 @@ class DXFCPP_EXPORT DXFeedSubscription : public SharedEntity {
*
* @return A set of subscribed event types.
*/
const std::unordered_set<EventTypeEnum> &getEventTypes() const noexcept { return eventTypes_; }
const std::unordered_set<EventTypeEnum> &getEventTypes() const noexcept {
return eventTypes_;
}

/**
* Returns `true` if this subscription contains the corresponding event type.
Expand All @@ -651,7 +661,9 @@ class DXFCPP_EXPORT DXFeedSubscription : public SharedEntity {
*
* @see ::getEventTypes()
*/
bool containsEventType(const EventTypeEnum &eventType) const noexcept { return eventTypes_.contains(eventType); }
bool containsEventType(const EventTypeEnum &eventType) const noexcept {
return eventTypes_.contains(eventType);
}

/**
* Returns a set of subscribed symbols (depending on the actual implementation of subscription).
Expand Down
11 changes: 5 additions & 6 deletions include/dxfeed_graal_cpp_api/api/FilteredSubscriptionSymbol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ namespace dxfcpp {
/**
* This marker interface marks subscription symbol classes (like TimeSeriesSubscriptionSymbol)
* that attach "filters" to the actual symbols. Filtered subscription symbols implement their `operator ==`
* and `std::hash<>` based on their symbol only, without considering their "filter" part (for example, a TimeSeriesSubscriptionSymbol has
* a @ref TimeSeriesSubscriptionSymbol::getFromTime() "fromTime" filter on a time range of events).
* and `std::hash<>` based on their symbol only, without considering their "filter" part (for example, a
* TimeSeriesSubscriptionSymbol has a @ref TimeSeriesSubscriptionSymbol::getFromTime() "fromTime" filter on a time range
* of events).
*
* <p>DXFeedSubscription has the following behavior for filtered symbols. There can be only one
* active filter per symbol. Adding new filtered symbol with the same symbol but different filter
Expand All @@ -21,8 +22,6 @@ namespace dxfcpp {
* symbols (like StringSymbol, for example) there is no notification when replacing one symbol with the other that
* is "equal" to the first one.
*/
struct FilteredSubscriptionSymbol {
struct FilteredSubscriptionSymbol {};

};

}
} // namespace dxfcpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class DXFCPP_EXPORT IndexedEventSubscriptionSymbol {

virtual void *toGraal() const noexcept;

static void freeGraal(void* graal) noexcept;
static void freeGraal(void *graal) noexcept;

static IndexedEventSubscriptionSymbol fromGraal(void* graal) noexcept;
static IndexedEventSubscriptionSymbol fromGraal(void *graal) noexcept;

/**
* Returns string representation of this indexed event subscription symbol.
Expand Down
33 changes: 22 additions & 11 deletions include/dxfeed_graal_cpp_api/api/osub/WildcardSymbol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#include <cstdint>
#include <memory>
#include <utility>
#include <string>
#include <utility>

namespace dxfcpp {

Expand All @@ -31,10 +31,10 @@ struct DXFCPP_EXPORT WildcardSymbol final {
* <p><b>NOTE:</b> Wildcard subscription can create extremely high network and CPU load for certain kinds of
* high-frequency events like quotes. It requires a special arrangement on the side of upstream data provider and
* is disabled by default in upstream feed configuration. Make that sure you have adequate resources and understand
* the impact before using it. It can be used for low-frequency events only (like Forex quotes), because each instance
* of DXFeedSubscription processes events in a single thread and there is no provision to load-balance wildcard
* subscription amongst multiple threads.
* Contact your data provider for the corresponding configuration arrangement if needed.
* the impact before using it. It can be used for low-frequency events only (like Forex quotes), because each
* instance of DXFeedSubscription processes events in a single thread and there is no provision to load-balance
* wildcard subscription amongst multiple threads. Contact your data provider for the corresponding configuration
* arrangement if needed.
*
* @see WildcardSymbol
*/
Expand All @@ -43,7 +43,8 @@ struct DXFCPP_EXPORT WildcardSymbol final {
private:
std::string symbol_;

WildcardSymbol(const std::string &symbol) noexcept : symbol_{symbol} {}
WildcardSymbol(const std::string &symbol) noexcept : symbol_{symbol} {
}

public:
WildcardSymbol(const WildcardSymbol &) noexcept = default;
Expand All @@ -53,7 +54,9 @@ struct DXFCPP_EXPORT WildcardSymbol final {
WildcardSymbol() noexcept = default;
virtual ~WildcardSymbol() noexcept = default;

const std::string &getSymbol() const noexcept { return symbol_; }
const std::string &getSymbol() const noexcept {
return symbol_;
}

void *toGraal() const noexcept;

Expand All @@ -74,16 +77,24 @@ struct DXFCPP_EXPORT WildcardSymbol final {
}
}

bool operator==(const WildcardSymbol &wildcardSymbol) const { return symbol_ == wildcardSymbol.symbol_; }
bool operator==(const WildcardSymbol &wildcardSymbol) const {
return symbol_ == wildcardSymbol.symbol_;
}

bool operator<(const WildcardSymbol &wildcardSymbol) const { return symbol_ < wildcardSymbol.symbol_; }
bool operator<(const WildcardSymbol &wildcardSymbol) const {
return symbol_ < wildcardSymbol.symbol_;
}
};

inline namespace literals {

inline WildcardSymbol operator""_ws(const char *, size_t) noexcept { return WildcardSymbol::ALL; }
inline WildcardSymbol operator""_ws(const char *, size_t) noexcept {
return WildcardSymbol::ALL;
}

inline WildcardSymbol operator""_wcs(const char *, size_t) noexcept { return WildcardSymbol::ALL; }
inline WildcardSymbol operator""_wcs(const char *, size_t) noexcept {
return WildcardSymbol::ALL;
}

} // namespace literals

Expand Down
4 changes: 3 additions & 1 deletion include/dxfeed_graal_cpp_api/entity/SharedEntity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ struct DXFCPP_EXPORT SharedEntity : public Entity, std::enable_shared_from_this<
*
* @return a string representation
*/
virtual std::string toString() const noexcept { return "SharedEntity{}"; }
virtual std::string toString() const noexcept {
return "SharedEntity{}";
}
};

} // namespace dxfcpp
23 changes: 14 additions & 9 deletions include/dxfeed_graal_cpp_api/event/DXEvent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,29 @@
#include "TimeSeriesEvent.hpp"
#include "candle/Candle.hpp"
#include "candle/CandleSymbol.hpp"
#include "market/AnalyticOrder.hpp"
#include "market/Direction.hpp"
#include "market/IcebergType.hpp"
#include "market/MarketEvent.hpp"
#include "market/OptionSale.hpp"
#include "market/OrderAction.hpp"
#include "market/OrderBase.hpp"
#include "market/OrderSource.hpp"
#include "market/PriceType.hpp"
#include "market/Profile.hpp"
#include "market/Quote.hpp"
#include "market/Scope.hpp"
#include "market/ShortSaleRestriction.hpp"
#include "market/Side.hpp"
#include "market/SpreadOrder.hpp"
#include "market/Summary.hpp"
#include "market/TimeAndSale.hpp"
#include "market/TimeAndSaleType.hpp"
#include "market/Trade.hpp"
#include "market/TradeBase.hpp"
#include "market/TradeETH.hpp"
#include "market/TradingStatus.hpp"
#include "option/Greeks.hpp"
#include "option/Series.hpp"
#include "option/TheoPrice.hpp"
#include "option/Underlying.hpp"
#include "market/Trade.hpp"
#include "market/TradeETH.hpp"
#include "market/Side.hpp"
#include "market/TimeAndSaleType.hpp"
#include "market/TimeAndSale.hpp"
#include "option/Series.hpp"
#include "market/OptionSale.hpp"
#include "market/OrderSource.hpp"
#include "market/OrderBase.hpp"
Loading

0 comments on commit 0d64853

Please sign in to comment.