dxFeed Graal CXX API
Loading...
Searching...
No Matches
OnDemandService Struct Reference

Provides on-demand historical tick data replay controls. More...

#include <OnDemandService.hpp>

+ Inheritance diagram for OnDemandService:

Public Types

using Ptr = std::shared_ptr<OnDemandService>
 The alias to a type of shared pointer to the OnDemandService object.
 
using Unique = std::unique_ptr<OnDemandService>
 The alias to a type of unique pointer to the OnDemandService 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

std::shared_ptr< DXEndpointgetEndpoint () const noexcept
 Returns DXEndpoint that is associated with this on-demand service.
 
bool isReplaySupported () const noexcept
 Returns true when on-demand historical data replay mode is supported.
 
bool isReplay () const noexcept
 Returns true when this on-demand historical data replay service is in replay mode.
 
bool isClear () const noexcept
 Returns true when this on-demand historical data replay service is in clear mode.
 
std::int64_t getTime () const noexcept
 Returns current or last on-demand historical data replay time.
 
double getSpeed () const noexcept
 Returns on-demand historical data replay speed.
 
void replay (std::int64_t time) const noexcept
 Turns on-demand historical data replay mode from a specified time with real-time speed.
 
void replay (std::int64_t time, double speed) const noexcept
 Turns on-demand historical data replay mode from a specified time and with a specified speed.
 
void pause () const noexcept
 Pauses on-demand historical data replay and keeps data snapshot.
 
void stopAndResume () const noexcept
 Stops on-demand historical data replay and resumes ordinary data feed.
 
void stopAndClear () const noexcept
 Stops incoming data and clears it without resuming data updates.
 
void setSpeed (double speed) const noexcept
 Changes on-demand historical data replay speed while continuing replay at current time.
 
- 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.
 
virtual std::string toString () const noexcept
 Returns a string representation of the current object.
 
- Public Member Functions inherited from Entity
virtual ~Entity () noexcept=default
 The default virtual d-tor.
 

Static Public Member Functions

static std::shared_ptr< OnDemandServicegetInstance () noexcept
 Returns on-demand service for the default DXEndpoint instance with ON_DEMAND_FEED role that is not connected to any other real-time or delayed data feed.
 
static std::shared_ptr< OnDemandServicegetInstance (std::shared_ptr< DXEndpoint > endpoint)
 Returns on-demand service for the specified DXEndpoint.
 

Detailed Description

Provides on-demand historical tick data replay controls.

This class is used to seamlessly transition from ordinary real-time or delayed data feed to the replay of the tick-by-tick history of market data behaviour without any changes to the code that consumes and process these market events.

As single OnDemandService instance is conceptually associated with each DXEndpoint endpoint instance with the role of FEED or ON_DEMAND_FEED. You can retrieve OnDemandService instance that is associated with a given DXEndpoint using getInstance(endpoint) method.

For example, OnDemandService instance for a default DXFeed that is featured in the documentation of DXFeed class and is retrieved via DXFeed::getInstance() method can be acquired with the following code:


auto endpoint = DXEndpoint::getInstance();
auto onDemand = OnDemandService::getInstance(endpoint);

This instance can be used for on-demand historical tick data replay only when endpoint is connected to the on-demand data provider and the appropriate credentials are provided. isReplaySupported returns true when it is so.

On-demand replay is started with replay method that takes time as a parameter. DXFeed is then disconnected from other data providers, pre-buffers historical tick data for replay, and starts replay of the data as if it was coming from the data feeds now. All the usual APIs that are part of DXFeed like subscription and various dxFeed models can be used normally as with the ordinary real-time or delayed data feed.

Replay speed can be changed on the fly with setSpeed method or it can be set initially when starting replay with a two-argument version of replay method. pause method is the same as setSpeed(0).

stopAndResume method stops data replay and resumes ordinary real-time or delayed data feed that was used before replay method was invoked. Endpoints with a role of ON_DEMAND_FEED do not have an ordinary feed (they are essentially on-demand only) and thus stopAndResume method works like stopAndClear for them.

State and change notifications

On-demand historical tick data replay state can be queried with isReplaySupported, isReplay, getSpeed, and getTime methods.

Threads and locks

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

Member Function Documentation

◆ getEndpoint()

std::shared_ptr< DXEndpoint > OnDemandService::getEndpoint ( ) const
noexcept

Returns DXEndpoint that is associated with this on-demand service.

Returns
DXEndpoint that is associated with this on-demand service.

◆ getInstance() [1/2]

std::shared_ptr< OnDemandService > OnDemandService::getInstance ( )
staticnoexcept

Returns on-demand service for the default DXEndpoint instance with ON_DEMAND_FEED role that is not connected to any other real-time or delayed data feed.

This method is a shortcut for:


OnDemandService::getInstance(DXEndpoint::getInstance(DXEndpoint::Role::ON_DEMAND_FEED))

If you need an instance of OnDemandService to seamlessly switch from other real-time or delayed data feed to on-demand historical tick data replay, then use {getInstance(endpoint) method for a specific endpoint that you are using.

Returns
on-demand endpoint for the default DXEndpoint instance.

References DXEndpoint::ON_DEMAND_FEED.

◆ getInstance() [2/2]

std::shared_ptr< OnDemandService > OnDemandService::getInstance ( std::shared_ptr< DXEndpoint > endpoint)
static

Returns on-demand service for the specified DXEndpoint.

Each DXEndpoint is conceptually associated with a single instance of on-demand service to control its historic data replay and this method returns this instance. The endpoint must have a role of FEED or ON_DEMAND_FEED.

Parameters
endpointthe endpoint.
Returns
the on-demand service.

◆ getSpeed()

double OnDemandService::getSpeed ( ) const
noexcept

Returns on-demand historical data replay speed.

Speed is measured with respect to the real-time playback speed. The result of this method is zero when this service is not in replay mode. The speed is set when starting replay by replay(time, speed) method and with setSpeed(speed) method during replay.

Returns
on-demand historical data replay speed.

◆ getTime()

std::int64_t OnDemandService::getTime ( ) const
noexcept

Returns current or last on-demand historical data replay time.

In replay mode this is the time that is being currently replayed, otherwise this is the last time that was replayed. If replay was never started, then result is 0.

Returns
current or last on-demand historical data replay time in millis.

◆ isClear()

bool OnDemandService::isClear ( ) const
noexcept

Returns true when this on-demand historical data replay service is in clear mode.

Clear mode is in effect after invocation of stopAndClear method and before invocation stopAndResume or replay methods.

Returns
true when this on-demand historical data replay service is in clear mode.

◆ isReplay()

bool OnDemandService::isReplay ( ) const
noexcept

Returns true when this on-demand historical data replay service is in replay mode.

Replay mode is in effect after invocation of replay method and before invocation stopAndResume or stopAndClear methods.

Returns
true when this on-demand historical data replay service is in replay mode.

◆ isReplaySupported()

bool OnDemandService::isReplaySupported ( ) const
noexcept

Returns true when on-demand historical data replay mode is supported.

DXEndpoint should be connected to an address with "(ondemand:<address>)" component that specifies an on-demand historical data provider address. When this method returns false, replay method does nothing.

Returns
true when on-demand historical data replay mode is supported.

◆ pause()

void OnDemandService::pause ( ) const
noexcept

Pauses on-demand historical data replay and keeps data snapshot.

This method can only be called in replay mode. This is a shortcut for:


    setSpeed(0);

This method atomically captures current replay time and pauses at it. After invocation of this method:

◆ replay() [1/2]

void OnDemandService::replay ( std::int64_t time) const
noexcept

Turns on-demand historical data replay mode from a specified time with real-time speed.

This is a shortcut for:


    replay(time, 1);

This method can be used only when OnDemandService::isReplaySupported() method returns true, that is when DXEndpoint is connected to an address with "(ondemand:<address>)" component that specifies an on-demand historical data provider address.

Parameters
timetime (timestamp in millis) to start replay from.

◆ replay() [2/2]

void OnDemandService::replay ( std::int64_t time,
double speed ) const
noexcept

Turns on-demand historical data replay mode from a specified time and with a specified speed.

This method can be used only when OnDemandService::isReplaySupported() method returns true, that is when DXEndpoint is connected to an address with "(ondemand:<address>)" component that specifies an on-demand historical data provider address.

After invocation of this method:

Parameters
timetime (timestamp in millis) to start replay from.
speedspeed to start replay with. Use 1 for real-time speed, >1 for faster than real-time speed, <1 for slower than real-time speed, and 0 for pause.

◆ setSpeed()

void OnDemandService::setSpeed ( double speed) const
noexcept

Changes on-demand historical data replay speed while continuing replay at current time.

Speed is measured with respect to the real-time playback speed. This method can only be called with non-zero speed in replay mode.

Parameters
speedon-demand historical data replay speed.

◆ stopAndClear()

void OnDemandService::stopAndClear ( ) const
noexcept

Stops incoming data and clears it without resuming data updates.

This method works both in on-demand historical data replay mode and for ordinary data feed. All incoming data updates are suspended and current data is cleared. After invocation of this method:

Ordinary data feed can be resumed with OnDemandService::stopAndResume() method and on-demand historical data replay can be continued with replay(...) method.

◆ stopAndResume()

void OnDemandService::stopAndResume ( ) const
noexcept

Stops on-demand historical data replay and resumes ordinary data feed.

This method has no effect when invoked not in replay mode. After invocation of this method:

To stop on-demand historical data replay without resuming ordinary data feed use either OnDemandService::pause() to keep data snapshot or OnDemandService::stopAndClear() to clear data.

Note, that endpoints with a role of ON_DEMAND_FEED do not have an ordinary feed (they are essentially on-demand only) and thus stopAndResume method works like stopAndClear for them.