Skip to content

Commit

Permalink
[MDAPI-37][C++] Retrieve latest events from feed
Browse files Browse the repository at this point in the history
DXFeed::getLastEvents
  • Loading branch information
ttldtor committed Jul 26, 2024
1 parent 218a7a2 commit 718b990
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
21 changes: 20 additions & 1 deletion include/dxfeed_graal_cpp_api/api/DXFeed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ struct DXFCPP_EXPORT DXFeed : SharedEntity {
* @ref DXEndpoint::Role::STREAM_FEED "STREAM_FEED" role (never fills in the event).
*
* @tparam E The type of event.
* @param event the event.
* @param event The event.
* @return The same event.
*/
template <Derived<LastingEvent> E> std::shared_ptr<E> getLastEvent(std::shared_ptr<E> event) {
Expand All @@ -232,6 +232,25 @@ struct DXFCPP_EXPORT DXFeed : SharedEntity {
return event;
}

/**
* Returns the last events for the specified list of event instances.
* This is a bulk version of @ref ::getLastEvent() "getLastEvent" method.
*
* <p>Note, that this method does not work when DXEndpoint was created with
* @ref DXEndpoint::Role::STREAM_FEED "STREAM_FEED" role.
*
* @tparam Collection The collection type.
* @param events The collection of shared ptrs of events.
* @return The same collection of shared ptrs of events.
*/
template <typename Collection> const Collection &getLastEvents(const Collection &events) {
for (auto e : events) {
getLastEvent(e);
}

return events;
}

/**
* Creates new subscription for a single event type that is <i>attached</i> to this feed.
* This method creates new DXFeedSubscription and invokes @link DXFeed::attachSubscription.
Expand Down
10 changes: 9 additions & 1 deletion samples/cpp/DxFeedSample/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <dxfeed_graal_cpp_api/api.hpp>

#include <iostream>
#include <chrono>
#include <iostream>
#include <memory>

using namespace dxfcpp;
Expand Down Expand Up @@ -59,6 +59,14 @@ void testTradeSnapshots(const std::string &symbol) {
auto feed = DXFeed::getInstance();
auto sub = feed->createSubscription(Trade::TYPE);

std::vector e = {std::make_shared<TimeAndSale>("AAPL"), std::make_shared<TimeAndSale>("IBM")};
auto x = std::remove_reference_t<std::remove_pointer_t<
typename std::iterator_traits<std::vector<std::shared_ptr<Quote>>::iterator>::value_type>>();

decltype(x) y;

auto z = feed->getLastEvents(e);

sub->addSymbols(symbol);

while (true) {
Expand Down

0 comments on commit 718b990

Please sign in to comment.