dxFeed Graal CXX API
|
Main entry class for dxFeed API (read it first). More...
#include <DXFeed.hpp>
Public Types | |
using | Ptr = std::shared_ptr<DXFeed> |
The alias to a type of shared pointer to the DXFeed object. | |
using | Unique = std::unique_ptr<DXFeed> |
The alias to a type of unique pointer to the DXFeed 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 | |
void | attachSubscription (std::shared_ptr< DXFeedSubscription > subscription) noexcept |
Attaches the given subscription to this feed. | |
void | detachSubscription (std::shared_ptr< DXFeedSubscription > subscription) noexcept |
Detaches the given subscription from this feed. | |
void | detachSubscriptionAndClear (std::shared_ptr< DXFeedSubscription > subscription) noexcept |
Detaches the given subscription from this feed and clears data delivered to this subscription by publishing empty events. | |
std::shared_ptr< DXFeedSubscription > | createSubscription (const EventTypeEnum &eventType) noexcept |
Creates new subscription for a single event type that is attached to this feed. | |
template<typename EventTypeIt > | |
std::shared_ptr< DXFeedSubscription > | createSubscription (EventTypeIt begin, EventTypeIt end) noexcept |
Creates new subscription for multiple event types that is attached to this feed. | |
std::shared_ptr< DXFeedSubscription > | createSubscription (std::initializer_list< EventTypeEnum > eventTypes) noexcept |
Creates new subscription for multiple event types that is attached to this feed. | |
template<typename EventTypesCollection > | |
std::shared_ptr< DXFeedSubscription > | createSubscription (EventTypesCollection &&eventTypes) noexcept |
Creates new subscription for multiple event types that is attached to this feed. | |
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< DXFeed > | getInstance () noexcept |
Returns a default application-wide singleton instance of feed. | |
Friends | |
struct | DXEndpoint |
Main entry class for dxFeed API (read it first).
This section gives sample usage scenarios.
There is a singleton instance of the feed that is returned by DXFeed::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 and credentials using "@ref DXEndpoint::DXFEED_ADDRESS_PROPERTY "dxfeed.address"", "@ref DXEndpoint::DXFEED_USER_PROPERTY "dxfeed.user"", and "@ref DXEndpoint::DXFEED_PASSWORD_PROPERTY "dxfeed.password"" system properties or by putting them into "@ref DXEndpoint::DXFEED_PROPERTIES_PROPERTY "dxfeed.properties"" file in the same directory. dxFeed API samples come with a ready-to-use "<b>dxfeed.properties</b>" file that contains an address of dxFeed demo feed at "<b>demo.dxfeed.com:7300</b>" and demo access credentials.
The following code creates listener that prints mid price for each quote and subscribes for quotes on SPDR S&P 500 ETF symbol:
auto sub = DXFeed::getInstance()->createSubscription(Quote::TYPE);
sub->addEventListener<Quote>([](const auto& quotes) {
for (const auto& quote : quotes) {
std::cout << "Mid = " + (quote->getBidPrice() + quote->getAskPrice()) / 2) << std::endl;
}
});
sub->addSymbols("SPY");
Note, that order of calls is important here. By attaching listeners first and then setting subscription we ensure that the current quote gets received by the listener. See DXFeedSubscription::addSymbols() for details. If a set of symbols is changed first, then sub->addEventListener raises an IllegalStateException in JVM to protected from hard-to-catch bugs with potentially missed events.
The following code creates listener that prints each received event and subscribes for quotes and trades on SPDR S&P 500 ETF symbol:
auto sub = DXFeed::getInstance()->createSubscription({Quote::TYPE, Trade::TYPE});
sub->addEventListener([](auto&& events) {
for (const auto& event : events) {
std::cout << event << std::endl;
}
});
sub->addSymbols("SPY");
The following code subscribes for trades on SPDR S&P 500 ETF symbol and prints last trade every second.
using namespace std::chrono_literals;
auto sub = DXFeed::getInstance()->createSubscription({Trade::TYPE});
sub->addSymbols("SPY");
auto feed = DXFeed::getInstance();
while (true) {
std::cout << System.out.println(feed->getLastEvent(Trade::create("SPY")));
std::this_thread::sleep_for(1000ms);
}
This class is thread-safe and can be used concurrently from multiple threads without external synchronization.
|
noexcept |
Attaches the given subscription to this feed.
This method does nothing if the corresponding subscription is already attached to this feed.
This feed publishes data to the attached subscription. Application can attach event listener via DXFeedSubscription::addEventListener to get notified about data changes and can change its data subscription via DXFeedSubscription methods.
This method adds a non-serializable ObservableSubscriptionChangeListener for the given subscription via DXFeedSubscription::addChangeListener method.
subscription | The subscription. |
|
noexcept |
Creates new subscription for a single event type that is attached to this feed.
This method creates new DXFeedSubscription and invokes Example: {cpp} auto sub = dxfcpp::DXFeed::getInstance()->createSubscription(dxfcpp::Quote::TYPE); eventType The type of event The new subscription
References EventTypeEnum::getName(), and toString().
|
inlinenoexcept |
Creates new subscription for multiple event types that is attached to this feed.
This method creates new DXFeedSubscription and invokes Example: {cpp} auto eventTypes = {dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE}; auto sub = dxfcpp::DXFeed::getInstance()->createSubscription(eventTypes.begin(), eventTypes.end()); {cpp} std::vector types{dxfcpp::Quote::TYPE, dxfcpp::Trade::TYPE, dxfcpp::Summary::TYPE}; auto sub = dxfcpp::DXFeedSubscription::create(types.begin(), types.end()); {cpp} std::set types{dxfcpp::Quote::TYPE, dxfcpp::Trade::TYPE, dxfcpp::Summary::TYPE}; auto endpoint = dxfcpp::DXEndpoint::newBuilder()->withRole(dxfcpp::DXEndpoint::Role::FEED)->build(); auto sub = endpoint->getFeed()->createSubscription(eventTypes.begin(), eventTypes.end()); endpoint->connect("demo.dxfeed.com:7300"); EventTypeIt The iterator type of the collection of event types begin The start iterator end The end iterator The new subscription
|
inlinenoexcept |
Creates new subscription for multiple event types that is attached to this feed.
This method creates new DXFeedSubscription and invokes Example: {cpp} auto sub = dxfcpp::DXFeed::getInstance()->createSubscription(std::unordered_set{dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE}); {cpp} std::vector types = {dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE}; auto sub = dxfcpp::DXFeed::getInstance()->createSubscription(types); EventTypesCollection The class of the collection of event types eventTypes The collection of event types The new subscription
|
noexcept |
Creates new subscription for multiple event types that is attached to this feed.
This method creates new DXFeedSubscription and invokes Example: {cpp} auto sub = dxfcpp::DXFeed::getInstance()->createSubscription({dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE}); eventTypes The initializer list of event types The new subscription
|
noexcept |
Detaches the given subscription from this feed.
This method does nothing if the corresponding subscription is not attached to this feed.
This method removes ObservableSubscriptionChangeListener from the given subscription via DXFeedSubscription::removeChangeListener method.
subscription | The subscription. |
|
noexcept |
Detaches the given subscription from this feed and clears data delivered to this subscription by publishing empty events.
This method does nothing if the corresponding subscription is not attached to this feed.
subscription | The subscription. |
|
staticnoexcept |
Returns a default application-wide singleton instance of feed.
Most applications use only a single data-source and should rely on this method to get one. This is a shortcut to DXEndpoint::getInstance()->getFeed().
|
overridevirtualnoexcept |
Returns a string representation of the current object.
Reimplemented from SharedEntity.
Referenced by createSubscription().