dxFeed Graal CXX API v4.0.0
Loading...
Searching...
No Matches
TimeSeriesTxModel< E > Struct Template Referencefinal

An incremental model for time-series events. More...

#include <TimeSeriesTxModel.hpp>

+ Inheritance diagram for TimeSeriesTxModel< E >:

Classes

struct  Builder
 A builder class for creating an instance of TimeSeriesTxModel. More...
 

Public Member Functions

 ~TimeSeriesTxModel () noexcept override
 Calls close method and destructs this model.
 
bool isBatchProcessing () const
 Returns whether batch processing is enabled.
 
bool isSnapshotProcessing () const
 Returns whether snapshot processing is enabled.
 
void attach (const std::shared_ptr< DXFeed > &feed) const
 Attaches this model to the specified feed.
 
void detach (const std::shared_ptr< DXFeed > &feed) const
 Detaches this model from the specified feed.
 
void close () const
 Closes this model and makes it permanently detached.
 
std::int64_t getFromTime () const
 Returns the time from which to subscribe for time-series, or std::numeric_limits<std::int64_t>::max() if this model is not subscribed (this is a default value).
 
void setFromTime (std::int64_t fromTime) const
 Sets the time from which to subscribe for time-series.
 
void setFromTime (std::chrono::milliseconds fromTime) const
 Sets the time from which to subscribe for time-series.
 
std::string toString () const 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< BuildernewBuilder ()
 Factory method to create a new builder for this model.
 
- Static Public Member Functions inherited from RequireMakeShared< TimeSeriesTxModel< E > >
static auto createShared (Args &&...args)
 Creates smart pointer to object.
 

Additional Inherited Members

- Public Types inherited from SharedEntity
using Ptr = std::shared_ptr<SharedEntity>
 The alias to a type of shared pointer to the SharedEntity object.
 

Detailed Description

template<Derived< TimeSeriesEvent > E>
struct TimeSeriesTxModel< E >

An incremental model for time-series events.

This model manages all snapshot and transaction logic, subscription handling, and listener notifications.

This model is designed to handle incremental transactions. Users of this model only see the list of events in a consistent state. This model delays incoming events that are part of an incomplete snapshot or ongoing transaction until the snapshot is complete or the transaction has ended. This model notifies the user of received transactions through an installed listener.

Configuration

This model must be configured using the builder, as most configuration settings cannot be changed once the model is built. This model requires configuration with a symbol and a fromTime for subscription, and it must be attached to a DXFeed instance to begin operation. For ease of use, some of these configurations can be changed after the model is built, see setFromTime, attach.

This model only supports single symbol subscriptions; multiple symbols cannot be configured.

Resource management and closed models

Attached model is a potential memory leak. If the pointer to attached model is lost, then there is no way to detach this model from the feed.

The convenient way to detach model from the feed is to call its close method (it is automatically called when the destructor is called, i.e. RAII). Closed model becomes permanently detached from all feeds, removes all its listeners.

Threads and locks

This class is thread-safe and can be used concurrently from multiple threads without external synchronization.

Sample:

auto feed = DXEndpoint::getInstance(DXEndpoint::Role::FEED)->connect("demo.dxfeed.com:7300")->getFeed();
auto listener = TimeSeriesTxModelListener<Candle>::create([](const auto &events, bool isSnapshot) {
if (isSnapshot) {
std::cout << "Snapshot:" << std::endl;
} else {
std::cout << "Update:" << std::endl;
}
for (const auto &e : events) {
std::cout << "[" << e->getEventFlagsMask().toString() << "]:" << e << std::endl;
}
std::cout << std::endl;
});
->withFeed(feed)
->withBatchProcessing(true)
->withSnapshotProcessing(true)
->withFromTime(std::chrono::milliseconds(dxfcpp::now()) - std::chrono::days(3))
->withListener(listener)
->withSymbol(CandleSymbol::valueOf("AAPL&Q{=1m}"))
->build();
std::this_thread::sleep_for(10s);
static CandleSymbol valueOf(std::string symbol) noexcept
Converts the given string symbol into the candle symbol object.
Definition CandleSymbol.hpp:291
@ FEED
FEED endpoint connects to the remote data feed provider and is optimized for real-time or delayed dat...
std::shared_ptr< DXFeed > getFeed()
Definition DXEndpoint.cpp:229
std::shared_ptr< DXEndpoint > connect(const std::string &address)
Connects to the specified remote address.
Definition DXEndpoint.cpp:170
static std::shared_ptr< DXEndpoint > getInstance()
Returns a default application-wide singleton instance of DXEndpoint with a FEED role.
Definition DXEndpoint.cpp:426
static std::shared_ptr< Builder > newBuilder()
Factory method to create a new builder for this model.
Definition TimeSeriesTxModel.hpp:359
static std::shared_ptr< TimeSeriesTxModelListener< E > > create(std::function< void(const std::vector< std::shared_ptr< E > > &, bool)> onEventsReceived)
Creates a listener for receiving time series events (with instantiation by event type E and verificat...
Definition TxModelListener.hpp:176
Template Parameters
EThe type of event (derived from TimeSeriesEvent)

Member Function Documentation

◆ attach()

template<Derived< TimeSeriesEvent > E>
void TimeSeriesTxModel< E >::attach ( const std::shared_ptr< DXFeed > & feed) const
inline

Attaches this model to the specified feed.

Technically, this model can be attached to multiple feeds at once, but this is rarely needed and not recommended.

Parameters
feedThe feed to attach to.

◆ close()

template<Derived< TimeSeriesEvent > E>
void TimeSeriesTxModel< E >::close ( ) const
inline

Closes this model and makes it permanently detached.

This method clears installed listener.

Referenced by TimeSeriesTxModel< E >::~TimeSeriesTxModel().

◆ detach()

template<Derived< TimeSeriesEvent > E>
void TimeSeriesTxModel< E >::detach ( const std::shared_ptr< DXFeed > & feed) const
inline

Detaches this model from the specified feed.

Parameters
feedThe feed to detach from.

◆ getFromTime()

template<Derived< TimeSeriesEvent > E>
std::int64_t TimeSeriesTxModel< E >::getFromTime ( ) const
inline

Returns the time from which to subscribe for time-series, or std::numeric_limits<std::int64_t>::max() if this model is not subscribed (this is a default value).

Returns
The time in milliseconds, since Unix epoch of January 1, 1970.

◆ isBatchProcessing()

template<Derived< TimeSeriesEvent > E>
bool TimeSeriesTxModel< E >::isBatchProcessing ( ) const
inline

Returns whether batch processing is enabled.

See withBatchProcessing.

Returns
true if batch processing is enabled; false otherwise.

◆ isSnapshotProcessing()

template<Derived< TimeSeriesEvent > E>
bool TimeSeriesTxModel< E >::isSnapshotProcessing ( ) const
inline

Returns whether snapshot processing is enabled.

See withSnapshotProcessing.

Returns
true if snapshot processing is enabled; false otherwise.

◆ newBuilder()

template<Derived< TimeSeriesEvent > E>
static std::shared_ptr< Builder > TimeSeriesTxModel< E >::newBuilder ( )
inlinestatic

Factory method to create a new builder for this model.

auto builder = model->newBuilder();
Returns
A new builder instance.

◆ setFromTime() [1/2]

template<Derived< TimeSeriesEvent > E>
void TimeSeriesTxModel< E >::setFromTime ( std::chrono::milliseconds fromTime) const
inline

Sets the time from which to subscribe for time-series.

If this time has already been set, nothing happens.

Parameters
fromTimeThe duration in milliseconds, since Unix epoch of January 1, 1970.

◆ setFromTime() [2/2]

template<Derived< TimeSeriesEvent > E>
void TimeSeriesTxModel< E >::setFromTime ( std::int64_t fromTime) const
inline

Sets the time from which to subscribe for time-series.

If this time has already been set, nothing happens.

Parameters
fromTimeThe time in milliseconds, since Unix epoch of January 1, 1970.

◆ toString()

template<Derived< TimeSeriesEvent > E>
std::string TimeSeriesTxModel< E >::toString ( ) const
inlineoverridevirtual

Returns a string representation of the current object.

Returns
a string representation

Reimplemented from SharedEntity.