dxFeed Graal CXX API
|
Provides API for publishing of events to local or remote DXFeed. More...
#include <DXPublisher.hpp>
Public Types | |
using | Ptr = std::shared_ptr<DXPublisher> |
The alias to a type of shared pointer to the DXPublisher object. | |
using | Unique = std::unique_ptr<DXPublisher> |
The alias to a type of unique pointer to the DXPublisher object. | |
Public Types inherited from SharedEntity | |
using | Ptr = std::shared_ptr<SharedEntity> |
The alias to a type of shared pointer to the SharedEntity object. | |
Public Member Functions | |
template<typename EventsCollection > | |
void | publishEvents (EventsCollection &&events) noexcept |
Publishes events to the corresponding feed. | |
void | publishEvents (std::initializer_list< std::shared_ptr< EventType > > events) noexcept |
Publishes events to the corresponding feed. | |
void | publishEvents (std::shared_ptr< EventType > event) noexcept |
Publishes an event to the corresponding feed. | |
template<typename EventIt > | |
void | publishEvents (EventIt begin, EventIt end) |
Publishes events to the corresponding feed. | |
std::shared_ptr< ObservableSubscription > | getSubscription (const EventTypeEnum &eventType) |
Returns observable set of subscribed symbols for the specified event type. | |
std::string | toString () const noexcept override |
Returns a string representation of the current object. | |
Public Member Functions inherited from SharedEntity | |
template<typename T > | |
bool | is () const noexcept |
Checks that pointer to the current type could be converted to type T* In other words: whether type T belongs to the type hierarchy in which the current type resides. | |
template<typename T > | |
std::shared_ptr< T > | sharedAs () noexcept |
Returns a pointer to the current object wrapped in a smart pointer to type T. | |
template<typename T > | |
std::shared_ptr< T > | sharedAs () const noexcept |
Returns a pointer to the current object wrapped in a smart pointer to type T. | |
Public Member Functions inherited from Entity | |
virtual | ~Entity () noexcept=default |
The default virtual d-tor. | |
Static Public Member Functions | |
static std::shared_ptr< DXPublisher > | getInstance () |
Returns a default application-wide singleton instance of DXPublisher. | |
Friends | |
struct | DXEndpoint |
Provides API for publishing of events to local or remote DXFeed.
This section gives sample usage scenarios.
There is a singleton instance of the publisher that is returned by DXPublisher::getInstance() method. It is created on the first use with default configuration properties that are explained in detail in documentation for DXEndpoint class in the "Default properties" section. In particular, you can provide a default address to connect using 'dxpublisher.address' system property or by putting it into 'dxpublisher.properties' file in the current directory.
The following code publishes a single quote for a "A:TEST" symbol:
auto quote = std::make_shared<Quote>("A:TEST");
quote->setBidPrice(100);
quote->setAskPrice(101);
DXPublisher::getInstance()->publishEvents(quote);
This class is thread-safe and can be used concurrently from multiple threads without external synchronization.
|
static |
Returns a default application-wide singleton instance of DXPublisher.
Most applications use only a single data-sink and should rely on this method to get one. This is a shortcut to DXEndpoint::getInstance(DXEndpoint::Role::PUBLISHER)->getPublisher().
std::shared_ptr< ObservableSubscription > DXPublisher::getSubscription | ( | const EventTypeEnum & | eventType | ) |
Returns observable set of subscribed symbols for the specified event type.
Note, that subscription is represented by SymbolWrapper symbols. Check the type of each symbol in ObservableSubscription using SymbolWrapper::isStringSymbol(), SymbolWrapper::isWildcardSymbol(), SymbolWrapper::isIndexedEventSubscriptionSymbol(), SymbolWrapper::isTimeSeriesSubscriptionSymbol(), SymbolWrapper::isCandleSymbol().
The set of subscribed symbols contains WildcardSymbol::ALL if and only if there is a subscription to this wildcard symbol.
If DXFeedTimeSeriesSubscription is used to subscribe to time-service of the events of this type, then instances of TimeSeriesSubscriptionSymbol class represent the corresponding subscription item.
The resulting observable subscription can generate repeated ObservableSubscriptionChangeListener::onSymbolsAdded_ notifications to its listeners for the same symbols without the corresponding ObservableSubscriptionChangeListener::onSymbolsRemoved_ notifications in between them. It happens when subscription disappears, cached data is lost, and subscription reappears again. On each ObservableSubscriptionChangeListener::onSymbolsAdded_ notification data provider shall publish the most recent events for the corresponding symbols.
eventType | The event type. |
|
inline |
Publishes events to the corresponding feed.
EventIt | The collection's iterator type |
begin | The beginning of the collection of events. |
end | The end of events collection. |
|
inlinenoexcept |
Publishes events to the corresponding feed.
If the endpoint of this publisher has role of DXEndpoint::Role::PUBLISHER and it is connected, the published events will be delivered to the remote endpoints. Local feed will always receive published events.
This method serializes all events into internal representation, so that the instance of the collection as well as the instances of events can be reused after invocation of this method returns.
DXFeed instances that are connected to this publisher either locally or via network receive published events if and only if they are subscribed to the corresponding symbols, or they are subscribed via WildcardSymbol::ALL, or, in case of TimeSeriesEvent type, they are subscribed via DXFeedTimeSeriesSubscription for the corresponding symbol and time frame.
Published events are not stored and get immediately lost if there is no subscription. Last published events of LastingEvent types are cached as long as subscription to them is maintained via a specific event symbol (WildcardSymbol::ALL does not count) and the cache is discarded as soon as subscription disappears.
Example:
EventsCollection | The type of events collection (for example: std::vector<::EventType::Ptr>) |
events | The collection of events to publish. |
|
inlinenoexcept |
Publishes events to the corresponding feed.
events | The collection of events to publish. |
|
inlinenoexcept |
Publishes an event to the corresponding feed.
event | The event to publish. |
|
overridevirtualnoexcept |
Returns a string representation of the current object.
Reimplemented from SharedEntity.