dxFeed Graal CXX API v9.0.0
Loading...
Searching...
No Matches
DXFeedSubscription Class Reference

Subscription for a set of symbols and event types. More...

#include <DXFeedSubscription.hpp>

Inheritance diagram for DXFeedSubscription:

Public Types

using Ptr = std::shared_ptr<DXFeedSubscription>
 The alias to a type of shared pointer to the DXFeedSubscription object.
using Unique = std::unique_ptr<DXFeedSubscription>
 The alias to a type of unique pointer to the DXFeedSubscription object.
using OnSilenceHandler
 The function that the silence watchdog calls (see setSilenceWatchdog()): the subscription and the time since its silence began.
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

std::string toString () const override
 Returns a string representation of the current object.
void attach (std::shared_ptr< DXFeed > feed)
 Attaches subscription to the specified feed.
void detach (std::shared_ptr< DXFeed > feed)
 Detaches subscription from the specified feed.
bool isClosed () override
 Returns true if this subscription is closed.
void close () const
 Closes this subscription and makes it permanently detached.
void setSilenceWatchdog (std::chrono::milliseconds timeout, OnSilenceHandler onSilence={})
 Turns the silence watchdog of this subscription on or off.
std::unordered_set< EventTypeEnum > getEventTypes () override
 Returns a set of subscribed event types.
bool containsEventType (const EventTypeEnum &eventType) override
 Returns true if this subscription contains the corresponding event type.
void clear () const
 Clears the set of subscribed symbols.
std::vector< SymbolWrapper > getSymbols () const
 Returns a set of subscribed symbols (depending on the actual implementation of the subscription).
std::vector< SymbolWrapper > getDecoratedSymbols () const
 Returns a set of decorated symbols (depending on the actual implementation of the subscription).
template<typename SymbolIt>
void setSymbols (SymbolIt begin, SymbolIt end) const
 Changes the set of subscribed symbols so that it contains just the symbols from the specified collection (using iterators).
template<ConvertibleToSymbolWrapperCollection SymbolsCollection>
void setSymbols (SymbolsCollection &&collection) const
 Changes the set of subscribed symbols so that it contains just the symbols from the specified collection.
void setSymbols (std::initializer_list< SymbolWrapper > collection) const
 Changes the set of subscribed symbols so that it contains just the symbols from the specified collection (initializer list).
void addSymbols (const SymbolWrapper &symbolWrapper) const
 Adds the specified symbol to the set of subscribed symbols.
template<typename SymbolIt>
void addSymbols (SymbolIt begin, SymbolIt end) const
 Adds the specified collection (using iterators) of symbols to the set of subscribed symbols.
template<ConvertibleToSymbolWrapperCollection SymbolsCollection>
void addSymbols (const SymbolsCollection &collection) const
 Adds the specified collection of symbols to the set of subscribed symbols.
void addSymbols (std::initializer_list< SymbolWrapper > collection) const
 Adds the specified collection (initializer list) of symbols to the set of subscribed symbols.
void removeSymbols (const SymbolWrapper &symbolWrapper) const
 Removes the specified symbol from the set of subscribed symbols.
template<typename SymbolIt>
void removeSymbols (SymbolIt begin, SymbolIt end) const
 Removes the specified collection (using iterators) of symbols from the set of subscribed symbols.
template<ConvertibleToSymbolWrapperCollection SymbolsCollection>
void removeSymbols (SymbolsCollection &&collection) const
 Removes the specified collection of symbols from the set of subscribed symbols.
void removeSymbols (std::initializer_list< SymbolWrapper > collection) const
 Removes the specified collection (initializer list) of symbols from the set of subscribed symbols.
TimePeriod getAggregationPeriod () const
 Returns the aggregation period for data for this subscription instance.
void setAggregationPeriod (const TimePeriod &aggregationPeriod) const
 Sets the aggregation period for data.
void setAggregationPeriod (std::chrono::milliseconds aggregationPeriod) const
 Sets the aggregation period for data.
void setAggregationPeriod (std::int64_t aggregationPeriod) const
 Sets the aggregation period for data.
TimePeriodInfo getAggregationPeriodInfo () const
 Returns the aggregation period that was applied to the events delivered to this subscription: the maximum of the period that the server applies (see DXEndpoint::getAggregationPeriodInfo()) and getAggregationPeriod(), as it was used when the events were delivered.
std::int64_t getTotalDroppedEvents () const
 Returns the total number of events that were dropped for this subscription since it was created.
template<typename EventListener>
std::size_t addEventListener (EventListener &&listener)
 Adds listener for events.
template<typename EventT>
std::size_t addEventListener (std::function< void(const std::vector< std::shared_ptr< EventT > > &)> &&listener)
 Adds typed listener for events.
void removeEventListener (std::size_t listenerId)
 Removes listener for events.
OnEventHandler & onEvent ()
 Returns a reference to an incoming events' handler (delegate), to which listeners can be added and removed.
std::size_t addChangeListener (std::shared_ptr< ObservableSubscriptionChangeListener > listener) override
 Adds subscription change listener.
void removeChangeListener (std::size_t changeListenerId) override
 Removes subscription change listener by id.
std::int32_t getEventsBatchLimit () const
void setEventsBatchLimit (std::int32_t eventsBatchLimit) const
 Sets maximum number of events in the single notification of OnEventHandler.
Public Member Functions inherited from SharedEntity
template<typename T>
bool is () const noexcept
 Checks that the object is of type T: its dynamic type is T or derived from T.
template<typename T>
std::shared_ptr< T > sharedAs () noexcept
 Returns a pointer to the current object wrapped in a smart pointer to type T or std::shared_ptr<T>{nullptr} if the object is not managed by std::shared_ptr.
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 or std::shared_ptr<T>{nullptr} if the object is not managed by std::shared_ptr.
Public Member Functions inherited from Entity
virtual ~Entity () noexcept
 The default virtual d-tor.

Static Public Member Functions

static std::shared_ptr< DXFeedSubscription > create (const EventTypeEnum &eventType)
 Creates a detached subscription for a single event type.
template<typename EventTypeIt>
static std::shared_ptr< DXFeedSubscription > create (EventTypeIt begin, EventTypeIt end)
 Creates a detached subscription for the given collection of event types.
static std::shared_ptr< DXFeedSubscription > create (std::initializer_list< EventTypeEnum > eventTypes)
 Creates a detached subscription for the given collection of event types.
template<typename EventTypesCollection>
static std::shared_ptr< DXFeedSubscription > create (EventTypesCollection &&eventTypes)
 Creates a detached subscription for the given collection of event types.
Static Public Member Functions inherited from RequireMakeShared< DXFeedSubscription >
static auto createShared (Args &&...args)
 Creates a smart pointer to an object.

Static Public Attributes

static constexpr char SLOW_LISTENER_THRESHOLD_PROPERTY [] = "dxfcpp.subscription.slowListenerThreshold"
 "dxfcpp.subscription.slowListenerThreshold"
static constexpr char EVENT_LAG_THRESHOLD_PROPERTY [] = "dxfcpp.subscription.eventLagThreshold"
 "dxfcpp.subscription.eventLagThreshold"
static constexpr char WARNING_PERIOD_PROPERTY [] = "dxfcpp.subscription.warningPeriod"
 "dxfcpp.subscription.warningPeriod"
static constexpr std::int32_t OPTIMAL_BATCH_LIMIT = 0
 The optimal events' batch limit for a single notification in OnEventHandler.
static constexpr std::int32_t MAX_BATCH_LIMIT = (std::numeric_limits<std::int32_t>::max)()
 The maximum events' batch limit for a single notification in OnEventHandler.

Friends

struct DXFeed

Detailed Description

Subscription for a set of symbols and event types.

The functions that take symbols throw InvalidArgumentException if a symbol is not valid UTF-8 (see StringParam); the set of subscribed symbols is not changed then.

Threads and locks

This class is thread-safe. The event listeners are called on a thread of the executor of the endpoint, one batch at a time, and must not block: see Listeners and threads.

Member Function Documentation

◆ addChangeListener()

std::size_t DXFeedSubscription::addChangeListener ( std::shared_ptr< ObservableSubscriptionChangeListener > listener)
overridevirtual

Adds subscription change listener.

This method does nothing if the subscription is closed. Otherwise, it installs the corresponding listener and immediately invokes ObservableSubscriptionChangeListener::onSymbolsAdded_ on the given listener while holding the lock for this subscription. This way the given listener synchronously receives the existing subscription state and is synchronously notified on all changes in the subscription afterward.

Parameters
listenerThe subscription change listener.
Returns
The listener id

Implements ObservableSubscription.

◆ addEventListener() [1/2]

template<typename EventListener>
std::size_t DXFeedSubscription::addEventListener ( EventListener && listener)
inline

Adds listener for events.

Event lister can be added only when the subscription is not producing any events. The subscription must be either empty (its set of symbols is empty or not attached to any feed (its set of change listeners is empty).

This method does nothing if this subscription is closed.

Example:

auto sub = endpoint->getFeed()->createSubscription({dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE});
sub->addEventListener([](auto &&events) {
for (const auto &e : events) {
if (auto quote = e->template sharedAs<dxfcpp::Quote>(); quote) {
std::cout << "Q : " + quote->toString() << std::endl;
} else if (auto tns = e->template sharedAs<dxfcpp::TimeAndSale>(); tns) {
std::cout << "TnS : " + tns->toString() << std::endl;
}
}
});
sub->addSymbols({"$TOP10L/Q", "$SP500#45", "$TICK", "SPX"});
std::shared_ptr< T > sharedAs() noexcept
Returns a pointer to the current object wrapped in a smart pointer to type T or std::shared_ptr<T>{nu...
Definition SharedEntity.hpp:49
Template Parameters
EventListenerThe listener type. Listener can be callable with signature: void(const std::vector<std::shared_ptr<EventType>&)
Parameters
listenerThe event listener
Returns
The listener id

References addEventListener().

Referenced by addEventListener().

◆ addEventListener() [2/2]

template<typename EventT>
std::size_t DXFeedSubscription::addEventListener ( std::function< void(const std::vector< std::shared_ptr< EventT > > &)> && listener)
inline

Adds typed listener for events.

Event lister can be added only when the subscription is not producing any events. The subscription must be either empty (its set of symbols is empty or not attached to any feed (its set of change listeners is empty).

This method does nothing if this subscription is closed.

Example:

auto sub = endpoint->getFeed()->createSubscription({dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE});
sub->addEventListener(std::function([](const std::vector<std::shared_ptr<dxfcpp::Quotes>> &quotes) -> void {
for (const auto &q : quotes) {
std::cout << "Q : " + q->toString() << std::endl;
}
}));
sub->addEventListener<dxfcpp::TimeAndSale>([](const auto &timeAndSales) -> void {
for (const auto &tns : timeAndSales) {
std::cout << "TnS : " + tns->toString() << std::endl;
}
});
sub->addEventListener<dxfcpp::MarketEvent>([](const auto &marketEvents) -> void {
for (const auto &me : marketEvents) {
std::cout << "Market Event's symbol: " + me->getEventSymbol() << std::endl;
}
});
sub->addSymbols({"$TOP10L/Q", "AAPL", "$TICK", "SPX"});
Template Parameters
EventTThe event type (EventType's child with field TYPE, convertible to EventTypeEnum or MarketEvent or LastingEvent or TimeSeriesEvent or IndexedEvent)
Parameters
listenerThe listener. Listener can be callable with signature: void(const std::vector<std::shared_ptr<EventT>&)
Returns
The listener id

◆ addSymbols() [1/4]

template<ConvertibleToSymbolWrapperCollection SymbolsCollection>
void DXFeedSubscription::addSymbols ( const SymbolsCollection & collection) const
inline

Adds the specified collection of symbols to the set of subscribed symbols.

Example:

auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
sub->addSymbols(std::vector{"AAPL", "IBM"});
sub->addSymbols(v);
Template Parameters
SymbolsCollectionThe symbol collection's type
Parameters
collectionThe symbol collection

◆ addSymbols() [2/4]

void DXFeedSubscription::addSymbols ( const SymbolWrapper & symbolWrapper) const

Adds the specified symbol to the set of subscribed symbols.

This is a convenience method to subscribe to one symbol at a time that has a return fast-path for a case when the symbol is already in the set. When subscribing to multiple symbols at once, it is preferable to use addSymbols(symbols) method.

Example:

sub->addSymbols("TSLA");
sub->addSymbols("XBT/USD:GDAX"s);
sub->addSymbols("BTC/EUR:CXBITF"sv);
Parameters
symbolWrapperThe symbol.

◆ addSymbols() [3/4]

void DXFeedSubscription::addSymbols ( std::initializer_list< SymbolWrapper > collection) const

Adds the specified collection (initializer list) of symbols to the set of subscribed symbols.

Example:

sub->addSymbols({"AAPL", "IBM"sv, "TSLA"s, "GOOG"_s});
Parameters
collectionThe symbol collection

◆ addSymbols() [4/4]

template<typename SymbolIt>
void DXFeedSubscription::addSymbols ( SymbolIt begin,
SymbolIt end ) const
inline

Adds the specified collection (using iterators) of symbols to the set of subscribed symbols.

Example:

auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
sub->addSymbols(v.begin(), v.end());
Template Parameters
SymbolItThe collection's iterator type
Parameters
beginThe beginning of the symbol collection.
endThe end of the symbol collection.

◆ attach()

void DXFeedSubscription::attach ( std::shared_ptr< DXFeed > feed)

Attaches subscription to the specified feed.

Parameters
feedThe feed to attach to.

◆ close()

void DXFeedSubscription::close ( ) const

Closes this subscription and makes it permanently detached.

This method notifies all installed instances of subscription change listeners by invoking subscriptionClosed while holding the lock for this subscription. This method clears lists of all installed event listeners and subscription change listeners and makes sure that no more listeners can be added.

The subscription is detached from all the feeds, which do not own it anymore. After this method returns, the event listeners are not called; called from a listener or a callback of the library, it does not wait for the calls in progress on the other threads. Adding a listener to a closed subscription or attaching it to a feed does nothing, as a second close() does. A subscription that is attached to no feed is closed when its last pointer is released. See Lifetime of the entities and AutoClose.

◆ containsEventType()

bool DXFeedSubscription::containsEventType ( const EventTypeEnum & eventType)
overridevirtual

Returns true if this subscription contains the corresponding event type.

Parameters
eventTypeThe type of event that is checked.
Returns
true if this subscription contains the corresponding event type.
See also
DXFeedSubscription::getEventTypes()

Implements ObservableSubscription.

◆ create() [1/4]

std::shared_ptr< DXFeedSubscription > DXFeedSubscription::create ( const EventTypeEnum & eventType)
static

Creates a detached subscription for a single event type.

Example:

auto sub = dxfcpp::DXFeedSubscription::create(dxfcpp::Quote::TYPE);
Parameters
eventTypethe event type.

◆ create() [2/4]

template<typename EventTypeIt>
std::shared_ptr< DXFeedSubscription > DXFeedSubscription::create ( EventTypeIt begin,
EventTypeIt end )
inlinestatic

Creates a detached subscription for the given collection of event types.

Example:

auto eventTypes = {dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE};
auto sub = dxfcpp::DXFeedSubscription::create(eventTypes.begin(), eventTypes.end());
std::vector types{dxfcpp::Quote::TYPE, dxfcpp::Trade::TYPE, dxfcpp::Summary::TYPE};
auto sub = dxfcpp::DXFeedSubscription::create(types.begin(), types.end());
Template Parameters
EventTypeItThe collection's iterator type
Parameters
beginThe beginning of the event type collection.
endThe end of an event type collection.
Returns
The new detached subscription for the given collection of event types.

◆ create() [3/4]

template<typename EventTypesCollection>
std::shared_ptr< DXFeedSubscription > DXFeedSubscription::create ( EventTypesCollection && eventTypes)
inlinestatic

Creates a detached subscription for the given collection of event types.

Example:

auto sub = dxfcpp::DXFeedSubscription::create(std::unordered_set{dxfcpp::Quote::TYPE,
dxfcpp::TimeAndSale::TYPE});
std::vector types = {dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE};
auto sub = dxfcpp::DXFeedSubscription::create(types);
Template Parameters
EventTypesCollectionThe type of the collection of event types
Parameters
eventTypesThe event type collection.
Returns
The new detached subscription for the given collection of event types.

◆ create() [4/4]

std::shared_ptr< DXFeedSubscription > DXFeedSubscription::create ( std::initializer_list< EventTypeEnum > eventTypes)
static

Creates a detached subscription for the given collection of event types.

Example:

auto sub = dxfcpp::DXFeedSubscription::create({dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE});
Parameters
eventTypesThe event type collection.
Returns
The new detached subscription for the given collection of event types.

◆ detach()

void DXFeedSubscription::detach ( std::shared_ptr< DXFeed > feed)

Detaches subscription from the specified feed.

Parameters
feedThe feed to detach from.

◆ getAggregationPeriod()

TimePeriod DXFeedSubscription::getAggregationPeriod ( ) const

Returns the aggregation period for data for this subscription instance.

Returns
The aggregation period for data, represented as a TimePeriod object.

◆ getAggregationPeriodInfo()

TimePeriodInfo DXFeedSubscription::getAggregationPeriodInfo ( ) const

Returns the aggregation period that was applied to the events delivered to this subscription: the maximum of the period that the server applies (see DXEndpoint::getAggregationPeriodInfo()) and getAggregationPeriod(), as it was used when the events were delivered.

The value is informational and updates when the events are delivered: it is TimePeriodInfo::UNKNOWN until the first events arrive.

Javadoc.

Returns
The applied aggregation period info, or TimePeriodInfo::UNKNOWN.
Exceptions
InvalidArgumentException
JavaException
GraalException

◆ getDecoratedSymbols()

std::vector< SymbolWrapper > DXFeedSubscription::getDecoratedSymbols ( ) const

Returns a set of decorated symbols (depending on the actual implementation of the subscription).

The resulting set is maybe either a snapshot of the set of the subscribed symbols at the time of invocation or a weakly consistent view of the set.

Returns
A set of decorated subscribed symbols.

◆ getEventsBatchLimit()

std::int32_t DXFeedSubscription::getEventsBatchLimit ( ) const
Returns
maximum number of events in the single notification of OnEventHandler. Special cases are supported for constants ::OPTIMAL_BATCH_LIMIT and ::MAX_BATCH_LIMIT.

◆ getEventTypes()

std::unordered_set< EventTypeEnum > DXFeedSubscription::getEventTypes ( )
overridevirtual

Returns a set of subscribed event types.

Returns
A set of subscribed event types.

Implements ObservableSubscription.

◆ getSymbols()

std::vector< SymbolWrapper > DXFeedSubscription::getSymbols ( ) const

Returns a set of subscribed symbols (depending on the actual implementation of the subscription).

The resulting set is maybe either a snapshot of the set of the subscribed symbols at the time of invocation or a weakly consistent view of the set.

Returns
A set of subscribed symbols.

◆ getTotalDroppedEvents()

std::int64_t DXFeedSubscription::getTotalDroppedEvents ( ) const

Returns the total number of events that were dropped for this subscription since it was created.

Javadoc.

Returns
The total number of dropped events.
Exceptions
InvalidArgumentException
JavaException
GraalException

◆ isClosed()

bool DXFeedSubscription::isClosed ( )
overridevirtual

Returns true if this subscription is closed.

Returns
true if this subscription is closed.
See also
DXFeedSubscription::close()

Implements ObservableSubscription.

◆ onEvent()

DXFeedSubscription::OnEventHandler & DXFeedSubscription::onEvent ( )

Returns a reference to an incoming events' handler (delegate), to which listeners can be added and removed.

Listener can be callable with signature: void(const std::vector<std::shared_ptr<EventType>&)

Example:

auto sub = endpoint->getFeed()->createSubscription({dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE});
auto id = sub->onEvent() += [](auto &&events) {
for (const auto &e : events) {
if (auto quote = e->template sharedAs<dxfcpp::Quote>(); quote) {
std::cout << "Q : " + quote->toString() << std::endl;
} else if (auto tns = e->template sharedAs<dxfcpp::TimeAndSale>(); tns) {
std::cout << "TnS : " + tns->toString() << std::endl;
}
}
};
sub->addSymbols({"$TOP10L/Q", "$SP500#45", "$TICK", "SPX"});
sub->onEvent() -= id;
Returns
The incoming events' handler (delegate)

◆ removeChangeListener()

void DXFeedSubscription::removeChangeListener ( std::size_t id)
overridevirtual

Removes subscription change listener by id.

This method does nothing if the listener with the given id was not installed or was already removed as a subscription change listener for this subscription. Otherwise, it removes the corresponding listener and immediately invokes ObservableSubscriptionChangeListener::onSubscriptionClosed_ on the given listener while holding the lock for this subscription.

Parameters
idThe subscription change listener id.

Implements ObservableSubscription.

◆ removeEventListener()

void DXFeedSubscription::removeEventListener ( std::size_t listenerId)

Removes listener for events.

Example:

auto id = sub->addEventListener([](auto){});
sub->removeEventListener(id);
Parameters
listenerIdThe listener id

◆ removeSymbols() [1/4]

void DXFeedSubscription::removeSymbols ( const SymbolWrapper & symbolWrapper) const

Removes the specified symbol from the set of subscribed symbols.

To conveniently remove one or few symbols, you can use removeSymbols(symbols) method.

Example:

sub->removeSymbols("TSLA");
sub->removeSymbols("XBT/USD:GDAX"s);
sub->removeSymbols("BTC/EUR:CXBITF"sv);
Parameters
symbolWrapperThe symbol.

◆ removeSymbols() [2/4]

void DXFeedSubscription::removeSymbols ( std::initializer_list< SymbolWrapper > collection) const

Removes the specified collection (initializer list) of symbols from the set of subscribed symbols.

Example:

sub->removeSymbols({"AAPL", "IBM"sv, "TSLA"s, "GOOG"_s});
Parameters
collectionThe symbol collection

◆ removeSymbols() [3/4]

template<typename SymbolIt>
void DXFeedSubscription::removeSymbols ( SymbolIt begin,
SymbolIt end ) const
inline

Removes the specified collection (using iterators) of symbols from the set of subscribed symbols.

Example:

auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
sub->removeSymbols(v.begin(), v.end());
Template Parameters
SymbolItThe collection's iterator type
Parameters
beginThe beginning of the symbol collection.
endThe end of the symbol collection.

◆ removeSymbols() [4/4]

template<ConvertibleToSymbolWrapperCollection SymbolsCollection>
void DXFeedSubscription::removeSymbols ( SymbolsCollection && collection) const
inline

Removes the specified collection of symbols from the set of subscribed symbols.

Example:

auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
sub->removeSymbols(std::vector{"AAPL", "IBM"});
sub->removeSymbols(v);
Template Parameters
SymbolsCollectionThe symbol collection's type
Parameters
collectionThe symbol collection

◆ setAggregationPeriod() [1/3]

void DXFeedSubscription::setAggregationPeriod ( const TimePeriod & aggregationPeriod) const

Sets the aggregation period for data.

This method sets a new aggregation period for data, which will only take effect on the next iteration of data notification. For example, if the current aggregation period is 5 seconds, and it is changed to 1 second, the next call to the next call to the retrieve method may take up to 5 seconds, after which the new aggregation period will take effect.

Parameters
aggregationPeriodthe new aggregation period for data

◆ setAggregationPeriod() [2/3]

void DXFeedSubscription::setAggregationPeriod ( std::chrono::milliseconds aggregationPeriod) const

Sets the aggregation period for data.

This method sets a new aggregation period for data, which will only take effect on the next iteration of data notification. For example, if the current aggregation period is 5 seconds, and it is changed to 1 second, the next call to the next call to the retrieve method may take up to 5 seconds, after which the new aggregation period will take effect.

Parameters
aggregationPeriodthe new aggregation period (in millis) for data

◆ setAggregationPeriod() [3/3]

void DXFeedSubscription::setAggregationPeriod ( std::int64_t aggregationPeriod) const

Sets the aggregation period for data.

This method sets a new aggregation period for data, which will only take effect on the next iteration of data notification. For example, if the current aggregation period is 5 seconds, and it is changed to 1 second, the next call to the next call to the retrieve method may take up to 5 seconds, after which the new aggregation period will take effect.

Parameters
aggregationPeriodthe new aggregation period (in millis) for data

◆ setEventsBatchLimit()

void DXFeedSubscription::setEventsBatchLimit ( std::int32_t eventsBatchLimit) const

Sets maximum number of events in the single notification of OnEventHandler.

Special cases are supported for constants ::OPTIMAL_BATCH_LIMIT and ::MAX_BATCH_LIMIT.

Parameters
eventsBatchLimitthe notification events limit
Exceptions
JavaExceptionif eventsBatchLimit < 0 (see ::OPTIMAL_BATCH_LIMIT or ::MAX_BATCH_LIMIT)

◆ setSilenceWatchdog()

void DXFeedSubscription::setSilenceWatchdog ( std::chrono::milliseconds timeout,
OnSilenceHandler onSilence = {} )

Turns the silence watchdog of this subscription on or off.

It is off by default.

When the subscription receives no events for timeout while the endpoint of its feed is connected (DXEndpoint::State::CONNECTED), the library reports a warning through ErrorManager (ErrorInfo::Level::WARN, the component DXFeedSubscription) with the name of the subscription (its number and event types) and the time of the silence, then calls onSilence. This happens once per silence: the next batch of events, a new connection of the endpoint or an attach to a feed arm the watchdog again. The silence is counted from the latest of these: the last batch of events, this call, the attach to a feed and the transition of the endpoint to CONNECTED. A subscription that is attached to no feed, or whose endpoints are not connected, is not watched; with several connected endpoints the earliest connection counts.

The data can stop while the connection stays up: the state of the endpoint does not change, and nothing else tells about it. The watchdog is off by default because a silence is not always a failure: a symbol that does not trade, a quiet market, the hours outside the trading session and a subscription without symbols receive no events for a long time. Choose a timeout above the usual pause of the symbols of the subscription, or watch a separate subscription to a symbol that is always active.

onSilence is called on a thread of the library, one for all the subscriptions, outside of its locks. It may call the methods of the subscription and of the endpoint, for example reconnect:

auto endpoint = DXEndpoint::create()->connect("demo.dxfeed.com:7300");
auto sub = endpoint->getFeed()->createSubscription(Quote::TYPE);
sub->addEventListener<Quote>([](const auto &quotes) { ... });
sub->addSymbols("AAPL");
// A weak pointer: the subscription must not own its endpoint.
sub->setSilenceWatchdog(std::chrono::seconds(30),
[weakEndpoint = std::weak_ptr<DXEndpoint>(endpoint)](const auto &, auto silence) {
if (const auto endpoint = weakEndpoint.lock()) {
endpoint->reconnect();
}
});
std::size_t addEventListener(EventListener &&listener)
Adds listener for events.
Definition DXFeedSubscription.hpp:786
Quote event is a snapshot of the best bid and ask prices, and other fields that change with each quot...
Definition Quote.hpp:38
static const EventTypeEnum & TYPE
Type identifier and additional information about the current event class.
Definition Quote.hpp:71
std::shared_ptr< DXFeed > getFeed() const
Definition DXEndpoint.cpp:528
std::shared_ptr< DXEndpoint > connect(StringParam address)
Connects to the specified remote address.
Definition DXEndpoint.cpp:460
static std::shared_ptr< DXEndpoint > create()
Creates an endpoint with FEED role.
Definition DXEndpoint.cpp:879
std::shared_ptr< DXFeedSubscription > createSubscription(const EventTypeEnum &eventType) const
Creates a new subscription for a single event type that is attached to this feed.
Definition DXFeed.cpp:167

Each new connection arms the watchdog again: if the symbols stay silent, such a function reconnects once per timeout. Count the reconnects or pause them if this is not wanted.

onSilence should return soon: it delays the watchdog of the other subscriptions and the shutdown of the library at exit. Like a listener, it must not call dxfcpp::shutdown(). Its exception is reported through ErrorManager. close() of the subscription and a call with a zero timeout stop the watchdog, but do not wait for a call of onSilence in progress.

A new call replaces the timeout and the function and arms the watchdog again. On a closed subscription it does nothing.

The watchdog receives the events as an event listener does. So, like addEventListener(), on a subscription without event listeners it must be turned on before symbols are added to the attached subscription.

Parameters
timeoutThe silence to report; 0 or less turns the watchdog off.
onSilenceThe function to call, or an empty one for the warning only.
Exceptions
JavaExceptionIllegalStateException if the subscription has no event listeners, is attached and has symbols. The watchdog does not change then.

◆ setSymbols() [1/3]

void DXFeedSubscription::setSymbols ( std::initializer_list< SymbolWrapper > collection) const

Changes the set of subscribed symbols so that it contains just the symbols from the specified collection (initializer list).

Example:

sub->setSymbols({"AAPL", "IBM"sv, "TSLA"s, "GOOG"_s});
Parameters
collectionThe symbol collection

◆ setSymbols() [2/3]

template<typename SymbolIt>
void DXFeedSubscription::setSymbols ( SymbolIt begin,
SymbolIt end ) const
inline

Changes the set of subscribed symbols so that it contains just the symbols from the specified collection (using iterators).

Example:

auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
sub->setSymbols(v.begin(), v.end());
Template Parameters
SymbolItThe collection's iterator type
Parameters
beginThe beginning of the symbol collection.
endThe end of the symbol collection.

◆ setSymbols() [3/3]

template<ConvertibleToSymbolWrapperCollection SymbolsCollection>
void DXFeedSubscription::setSymbols ( SymbolsCollection && collection) const
inline

Changes the set of subscribed symbols so that it contains just the symbols from the specified collection.

Example:

auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
sub->setSymbols(std::vector{"AAPL", "IBM"});
sub->setSymbols(v);
Template Parameters
SymbolsCollectionThe symbol collection's type
Parameters
collectionThe symbol collection

◆ toString()

std::string DXFeedSubscription::toString ( ) const
overridevirtual

Returns a string representation of the current object.

Returns
a string representation

Reimplemented from SharedEntity.

Reimplemented in DXFeedTimeSeriesSubscription.

Member Data Documentation

◆ EVENT_LAG_THRESHOLD_PROPERTY

char DXFeedSubscription::EVENT_LAG_THRESHOLD_PROPERTY[] = "dxfcpp.subscription.eventLagThreshold"
staticconstexpr

"dxfcpp.subscription.eventLagThreshold"

The system property with the age of the newest event of a received batch above which a warning is reported. A time period, 0 (the check is off) by default. Read when a subscription is created. See Listeners and threads.

◆ SLOW_LISTENER_THRESHOLD_PROPERTY

char DXFeedSubscription::SLOW_LISTENER_THRESHOLD_PROPERTY[] = "dxfcpp.subscription.slowListenerThreshold"
staticconstexpr

"dxfcpp.subscription.slowListenerThreshold"

The system property with the time that the listeners of a subscription may take for one batch of events; a longer time is reported as a warning. A time period, 0.1s by default; 0 turns the check off. Read when a subscription is created. See Listeners and threads.

◆ WARNING_PERIOD_PROPERTY

char DXFeedSubscription::WARNING_PERIOD_PROPERTY[] = "dxfcpp.subscription.warningPeriod"
staticconstexpr

"dxfcpp.subscription.warningPeriod"

The system property with the period of the warnings of a slow listener and of lagging events: each check of a subscription reports at most one warning per period. A time period, 1m by default. Read when a subscription is created. See Listeners and threads.