dxFeed Graal CXX API v8.1.0
Loading...
Searching...
No Matches
DXFeedSubscription.hpp
1// Copyright (c) 2026 Devexperts LLC.
2// SPDX-License-Identifier: MPL-2.0
3
4#pragma once
5
6#include "../internal/Conf.hpp"
7
9
10#include "../entity/EntityModule.hpp"
11#include "../event/EventType.hpp"
12#include "../event/EventTypeEnum.hpp"
13#include "../internal/Common.hpp"
14#include "../internal/EventClassList.hpp"
15#include "../internal/Handler.hpp"
16#include "../internal/JavaObjectHandle.hpp"
17#include "../internal/context/ApiContext.hpp"
18#include "../internal/managers/EntityManager.hpp"
19#include "../symbols/SymbolWrapper.hpp"
20#include "../util/TimePeriod.hpp"
21#include "./osub/ObservableSubscription.hpp"
22
23#include <concepts>
24#include <memory>
25#include <mutex>
26#include <type_traits>
27#include <unordered_set>
28
29/**
30 * \addtogroup dxfcpp_api
31 * @{
32 */
33
35
36struct DXFeed;
37struct MarketEvent;
38struct IndexedEvent;
39struct TimeSeriesEvent;
40struct LastingEvent;
41
42/**
43 * Subscription for a set of symbols and event types.
44 */
46 public:
47 static constexpr std::size_t FAKE_CHANGE_LISTENER_ID{static_cast<std::size_t>(-1)};
48
49 ///
50 using OnEventHandler = SimpleHandler<void(const std::vector<std::shared_ptr<EventType>> &)>;
51
52 // These constants are linked with the same ones in RecordBuffer - POOLED_CAPACITY and UNLIMITED_CAPACITY.
53 /**
54 * The optimal events' batch limit for a single notification in OnEventHandler.
55 */
56 static const std::int32_t OPTIMAL_BATCH_LIMIT = 0;
57
58 /**
59 * The maximum events' batch limit for a single notification in OnEventHandler.
60 */
62
63 protected:
64 friend struct DXFeed;
65
66 inline static std::atomic<std::size_t> lastChangeListenerId_{};
67
68 struct Impl;
69
70 std::unique_ptr<Impl> impl_;
71
72 std::unordered_set<EventTypeEnum> eventTypes_;
73 JavaObjectHandle<DXFeedSubscription> handle_;
74
75 std::mutex eventListenerMutex_{};
76 JavaObjectHandle<DXFeedEventListener> eventListenerHandle_;
77 OnEventHandler onEvent_{};
79 mutable std::recursive_mutex changeListenersMutex_{};
80
81 static JavaObjectHandle<DXFeedSubscription>
82 createSubscriptionHandleFromEventClassList(const std::unique_ptr<EventClassList> &list);
83
84 void setEventListenerHandle(Id<DXFeedSubscription> id);
85
86 bool tryToSetEventListenerHandle();
87
88 void setSymbolsImpl(void *graalSymbolList) const;
89 void addSymbolsImpl(void *graalSymbolList) const;
90 void removeSymbolsImpl(void *graalSymbolList) const;
91
92 DXFeedSubscription();
93
94 DXFeedSubscription(const EventTypeEnum &eventType);
95
96 DXFeedSubscription(const EventTypeEnum &eventType, JavaObjectHandle<DXFeedSubscription> &&handle);
97
98 template <typename EventTypeIt>
99#if __cpp_concepts
100 requires requires(EventTypeIt iter) {
102 }
103#endif
105 if constexpr (Debugger::isDebug) {
106 // ReSharper disable once CppDFAUnreachableCode
107 Debugger::debug("DXFeedSubscription(eventTypes = " + namesToString(begin, end) + ")");
108 }
109
111
113
115 }
116
117 template <typename EventTypeIt>
118#if __cpp_concepts
119 requires requires(EventTypeIt iter) {
121 }
122#endif
125 if constexpr (Debugger::isDebug) {
126 // ReSharper disable once CppDFAUnreachableCode
127 Debugger::debug("DXFeedSubscription(eventTypes = " + namesToString(begin, end) + ")");
128 }
129
132 }
133
134 public:
135 /// The alias to a type of shared pointer to the DXFeedSubscription object
137
138 /// The alias to a type of unique pointer to the DXFeedSubscription object
140
141 DXFeedSubscription(LockExternalConstructionTag);
142
143 DXFeedSubscription(LockExternalConstructionTag, const EventTypeEnum &eventType);
144
145 template <typename EventTypeIt>
146#if __cpp_concepts
147 requires requires(EventTypeIt iter) {
149 }
150#endif
153 }
154
156
157 template <typename EventTypesCollection>
158 explicit DXFeedSubscription(LockExternalConstructionTag tag, EventTypesCollection &&eventTypes)
159#if __cpp_concepts
160 requires requires {
161 {
162 DXFeedSubscription(tag, std::begin(std::forward<EventTypesCollection>(eventTypes)),
163 std::end(std::forward<EventTypesCollection>(eventTypes)))
164 };
165 }
166#endif
167 : DXFeedSubscription(tag, std::begin(std::forward<EventTypesCollection>(eventTypes)),
168 std::end(std::forward<EventTypesCollection>(eventTypes))) {
169 }
170
171 ///
172 std::string toString() const override;
173
174 ~DXFeedSubscription() override;
175
176 /**
177 * Creates a <i>detached</i> subscription for a single event type.
178 *
179 * Example:
180 * ```cpp
181 * auto sub = dxfcpp::DXFeedSubscription::create(dxfcpp::Quote::TYPE);
182 * ```
183 *
184 * @param eventType the event type.
185 */
186 static std::shared_ptr<DXFeedSubscription> create(const EventTypeEnum &eventType);
187
188 /**
189 * Creates a <i>detached</i> subscription for the given collection of event types.
190 *
191 * Example:
192 * ```cpp
193 * auto eventTypes = {dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE};
194 *
195 * auto sub = dxfcpp::DXFeedSubscription::create(eventTypes.begin(), eventTypes.end());
196 * ```
197 *
198 * ```cpp
199 * std::vector types{dxfcpp::Quote::TYPE, dxfcpp::Trade::TYPE, dxfcpp::Summary::TYPE};
200 *
201 * auto sub = dxfcpp::DXFeedSubscription::create(types.begin(), types.end());
202 * ```
203 *
204 * @tparam EventTypeIt The collection's iterator type
205 * @param begin The beginning of the event type collection.
206 * @param end The end of an event type collection.
207 * @return The new <i>detached</i> subscription for the given collection of event types.
208 */
209 template <typename EventTypeIt>
210#if __cpp_concepts
211 requires requires(EventTypeIt iter) {
213 }
214#endif
216 if constexpr (Debugger::isDebug) {
217 // ReSharper disable once CppDFAUnreachableCode
218 Debugger::debug("DXFeedSubscription::create(eventTypes = " + namesToString(begin, end) + ")");
219 }
220
221 auto sub = createShared(begin, end);
223
225
226 return sub;
227 }
228
229 /**
230 * Creates a <i>detached</i> subscription for the given collection of event types.
231 *
232 * Example:
233 * ```cpp
234 * auto sub = dxfcpp::DXFeedSubscription::create({dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE});
235 * ```
236 *
237 * @param eventTypes The event type collection.
238 * @return The new <i>detached</i> subscription for the given collection of event types.
239 */
241
242 /**
243 * Creates a <i>detached</i> subscription for the given collection of event types.
244 *
245 * Example:
246 * ```cpp
247 * auto sub = dxfcpp::DXFeedSubscription::create(std::unordered_set{dxfcpp::Quote::TYPE,
248 * dxfcpp::TimeAndSale::TYPE});
249 * ```
250 *
251 * ```cpp
252 * std::vector types = {dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE};
253 * auto sub = dxfcpp::DXFeedSubscription::create(types);
254 * ```
255 *
256 * @tparam EventTypesCollection The type of the collection of event types
257 * @param eventTypes The event type collection.
258 * @return The new <i>detached</i> subscription for the given collection of event types.
259 */
260 template <typename EventTypesCollection>
261 static std::shared_ptr<DXFeedSubscription> create(EventTypesCollection &&eventTypes) {
262 auto sub = createShared(std::forward<EventTypesCollection>(eventTypes));
263 auto id = ApiContext::getInstance()->getManager<EntityManager<DXFeedSubscription>>()->registerEntity(sub);
264
265 dxfcpp::ignoreUnused(id);
266
267 return sub;
268 }
269
270 /**
271 * Attaches subscription to the specified feed.
272 *
273 * @param feed The feed to attach to.
274 */
275 void attach(std::shared_ptr<DXFeed> feed);
276
277 /**
278 * Detaches subscription from the specified feed.
279 *
280 * @param feed The feed to detach from.
281 */
282 void detach(std::shared_ptr<DXFeed> feed);
283
284 /**
285 * Returns `true` if this subscription is closed.
286 *
287 * @return `true` if this subscription is closed.
288 *
289 * @see DXFeedSubscription::close()
290 */
291 bool isClosed() override;
292
293 /**
294 * Closes this subscription and makes it <i>permanently detached</i>.
295 * This method notifies all installed instances of subscription change listeners by invoking `subscriptionClosed`
296 * while holding the lock for this subscription. This method clears lists of all installed
297 * event listeners and subscription change listeners and makes sure that no more listeners
298 * can be added.
299 */
300 void close() const;
301
302 /**
303 * Returns a set of subscribed event types.
304 *
305 * @return A set of subscribed event types.
306 */
308
309 /**
310 * Returns `true` if this subscription contains the corresponding event type.
311 *
312 * @param eventType The type of event that is checked.
313 * @return `true` if this subscription contains the corresponding event type.
314 *
315 * @see DXFeedSubscription::getEventTypes()
316 */
317 bool containsEventType(const EventTypeEnum &eventType) override;
318
319 /**
320 * Clears the set of subscribed symbols.
321 */
322 void clear() const;
323
324 /**
325 * Returns a set of subscribed symbols (depending on the actual implementation of the subscription).
326 *
327 * The resulting set is maybe either a snapshot of the set of the subscribed symbols at the time of invocation or a
328 * weakly consistent view of the set.
329 *
330 * @return A set of subscribed symbols.
331 */
333
334 /**
335 * Returns a set of decorated symbols (depending on the actual implementation of the subscription).
336 *
337 * The resulting set is maybe either a snapshot of the set of the subscribed symbols at the time of invocation or a
338 * weakly consistent view of the set.
339 *
340 * @return A set of decorated subscribed symbols.
341 */
343
344 /**
345 * Changes the set of subscribed symbols so that it contains just the symbols from the specified collection (using
346 * iterators).
347 *
348 * Example:
349 * ```cpp
350 * auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
351 *
352 * sub->setSymbols(v.begin(), v.end());
353 * ```
354 *
355 * @tparam SymbolIt The collection's iterator type
356 * @param begin The beginning of the symbol collection.
357 * @param end The end of the symbol collection.
358 */
359 template <typename SymbolIt> void setSymbols(SymbolIt begin, SymbolIt end) const {
360 if constexpr (Debugger::isDebug) {
361 // ReSharper disable once CppDFAUnreachableCode
362 Debugger::debug(toString() + "::setSymbols(symbols = " + elementsToString(begin, end) + ")");
363 }
364
365 auto list = SymbolWrapper::SymbolListUtils::toGraalListUnique(begin, end);
366
367 setSymbolsImpl(list.get());
368 }
369
370 /**
371 * Changes the set of subscribed symbols so that it contains just the symbols from the specified collection.
372 *
373 * Example:
374 * ```cpp
375 * auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
376 *
377 * sub->setSymbols(std::vector{"AAPL", "IBM"});
378 * sub->setSymbols(v);
379 * ```
380 *
381 * @tparam SymbolsCollection The symbol collection's type
382 * @param collection The symbol collection
383 */
384 template <ConvertibleToSymbolWrapperCollection SymbolsCollection>
385 void setSymbols(SymbolsCollection &&collection) const {
386 setSymbols(std::begin(collection), std::end(collection));
387 }
388
389 /**
390 * Changes the set of subscribed symbols so that it contains just the symbols from the specified collection
391 * (initializer list).
392 *
393 * Example:
394 * ```cpp
395 * sub->setSymbols({"AAPL", "IBM"sv, "TSLA"s, "GOOG"_s});
396 * ```
397 *
398 * @param collection The symbol collection
399 */
400 void setSymbols(std::initializer_list<SymbolWrapper> collection) const;
401
402 /**
403 * Adds the specified symbol to the set of subscribed symbols.
404 * This is a convenience method to subscribe to one symbol at a time that has a return fast-path for a case when
405 * the symbol is already in the set.
406 * When subscribing to multiple symbols at once, it is preferable to use @ref DXFeedSubscription::addSymbols(const
407 * SymbolsCollection &collection) "addSymbols(symbols)" method.
408 *
409 * Example:
410 * ```cpp
411 * sub->addSymbols("TSLA");
412 * sub->addSymbols("XBT/USD:GDAX"s);
413 * sub->addSymbols("BTC/EUR:CXBITF"sv);
414 * ```
415 *
416 * @param symbolWrapper The symbol.
417 */
418 void addSymbols(const SymbolWrapper &symbolWrapper) const;
419
420 /**
421 * Adds the specified collection (using iterators) of symbols to the set of subscribed symbols.
422 *
423 * Example:
424 * ```cpp
425 * auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
426 *
427 * sub->addSymbols(v.begin(), v.end());
428 * ```
429 *
430 * @tparam SymbolIt The collection's iterator type
431 * @param begin The beginning of the symbol collection.
432 * @param end The end of the symbol collection.
433 */
434 template <typename SymbolIt> void addSymbols(SymbolIt begin, SymbolIt end) const {
435 if constexpr (Debugger::isDebug) {
436 // ReSharper disable once CppDFAUnreachableCode
437 Debugger::debug(toString() + "::addSymbols(symbols = " + elementsToString(begin, end) + ")");
438 }
439
440 auto list = SymbolWrapper::SymbolListUtils::toGraalListUnique(begin, end);
441
442 addSymbolsImpl(list.get());
443 }
444
445 /**
446 * Adds the specified collection of symbols to the set of subscribed symbols.
447 *
448 * Example:
449 * ```cpp
450 * auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
451 *
452 * sub->addSymbols(std::vector{"AAPL", "IBM"});
453 * sub->addSymbols(v);
454 * ```
455 *
456 * @tparam SymbolsCollection The symbol collection's type
457 * @param collection The symbol collection
458 */
459 template <ConvertibleToSymbolWrapperCollection SymbolsCollection>
460 void addSymbols(const SymbolsCollection &collection) const {
461 addSymbols(std::begin(collection), std::end(collection));
462 }
463
464 /**
465 * Adds the specified collection (initializer list) of symbols to the set of subscribed symbols.
466 *
467 * Example:
468 * ```cpp
469 * sub->addSymbols({"AAPL", "IBM"sv, "TSLA"s, "GOOG"_s});
470 * ```
471 *
472 * @param collection The symbol collection
473 */
474 void addSymbols(std::initializer_list<SymbolWrapper> collection) const;
475
476 /**
477 * Removes the specified symbol from the set of subscribed symbols.
478 * To conveniently remove one or few symbols, you can use @ref DXFeedSubscription::removeSymbols(const
479 * SymbolsCollection &collection) "removeSymbols(symbols)" method.
480 *
481 * Example:
482 * ```cpp
483 * sub->removeSymbols("TSLA");
484 * sub->removeSymbols("XBT/USD:GDAX"s);
485 * sub->removeSymbols("BTC/EUR:CXBITF"sv);
486 * ```
487 *
488 * @param symbolWrapper The symbol.
489 */
490 void removeSymbols(const SymbolWrapper &symbolWrapper) const;
491
492 /**
493 * Removes the specified collection (using iterators) of symbols from the set of subscribed symbols.
494 *
495 * Example:
496 * ```cpp
497 * auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
498 *
499 * sub->removeSymbols(v.begin(), v.end());
500 * ```
501 *
502 * @tparam SymbolIt The collection's iterator type
503 * @param begin The beginning of the symbol collection.
504 * @param end The end of the symbol collection.
505 */
506 template <typename SymbolIt> void removeSymbols(SymbolIt begin, SymbolIt end) const {
507 if constexpr (Debugger::isDebug) {
508 // ReSharper disable once CppDFAUnreachableCode
509 Debugger::debug(toString() + "::removeSymbols(symbols = " + elementsToString(begin, end) + ")");
510 }
511
512 auto list = SymbolWrapper::SymbolListUtils::toGraalListUnique(begin, end);
513
514 removeSymbolsImpl(list.get());
515 }
516
517 /**
518 * Removes the specified collection of symbols from the set of subscribed symbols.
519 *
520 * Example:
521 * ```cpp
522 * auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
523 *
524 * sub->removeSymbols(std::vector{"AAPL", "IBM"});
525 * sub->removeSymbols(v);
526 * ```
527 *
528 * @tparam SymbolsCollection The symbol collection's type
529 * @param collection The symbol collection
530 */
531 template <ConvertibleToSymbolWrapperCollection SymbolsCollection>
532 void removeSymbols(SymbolsCollection &&collection) const {
533 removeSymbols(std::begin(collection), std::end(collection));
534 }
535
536 /**
537 * Removes the specified collection (initializer list) of symbols from the set of subscribed symbols.
538 *
539 * Example:
540 * ```cpp
541 * sub->removeSymbols({"AAPL", "IBM"sv, "TSLA"s, "GOOG"_s});
542 * ```
543 *
544 * @param collection The symbol collection
545 */
546 void removeSymbols(std::initializer_list<SymbolWrapper> collection) const;
547
548 /**
549 * Returns the aggregation period for data for this subscription instance.
550 *
551 * @return The aggregation period for data, represented as a TimePeriod object.
552 */
554
555 /**
556 * Sets the aggregation period for data.
557 * This method sets a new aggregation period for data, which will only take effect on the next iteration of
558 * data notification. For example, if the current aggregation period is 5 seconds, and it is changed
559 * to 1 second, the next call to the next call to the retrieve method may take up to 5 seconds, after which
560 * the new aggregation period will take effect.
561 *
562 * @param aggregationPeriod the new aggregation period for data
563 */
564 void setAggregationPeriod(const TimePeriod &aggregationPeriod) const;
565
566 /**
567 * Sets the aggregation period for data.
568 * This method sets a new aggregation period for data, which will only take effect on the next iteration of
569 * data notification. For example, if the current aggregation period is 5 seconds, and it is changed
570 * to 1 second, the next call to the next call to the retrieve method may take up to 5 seconds, after which
571 * the new aggregation period will take effect.
572 *
573 * @param aggregationPeriod the new aggregation period (in millis) for data
574 */
575 void setAggregationPeriod(std::chrono::milliseconds aggregationPeriod) const;
576
577 /**
578 * Sets the aggregation period for data.
579 * This method sets a new aggregation period for data, which will only take effect on the next iteration of
580 * data notification. For example, if the current aggregation period is 5 seconds, and it is changed
581 * to 1 second, the next call to the next call to the retrieve method may take up to 5 seconds, after which
582 * the new aggregation period will take effect.
583 *
584 * @param aggregationPeriod the new aggregation period (in millis) for data
585 */
586 void setAggregationPeriod(std::int64_t aggregationPeriod) const;
587
588 /**
589 * Adds listener for events.
590 * Event lister can be added only when the subscription is not producing any events.
591 * The subscription must be either empty
592 * (its set of @ref DXFeedSubscription::getSymbols() "symbols" is empty or not @ref DXFeedSubscription::attach()
593 * "attached" to any feed (its set of change listeners is empty).
594 *
595 * This method does nothing if this subscription is closed.
596 *
597 * Example:
598 * ```cpp
599 * auto sub = endpoint->getFeed()->createSubscription({dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE});
600 *
601 * sub->addEventListener([](auto &&events) {
602 * for (const auto &e : events) {
603 * if (auto quote = e->template sharedAs<dxfcpp::Quote>(); quote) {
604 * std::cout << "Q : " + quote->toString() << std::endl;
605 * } else if (auto tns = e->template sharedAs<dxfcpp::TimeAndSale>(); tns) {
606 * std::cout << "TnS : " + tns->toString() << std::endl;
607 * }
608 * }
609 * });
610 *
611 * sub->addSymbols({"$TOP10L/Q", "$SP500#45", "$TICK", "SPX"});
612 * ```
613 *
614 * @tparam EventListener The listener type. Listener can be callable with signature: `void(const
615 * std::vector<std::shared_ptr<EventType>&)`
616 * @param listener The event listener
617 * @return The listener id
618 */
619 template <typename EventListener>
620 std::size_t addEventListener(EventListener &&listener)
621#if __cpp_concepts
622 requires requires {
623 { listener(std::vector<std::shared_ptr<EventType>>{}) } -> std::same_as<void>;
624 }
625#endif
626 {
627 if (!tryToSetEventListenerHandle()) {
628 return OnEventHandler::FAKE_ID;
629 }
630
631 return onEvent_ += listener;
632 }
633
634 /**
635 * Adds typed listener for events.
636 * Event lister can be added only when the subscription is not producing any events.
637 * The subscription must be either empty
638 * (its set of @ref DXFeedSubscription::getSymbols() "symbols" is empty or not @ref DXFeedSubscription::attach()
639 * "attached" to any feed (its set of change listeners is empty).
640 *
641 * This method does nothing if this subscription is closed.
642 *
643 * Example:
644 * ```cpp
645 * auto sub = endpoint->getFeed()->createSubscription({dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE});
646 *
647 * sub->addEventListener(std::function([](const std::vector<std::shared_ptr<dxfcpp::Quotes>> &quotes) -> void {
648 * for (const auto &q : quotes) {
649 * std::cout << "Q : " + q->toString() << std::endl;
650 * }
651 * }));
652 *
653 * sub->addEventListener<dxfcpp::TimeAndSale>([](const auto &timeAndSales) -> void {
654 * for (const auto &tns : timeAndSales) {
655 * std::cout << "TnS : " + tns->toString() << std::endl;
656 * }
657 * });
658 *
659 * sub->addEventListener<dxfcpp::MarketEvent>([](const auto &marketEvents) -> void {
660 * for (const auto &me : marketEvents) {
661 * std::cout << "Market Event's symbol: " + me->getEventSymbol() << std::endl;
662 * }
663 * });
664 *
665 * sub->addSymbols({"$TOP10L/Q", "AAPL", "$TICK", "SPX"});
666 * ```
667 *
668 * @tparam EventT The event type (EventType's child with field TYPE, convertible to EventTypeEnum or MarketEvent
669 * or LastingEvent or TimeSeriesEvent or IndexedEvent)
670 * @param listener The listener. Listener can be callable with signature: `void(const
671 * std::vector<std::shared_ptr<EventT>&)`
672 * @return The listener id
673 */
674 template <typename EventT>
675 std::size_t addEventListener(std::function<void(const std::vector<std::shared_ptr<EventT>> &)> &&listener)
676#if __cpp_concepts
677 requires std::is_base_of_v<EventType, EventT> &&
678 (requires {
682#endif
683 {
685 return SimpleHandler<void(const std::vector<std::shared_ptr<EventType>> &)>::FAKE_ID;
686 }
687
688 return onEvent_ += [l = listener](auto &&events) {
690
692
693 for (const auto &e : events) {
694 if (auto expected = e->template sharedAs<EventT>(); expected) {
696 }
697 }
698
700 };
701 }
702
703 /**
704 * Removes listener for events.
705 *
706 * Example:
707 * ```cpp
708 * auto id = sub->addEventListener([](auto){});
709 *
710 * sub->removeEventListener(id);
711 * ```
712 *
713 * @param listenerId The listener id
714 */
716
717 /**
718 * Returns a reference to an incoming events' handler (delegate), to which listeners can be added and removed.
719 * Listener can be callable with signature: `void(const std::vector<std::shared_ptr<EventType>&)`
720 *
721 * Example:
722 * ```cpp
723 * auto sub = endpoint->getFeed()->createSubscription({dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE});
724 * auto id = sub->onEvent() += [](auto &&events) {
725 * for (const auto &e : events) {
726 * if (auto quote = e->template sharedAs<dxfcpp::Quote>(); quote) {
727 * std::cout << "Q : " + quote->toString() << std::endl;
728 * } else if (auto tns = e->template sharedAs<dxfcpp::TimeAndSale>(); tns) {
729 * std::cout << "TnS : " + tns->toString() << std::endl;
730 * }
731 * }
732 * };
733 *
734 * sub->addSymbols({"$TOP10L/Q", "$SP500#45", "$TICK", "SPX"});
735 * sub->onEvent() -= id;
736 * ```
737 *
738 * @return The incoming events' handler (delegate)
739 */
740 OnEventHandler &onEvent();
741
742 std::size_t addChangeListener(std::shared_ptr<ObservableSubscriptionChangeListener> listener) override;
743
744 void removeChangeListener(std::size_t changeListenerId) override;
745
746 /**
747 * @return maximum number of events in the single notification of OnEventHandler.
748 * Special cases are supported for constants ::OPTIMAL_BATCH_LIMIT and ::MAX_BATCH_LIMIT.
749 */
751
752 /**
753 * Sets maximum number of events in the single notification of OnEventHandler.
754 * Special cases are supported for constants ::OPTIMAL_BATCH_LIMIT and ::MAX_BATCH_LIMIT.
755 *
756 * @param eventsBatchLimit the notification events limit
757 * @throws JavaException if eventsBatchLimit < 0 (see ::OPTIMAL_BATCH_LIMIT or ::MAX_BATCH_LIMIT)
758 */
759 void setEventsBatchLimit(std::int32_t eventsBatchLimit) const;
760};
761
762/**
763 * Extends DXFeedSubscription to conveniently subscribe to time-series of events for a set of symbols and event types.
764 * This class decorates symbols that are passed to `xxxSymbols` methods in DXFeedSubscription by wrapping them into
765 * TimeSeriesSubscriptionSymbol instances with the current value of
766 * @ref DXFeedTimeSeriesSubscription::getFromTime() "fromTime" property. While
767 * @ref DXFeedSubscription::getSymbols() "getSymbols" method returns original (undecorated) symbols, any installed
768 * ObservableSubscriptionChangeListener will see decorated ones.
769 *
770 * <p> Only events that implement the TimeSeriesEvent interface can be subscribed to with DXFeedTimeSeriesSubscription.
771 *
772 * <h3>From time</h3>
773 *
774 * The value of @ref DXFeedTimeSeriesSubscription::getFromTime() "fromTime" property defines the time-span of events
775 * that are subscribed to. Only events that satisfy `event.getEventTime() >= thisSubscription->getFromTime()` are
776 * looked for.
777 *
778 * <p> The value `fromTime` is initially set to `std::numeric_limits<std::int64_t>::max()` with a special meaning that
779 * no events will be received until `fromTime` is changed with
780 * @ref DXFeedTimeSeriesSubscription::setFromTime() "setFromTime" method.
781 *
782 * <h3>Threads and locks</h3>
783 *
784 * This class is thread-safe and can be used concurrently from multiple threads without external synchronization.
785 */
787 public DXFeedSubscription {
788 std::atomic<std::int64_t> fromTime_{std::numeric_limits<std::int64_t>::max()};
789
790 static void registerEntity();
791
792 public:
793 DXFeedTimeSeriesSubscription(RequireMakeShared<DXFeedTimeSeriesSubscription>::LockExternalConstructionTag lockTag);
794
795 DXFeedTimeSeriesSubscription(RequireMakeShared<DXFeedTimeSeriesSubscription>::LockExternalConstructionTag lockTag,
796 const EventTypeEnum &eventType, JavaObjectHandle<DXFeedSubscription> &&handle);
797
798 ~DXFeedTimeSeriesSubscription() override;
799
800 template <typename EventTypeIt>
801#if __cpp_concepts
802 requires requires(EventTypeIt iter) {
804 }
805#endif
810 }
811
816 }
817
818 template <typename EventTypesCollection>
822#if __cpp_concepts
823 requires requires {
824 {
827 std::move(handle))
828 };
829 }
830#endif
833 }
834
835 ///
836 std::string toString() const override;
837
838 /**
839 * Returns the earliest timestamp from which time-series of events shall be received.
840 * The timestamp is in milliseconds from midnight, January 1, 1970 UTC.
841 *
842 * @return the earliest timestamp from which time-series of events shall be received.
843 */
845
846 /**
847 * Sets the earliest timestamp from which time-series of events shall be received.
848 * The timestamp is in milliseconds from midnight, January 1, 1970 UTC.
849 *
850 * @param fromTime the timestamp.
851 */
852 void setFromTime(std::int64_t fromTime);
853
854 /**
855 * Sets the earliest timestamp from which time-series of events shall be received.
856 * The timestamp is in milliseconds from midnight, January 1, 1970 UTC.
857 *
858 * @param fromTime the timestamp.
859 */
860 void setFromTime(std::chrono::milliseconds fromTime);
861};
862
864
865/// @}
866
#define DXFCPP_MACRO_CONCAT_INNER(a, b)
Definition Common.hpp:135
#define DXFCPP_MACRO_CONCAT(a, b)
Definition Common.hpp:134
#define DXFCPP_MACRO_UNIQUE_NAME(base)
Definition Common.hpp:136
#define DXFCXX_DISABLE_MSC_WARNINGS_POP()
Definition Conf.hpp:31
#define DXFCXX_DISABLE_CLANG_WARNINGS_PUSH(warnings)
Definition Conf.hpp:65
#define DXFCPP_END_NAMESPACE
Definition Conf.hpp:97
#define DXFCPP_BEGIN_NAMESPACE
Definition Conf.hpp:94
#define DXFCXX_DISABLE_GCC_WARNINGS_PUSH(warnings)
Definition Conf.hpp:47
#define DXFCXX_DISABLE_CLANG_WARNINGS_POP()
Definition Conf.hpp:67
#define DXFCXX_DISABLE_GCC_WARNINGS_POP()
Definition Conf.hpp:49
#define DXFCXX_DISABLE_MSC_WARNINGS_PUSH(warnings)
Definition Conf.hpp:30
#define DXFCPP_TRACE_ISOLATES
Definition Debug.hpp:19
#define DXFCPP_DEBUG
Definition Debug.hpp:15
#define DXFCPP_TRACE_LISTS
Definition Debug.hpp:22
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_name(dxfc_dxendpoint_builder_t builderHandle, const char *name)
Changes the name used to distinguish multiple endpoints in the same process (GraalVM Isolate) in logs...
Definition DXEndpoint.cpp:721
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_properties(dxfc_dxendpoint_builder_t builder, const dxfc_dxendpoint_property_t **properties, size_t size)
Sets all supported properties from the provided properties object.
Definition DXEndpoint.cpp:754
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_password(dxfc_dxendpoint_t endpoint, const char *password)
Changes password for this endpoint.
Definition DXEndpoint.cpp:1002
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_publisher(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxpublisher_t *publisher)
Definition DXEndpoint.cpp:1192
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_supports_property(dxfc_dxendpoint_builder_t builder, const char *key, DXFC_OUT int *supports)
Checks if a property is supported.
Definition DXEndpoint.cpp:781
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_add_state_change_listener(dxfc_dxendpoint_t endpoint, dxfc_dxendpoint_state_change_listener listener)
Adds a listener notified about changes in state property.
Definition DXEndpoint.cpp:1138
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_disconnect(dxfc_dxendpoint_t endpoint)
Terminates all remote network connections.
Definition DXEndpoint.cpp:1053
#define DXFCPP_EXPORT
Definition api.h:35
void * dxfc_dxendpoint_builder_t
The dxFeed endpoint's builder handle.
Definition api.h:207
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_close_and_await_termination(dxfc_dxendpoint_t endpoint)
Closes this endpoint and wait until all pending data processing tasks are completed.
Definition DXEndpoint.cpp:951
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_await_not_connected(dxfc_dxendpoint_t endpoint)
Waits while this endpoint state becomes NOT_CONNECTED or CLOSED.
Definition DXEndpoint.cpp:1104
dxfc_dxendpoint_state_t
Represents the current state of endpoint.
Definition api.h:149
@ DXFC_DXENDPOINT_STATE_CLOSED
Endpoint was closed.
Definition api.h:169
@ DXFC_DXENDPOINT_STATE_NOT_CONNECTED
Endpoint was created by is not connected to remote endpoints.
Definition api.h:153
@ DXFC_DXENDPOINT_STATE_CONNECTING
The connect function was called to establish connection to remove endpoint, but the connection is not...
Definition api.h:159
@ DXFC_DXENDPOINT_STATE_CONNECTED
The connection to the remote endpoint is established.
Definition api.h:164
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_instance(void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Returns a default application-wide singleton instance of dxFeed endpoint with a FEED role.
Definition DXEndpoint.cpp:840
#define DXFC_OUT
Definition api.h:17
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_state(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxendpoint_state_t *state)
Returns the state of this endpoint.
Definition DXEndpoint.cpp:1121
void * dxfc_dxendpoint_t
The dxFeed endpoint handle.
Definition api.h:198
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_property(dxfc_dxendpoint_builder_t builder, const char *key, const char *value)
Sets the specified property.
Definition DXEndpoint.cpp:737
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_free(dxfc_dxendpoint_builder_t builder)
Removes a builder from the registry.
Definition DXEndpoint.cpp:828
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_connect(dxfc_dxendpoint_t endpoint, const char *address)
Connects to the specified remote address.
Definition DXEndpoint.cpp:1019
dxfc_error_code_t
List of error codes.
Definition api.h:49
@ DXFC_EC_ERROR
The error returned if the current operation cannot be completed.
Definition api.h:60
@ DXFC_EC_SUCCESS
OK.
Definition api.h:53
@ DXFC_EC_G_ERR
dxFeed Graal Native API error.
Definition api.h:57
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_remove_state_change_listener(dxfc_dxendpoint_t endpoint, dxfc_dxendpoint_state_change_listener listener)
Removes a listener notified about changes in state property.
Definition DXEndpoint.cpp:1164
DXFCPP_EXPORT dxfc_error_code_t dxfc_system_set_property(const char *key, const char *value)
Sets the system property indicated by the specified key.
Definition System.cpp:74
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_build(dxfc_dxendpoint_builder_t builder, void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Builds the new dxFeed endpoint instance.
Definition DXEndpoint.cpp:798
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_feed(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxfeed_t *feed)
Definition DXEndpoint.cpp:1187
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_await_processed(dxfc_dxendpoint_t endpoint)
Waits until this endpoint stops processing data (becomes quiescent).
Definition DXEndpoint.cpp:1087
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_close(dxfc_dxendpoint_t endpoint)
Closes this endpoint.
Definition DXEndpoint.cpp:934
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_new_builder(DXFC_OUT dxfc_dxendpoint_builder_t *builder)
Creates a new dxFeed endpoint's builder instance.
Definition DXEndpoint.cpp:688
void(* dxfc_dxendpoint_state_change_listener)(dxfc_dxendpoint_state_t old_state, dxfc_dxendpoint_state_t new_state, void *user_data)
The endpoint current state change listener.
Definition api.h:178
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_reconnect(dxfc_dxendpoint_t endpoint)
Terminates all established network connections and initiates connecting again with the same address.
Definition DXEndpoint.cpp:1036
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_role(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxendpoint_role_t *role)
Returns the role of this endpoint.
Definition DXEndpoint.cpp:968
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_user(dxfc_dxendpoint_t endpoint, const char *user)
Changes username for this endpoint.
Definition DXEndpoint.cpp:985
DXFCPP_EXPORT dxfc_error_code_t dxfc_system_get_property(const char *key, DXFC_OUT char *buffer, size_t buffer_size)
Gets the system property indicated by the specified key.
dxfc_dxendpoint_role_t
Represents the role of an endpoint that was specified during its creation.
Definition api.h:89
@ DXFC_DXENDPOINT_ROLE_PUBLISHER
PUBLISHER endpoint connects to the remote publisher hub (also known as multiplexor) or creates a publ...
Definition api.h:127
@ DXFC_DXENDPOINT_ROLE_STREAM_FEED
STREAM_FEED endpoint is similar to DXFC_DXENDPOINT_ROLE_FEED and also connects to the remote data fee...
Definition api.h:116
@ DXFC_DXENDPOINT_ROLE_FEED
FEED endpoint connects to the remote data feed provider and is optimized for real-time or delayed dat...
Definition api.h:99
@ DXFC_DXENDPOINT_ROLE_STREAM_PUBLISHER
STREAM_PUBLISHER endpoint is similar to DXFC_DXENDPOINT_ROLE_PUBLISHER and also connects to the remot...
Definition api.h:136
@ DXFC_DXENDPOINT_ROLE_LOCAL_HUB
LOCAL_HUB endpoint is a local hub without the ability to establish network connections.
Definition api.h:143
@ DXFC_DXENDPOINT_ROLE_ON_DEMAND_FEED
ON_DEMAND_FEED endpoint is similar to DXFC_DXENDPOINT_ROLE_FEED, but it is designed to be used with d...
Definition api.h:107
void * dxfc_dxpublisher_t
The dxFeed publisher handle.
Definition api.h:217
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_create(void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Creates an endpoint with FEED role.
Definition DXEndpoint.cpp:887
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_instance2(dxfc_dxendpoint_role_t role, void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Returns a default application-wide singleton instance of DXEndpoint for a specific role.
Definition DXEndpoint.cpp:863
void * dxfc_dxfeed_t
The dxFeed handle.
Definition api.h:212
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_with_role(dxfc_dxendpoint_builder_t builder, dxfc_dxendpoint_role_t role)
Sets role for the created dxFeed endpoint.
Definition DXEndpoint.cpp:704
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_create2(dxfc_dxendpoint_role_t role, void *user_data, DXFC_OUT dxfc_dxendpoint_t *endpoint)
Creates an endpoint with a specified role.
Definition DXEndpoint.cpp:910
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_free(dxfc_dxendpoint_t endpoint)
Removes the dxFeed endpoint from the registry.
Definition DXEndpoint.cpp:1197
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_disconnect_and_clear(dxfc_dxendpoint_t endpoint)
Terminates all remote network connections and clears stored data.
Definition DXEndpoint.cpp:1070
Builder class for DXEndpoint that supports additional configuration properties.
Definition DXEndpoint.hpp:866
std::shared_ptr< DXEndpoint > build()
Builds DXEndpoint instance.
Definition DXEndpoint.cpp:348
std::shared_ptr< Builder > withName(const StringLike &name)
Changes the name used to distinguish multiple endpoints in the same process (GraalVM Isolate) in logs...
Definition DXEndpoint.cpp:391
std::shared_ptr< Builder > withExecutor(const std::shared_ptr< Executor > &executor)
Sets the executor that is used for notifications (events, state changes, etc.) of the endpoint to bui...
Definition DXEndpoint.hpp:995
bool supportsProperty(const StringLike &key) const
Checks if a property is supported.
Definition DXEndpoint.cpp:338
std::shared_ptr< Builder > withProperties(Properties &&properties)
Sets all supported properties from the provided properties object.
Definition DXEndpoint.hpp:957
~Builder() noexcept override
Releases the GraalVM handle.
Definition DXEndpoint.cpp:380
std::shared_ptr< Builder > withRole(Role role)
Sets role for the created DXEndpoint.
Definition DXEndpoint.cpp:300
std::shared_ptr< Builder > withProperty(const StringLike &key, const StringLike &value)
Sets the specified property.
Definition DXEndpoint.cpp:313
Subscription for a set of symbols and event types.
Definition DXFeedSubscription.hpp:45
bool containsEventType(const EventTypeEnum &eventType) override
Returns true if this subscription contains the corresponding event type.
Definition DXFeedSubscription.cpp:229
std::size_t addChangeListener(std::shared_ptr< ObservableSubscriptionChangeListener > listener) override
Adds subscription change listener.
Definition DXFeedSubscription.cpp:320
bool isClosed() override
Returns true if this subscription is closed.
Definition DXFeedSubscription.cpp:205
void addSymbols(SymbolIt begin, SymbolIt end) const
Adds the specified collection (using iterators) of symbols to the set of subscribed symbols.
Definition DXFeedSubscription.hpp:434
void close() const
Closes this subscription and makes it permanently detached.
Definition DXFeedSubscription.cpp:214
void setEventsBatchLimit(std::int32_t eventsBatchLimit) const
Sets maximum number of events in the single notification of OnEventHandler.
Definition DXFeedSubscription.cpp:366
std::unordered_set< EventTypeEnum > getEventTypes() override
Returns a set of subscribed event types.
Definition DXFeedSubscription.cpp:225
void setSymbols(std::initializer_list< SymbolWrapper > collection) const
Changes the set of subscribed symbols so that it contains just the symbols from the specified collect...
Definition DXFeedSubscription.cpp:260
void removeSymbols(SymbolIt begin, SymbolIt end) const
Removes the specified collection (using iterators) of symbols from the set of subscribed symbols.
Definition DXFeedSubscription.hpp:506
void removeSymbols(SymbolsCollection &&collection) const
Removes the specified collection of symbols from the set of subscribed symbols.
Definition DXFeedSubscription.hpp:532
static const std::int32_t MAX_BATCH_LIMIT
The maximum events' batch limit for a single notification in OnEventHandler.
Definition DXFeedSubscription.hpp:61
void removeSymbols(const SymbolWrapper &symbolWrapper) const
Removes the specified symbol from the set of subscribed symbols.
Definition DXFeedSubscription.cpp:279
void attach(std::shared_ptr< DXFeed > feed)
Attaches subscription to the specified feed.
Definition DXFeedSubscription.cpp:187
TimePeriod getAggregationPeriod() const
Returns the aggregation period for data for this subscription instance.
Definition DXFeedSubscription.cpp:294
std::string toString() const override
Returns a string representation of the current object.
Definition DXFeedSubscription.cpp:145
static const std::int32_t OPTIMAL_BATCH_LIMIT
The optimal events' batch limit for a single notification in OnEventHandler.
Definition DXFeedSubscription.hpp:56
std::size_t addEventListener(std::function< void(const std::vector< std::shared_ptr< EventT > > &)> &&listener)
Adds typed listener for events.
Definition DXFeedSubscription.hpp:675
void addSymbols(std::initializer_list< SymbolWrapper > collection) const
Adds the specified collection (initializer list) of symbols to the set of subscribed symbols.
Definition DXFeedSubscription.cpp:275
void setSymbols(SymbolsCollection &&collection) const
Changes the set of subscribed symbols so that it contains just the symbols from the specified collect...
Definition DXFeedSubscription.hpp:385
void setAggregationPeriod(const TimePeriod &aggregationPeriod) const
Sets the aggregation period for data.
Definition DXFeedSubscription.cpp:298
static std::shared_ptr< DXFeedSubscription > create(const EventTypeEnum &eventType)
Creates a detached subscription for a single event type.
Definition DXFeedSubscription.cpp:164
std::int32_t getEventsBatchLimit() const
Definition DXFeedSubscription.cpp:362
std::size_t addEventListener(EventListener &&listener)
Adds listener for events.
Definition DXFeedSubscription.hpp:620
static std::shared_ptr< DXFeedSubscription > create(EventTypesCollection &&eventTypes)
Creates a detached subscription for the given collection of event types.
Definition DXFeedSubscription.hpp:261
OnEventHandler & onEvent()
Returns a reference to an incoming events' handler (delegate), to which listeners can be added and re...
Definition DXFeedSubscription.cpp:314
void addSymbols(const SymbolsCollection &collection) const
Adds the specified collection of symbols to the set of subscribed symbols.
Definition DXFeedSubscription.hpp:460
void setSymbols(SymbolIt begin, SymbolIt end) const
Changes the set of subscribed symbols so that it contains just the symbols from the specified collect...
Definition DXFeedSubscription.hpp:359
void setAggregationPeriod(std::int64_t aggregationPeriod) const
Sets the aggregation period for data.
Definition DXFeedSubscription.cpp:306
void removeChangeListener(std::size_t changeListenerId) override
Removes subscription change listener by id.
Definition DXFeedSubscription.cpp:345
std::vector< SymbolWrapper > getDecoratedSymbols() const
Returns a set of decorated symbols (depending on the actual implementation of the subscription).
Definition DXFeedSubscription.cpp:251
void clear() const
Clears the set of subscribed symbols.
Definition DXFeedSubscription.cpp:233
void detach(std::shared_ptr< DXFeed > feed)
Detaches subscription from the specified feed.
Definition DXFeedSubscription.cpp:196
void addSymbols(const SymbolWrapper &symbolWrapper) const
Adds the specified symbol to the set of subscribed symbols.
Definition DXFeedSubscription.cpp:264
void setAggregationPeriod(std::chrono::milliseconds aggregationPeriod) const
Sets the aggregation period for data.
Definition DXFeedSubscription.cpp:302
void removeSymbols(std::initializer_list< SymbolWrapper > collection) const
Removes the specified collection (initializer list) of symbols from the set of subscribed symbols.
Definition DXFeedSubscription.cpp:290
std::vector< SymbolWrapper > getSymbols() const
Returns a set of subscribed symbols (depending on the actual implementation of the subscription).
Definition DXFeedSubscription.cpp:242
Extends DXFeedSubscription to conveniently subscribe to time-series of events for a set of symbols an...
Definition DXFeedSubscription.hpp:787
std::int64_t getFromTime()
Returns the earliest timestamp from which time-series of events shall be received.
Definition DXFeedSubscription.cpp:394
void setFromTime(std::chrono::milliseconds fromTime)
Sets the earliest timestamp from which time-series of events shall be received.
Definition DXFeedSubscription.cpp:405
void setFromTime(std::int64_t fromTime)
Sets the earliest timestamp from which time-series of events shall be received.
Definition DXFeedSubscription.cpp:398
The enumeration type that provides additional information about the dxFeed Graal C++-API event type.
Definition EventTypeEnum.hpp:29
Source identifier for IndexedEvent.
Definition IndexedEventSource.hpp:29
static JavaObjectHandleRegistry & getInstance() noexcept
Returns the process-wide handle registry.
Definition JavaObjectHandle.cpp:68
void releaseAll() noexcept
Releases all currently registered handles while the Graal isolate is still available.
Definition JavaObjectHandle.cpp:125
void reset(void *handle=nullptr) noexcept
Replaces the owned handle, releasing the previous one.
Definition JavaObjectHandle.cpp:163
JavaObjectHandleState(void *handle, Deleter deleter) noexcept
Creates an ownership state for a native handle.
Definition JavaObjectHandle.cpp:150
void * get() const noexcept
Returns the currently owned native handle.
Definition JavaObjectHandle.hpp:115
void moveFrom(JavaObjectHandleState &other) noexcept
Transfers ownership from another state and releases the handle previously owned by this state.
Definition JavaObjectHandle.cpp:159
~JavaObjectHandleState() noexcept
Releases the owned handle, if any, and unregisters the state.
Definition JavaObjectHandle.cpp:155
Thread-safe registry that associates callback identifiers with entities without owning them.
Definition EntityManager.hpp:180
bool unregisterEntity(const H *handle)
Unregisters an entity using a constant opaque callback handle.
Definition EntityManager.hpp:303
std::optional< Id< EntityIdType > > getId(const std::shared_ptr< EntityType > &entity)
Definition EntityManager.hpp:360
bool unregisterEntity(H *handle)
Unregisters an entity using an opaque callback handle.
Definition EntityManager.hpp:292
bool unregisterEntity(const std::shared_ptr< EntityType > &entity)
Unregisters an entity.
Definition EntityManager.hpp:254
bool unregisterEntity(Id< EntityIdType > id)
Unregisters an entity by identifier.
Definition EntityManager.hpp:273
std::shared_ptr< EntityType > getEntity(H *handle)
Locks and returns the entity identified by an opaque callback handle.
Definition EntityManager.hpp:339
Id< EntityIdType > registerEntity(const std::shared_ptr< EntityType > &entity)
Registers an entity and returns its callback identifier.
Definition EntityManager.hpp:221
bool contains(const std::shared_ptr< EntityType > &entity)
Definition EntityManager.hpp:384
WeakEntityManager()=default
Constructs an empty weak entity registry.
std::shared_ptr< EntityType > getEntity(const H *handle)
Locks and returns the entity identified by a constant opaque callback handle.
Definition EntityManager.hpp:350
std::size_t getLastId()
Definition EntityManager.hpp:243
bool contains(Id< EntityIdType > id)
Definition EntityManager.hpp:355
std::shared_ptr< EntityType > getEntity(Id< EntityIdType > id)
Locks and returns the entity registered for an identifier.
Definition EntityManager.hpp:315
Mixin for wrapping calls to common promise methods.
Definition Promise.hpp:80
JavaException getException() const
Returns exceptional outcome of computation.
Definition Promise.hpp:128
void cancel() const
This method cancels computation.
Definition Promise.hpp:175
bool hasResult() const
Returns true when computation has completed normally.
Definition Promise.hpp:96
bool isCancelled() const
Returns true when computation was cancelled.
Definition Promise.hpp:115
bool hasException() const
Returns true when a computation has completed exceptionally or was canceled.
Definition Promise.hpp:105
bool awaitWithoutException(const std::chrono::milliseconds &timeoutInMilliseconds) const
Wait for computation to complete or timeout or throw an exception in case of exceptional completion.
Definition Promise.hpp:162
bool isDone() const
Returns true when a computation has completed normally, or exceptionally, or was canceled.
Definition Promise.hpp:86
bool awaitWithoutException(std::int32_t timeoutInMilliseconds) const
Wait for computation to complete or timeout or throw an exception in case of exceptional completion.
Definition Promise.hpp:145
Manages network connections to feed or publisher.
Definition DXEndpoint.hpp:179
bool isClosed() const
Definition DXEndpoint.cpp:540
SimpleHandler< void(DXEndpoint::State, DXEndpoint::State)> & onStateChange() noexcept
Returns the onStateChange handler that can be used to add or remove listeners.
Definition DXEndpoint.cpp:552
static const std::string DXFEED_PASSWORD_PROPERTY
"dxfeed.password"
Definition DXEndpoint.hpp:246
static std::shared_ptr< DXEndpoint > create(Role role)
Creates an endpoint with a specified role.
Definition DXEndpoint.cpp:527
std::shared_ptr< DXFeed > getFeed() const
Definition DXEndpoint.cpp:227
std::shared_ptr< DXEndpoint > password(const StringLike &password)
Changes password for this endpoint.
Definition DXEndpoint.cpp:154
State
Represents the current state of endpoint.
Definition DXEndpoint.hpp:444
@ CLOSED
Endpoint was closed.
Definition DXEndpoint.hpp:464
@ CONNECTING
The connect method was called to establish connection to remove endpoint, but the connection is not e...
Definition DXEndpoint.hpp:454
@ CONNECTED
The connection to the remote endpoint is established.
Definition DXEndpoint.hpp:459
@ NOT_CONNECTED
Endpoint was created by is not connected to remote endpoints.
Definition DXEndpoint.hpp:448
std::shared_ptr< DXEndpoint > user(const StringLike &user)
Changes username for this endpoint.
Definition DXEndpoint.cpp:147
void reconnect() const
Terminates all established network connections and initiates connecting again with the same address.
Definition DXEndpoint.cpp:173
static std::shared_ptr< DXEndpoint > create()
Creates an endpoint with FEED role.
Definition DXEndpoint.cpp:518
void removeStateChangeListener(std::size_t listenerId) noexcept
Removes a listener notified about changes in state property.
Definition DXEndpoint.cpp:548
const std::string & getName() const &noexcept
Definition DXEndpoint.cpp:544
Role
Represents the role of an endpoint that was specified during its creation.
Definition DXEndpoint.hpp:373
@ PUBLISHER
PUBLISHER endpoint connects to the remote publisher hub (also known as multiplexor) or creates a publ...
Definition DXEndpoint.hpp:418
@ STREAM_FEED
STREAM_FEED endpoint is similar to DXEndpoint::FEED and also connects to the remote data feed provide...
Definition DXEndpoint.hpp:406
@ LOCAL_HUB
LOCAL_HUB endpoint is a local hub without the ability to establish network connections.
Definition DXEndpoint.hpp:434
@ ON_DEMAND_FEED
ON_DEMAND_FEED endpoint is similar to DXEndpoint::FEED, but it is designed to be used with OnDemandSe...
Definition DXEndpoint.hpp:397
@ STREAM_PUBLISHER
STREAM_PUBLISHER endpoint is similar to DXEndpoint::PUBLISHER and also connects to the remote publish...
Definition DXEndpoint.hpp:427
@ FEED
FEED endpoint connects to the remote data feed provider and is optimized for real-time or delayed dat...
Definition DXEndpoint.hpp:384
std::string toString() const override
Returns a string representation of the current object.
Definition DXEndpoint.cpp:401
void awaitProcessed() const
Waits until this endpoint stops processing data (becomes quiescent).
Definition DXEndpoint.cpp:209
std::shared_ptr< DXPublisher > getPublisher() const
Definition DXEndpoint.cpp:236
static const std::string DXFEED_WILDCARD_ENABLE_PROPERTY
"dxfeed.wildcard.enable"
Definition DXEndpoint.hpp:274
std::size_t addStateChangeListener(std::function< void(State, State)> listener) noexcept
Adds a listener notified about changes in state property.
Definition DXEndpoint.hpp:619
static const std::string DXENDPOINT_EVENT_TIME_PROPERTY
"dxendpoint.eventTime"
Definition DXEndpoint.hpp:319
static const std::string DXPUBLISHER_THREAD_POOL_SIZE_PROPERTY
"dxpublisher.threadPoolSize"
Definition DXEndpoint.hpp:302
State getState() const
Returns the state of this endpoint.
Definition DXEndpoint.cpp:143
static const std::string DXENDPOINT_STORE_EVERYTHING_PROPERTY
"dxendpoint.storeEverything"
Definition DXEndpoint.hpp:332
void awaitNotConnected() const
Waits while this endpoint state becomes NOT_CONNECTED or CLOSED.
Definition DXEndpoint.cpp:200
static std::shared_ptr< DXEndpoint > getInstance(Role role)
Returns a default application-wide singleton instance of DXEndpoint for a specific role.
Definition DXEndpoint.cpp:500
static const std::string DXFEED_AGGREGATION_PERIOD_PROPERTY
"dxfeed.aggregationPeriod"
Definition DXEndpoint.hpp:265
void close() const
Closes this endpoint.
Definition DXEndpoint.cpp:556
static const std::string DXFEED_THREAD_POOL_SIZE_PROPERTY
"dxfeed.threadPoolSize"
Definition DXEndpoint.hpp:255
void disconnect() const
Terminates all remote network connections.
Definition DXEndpoint.cpp:182
void closeAndAwaitTermination() const
Closes this endpoint and wait until all pending data processing tasks are completed.
Definition DXEndpoint.cpp:218
static std::shared_ptr< DXEndpoint > getInstance()
Returns a default application-wide singleton instance of DXEndpoint with a FEED role.
Definition DXEndpoint.cpp:491
static const std::string DXPUBLISHER_ADDRESS_PROPERTY
"dxpublisher.address"
Definition DXEndpoint.hpp:293
static const std::string DXFEED_USER_PROPERTY
"dxfeed.user"
Definition DXEndpoint.hpp:236
static const std::string NAME_PROPERTY
"name"
Definition DXEndpoint.hpp:196
static const std::string DXSCHEME_ENABLED_PROPERTY_PREFIX
"dxscheme.enabled."
Definition DXEndpoint.hpp:366
static const std::string DXPUBLISHER_PROPERTIES_PROPERTY
"dxpublisher.properties"
Definition DXEndpoint.hpp:283
static const std::string DXSCHEME_NANO_TIME_PROPERTY
"dxscheme.nanoTime"
Definition DXEndpoint.hpp:352
static const std::string DXFEED_ADDRESS_PROPERTY
"dxfeed.address"
Definition DXEndpoint.hpp:226
std::shared_ptr< DXEndpoint > executor(const std::shared_ptr< Executor > &executor)
Changes the executor that is used for notifications (events, state changes, etc.) of this endpoint.
Definition DXEndpoint.hpp:655
void disconnectAndClear() const
Terminates all remote network connections and clears stored data.
Definition DXEndpoint.cpp:191
Role getRole() const noexcept
Returns the role of this endpoint.
Definition DXEndpoint.cpp:536
static const std::string DXFEED_PROPERTIES_PROPERTY
"dxfeed.properties"
Definition DXEndpoint.hpp:207
static std::shared_ptr< Builder > newBuilder()
Creates a new Builder instance.
Definition DXEndpoint.cpp:509
std::shared_ptr< DXEndpoint > connect(const StringLike &address)
Connects to the specified remote address.
Definition DXEndpoint.cpp:161
Main entry class for dxFeed API (read it first).
Definition DXFeed.hpp:141
void detachSubscriptionAndClear(const std::shared_ptr< DXFeedSubscription > &subscription) const
Detaches the given subscription from this feed and clears data delivered to this subscription by publ...
Definition DXFeed.cpp:68
Collection getLastEvents(Collection &&events)
Returns the last events for the specified list of event instances.
Definition DXFeed.hpp:294
std::shared_ptr< PromiseList< E > > getLastEventsPromises(std::initializer_list< SymbolWrapper > collection) const
Requests the last events for the specified event type and a collection of symbols.
Definition DXFeed.hpp:749
std::vector< std::shared_ptr< E > > getTimeSeriesIfSubscribed(const SymbolWrapper &symbol, std::chrono::milliseconds fromTime, std::chrono::milliseconds toTime) const
Returns time series of events for the specified event type, symbol and a range of time if there is a ...
Definition DXFeed.hpp:1017
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:88
std::shared_ptr< DXFeedTimeSeriesSubscription > createTimeSeriesSubscription(std::initializer_list< EventTypeEnum > eventTypes) const
Creates new subscription for multiple event types that is attached to this feed.
Definition DXFeed.cpp:137
std::shared_ptr< DXFeedSubscription > createSubscription(EventTypeIt begin, EventTypeIt end) const
Creates new subscription for multiple event types that is attached to this feed.
Definition DXFeed.hpp:388
std::shared_ptr< PromiseList< E > > getLastEventsPromises(const SymbolsCollection &collection) const
Requests the last events for the specified event type and a collection of symbols.
Definition DXFeed.hpp:703
std::shared_ptr< E > getLastEventIfSubscribed(const SymbolWrapper &symbol)
Returns the last event for the specified event type and symbol if there is a subscription for it.
Definition DXFeed.hpp:328
std::shared_ptr< DXFeedSubscription > createSubscription(std::initializer_list< EventTypeEnum > eventTypes) const
Creates new subscription for multiple event types that is attached to this feed.
Definition DXFeed.cpp:101
std::vector< std::shared_ptr< E > > getTimeSeriesIfSubscribed(const SymbolWrapper &symbol, std::chrono::milliseconds fromTime) const
Returns time series of events for the specified event type, symbol and a range of time (without an up...
Definition DXFeed.hpp:1048
std::shared_ptr< DXFeedTimeSeriesSubscription > createTimeSeriesSubscription(EventTypeIt begin, EventTypeIt end) const
Creates new subscription for multiple event types that is attached to this feed.
Definition DXFeed.hpp:500
static std::shared_ptr< DXFeed > getInstance()
Returns a default application-wide singleton instance of feed.
Definition DXFeed.cpp:19
std::shared_ptr< E > getLastEvent(std::shared_ptr< E > event)
Returns the last event for the specified event instance.
Definition DXFeed.hpp:270
std::shared_ptr< PromiseList< E > > getLastEventsPromises(SymbolIt begin, SymbolIt end) const
Requests the last events for the specified event type and a collection of symbols.
Definition DXFeed.hpp:656
std::shared_ptr< DXFeedSubscription > createSubscription(const EventTypesCollection &eventTypes) const
Creates new subscription for multiple event types that is attached to this feed.
Definition DXFeed.hpp:438
std::shared_ptr< Promise< std::shared_ptr< E > > > getLastEventPromise(const SymbolWrapper &symbol) const
Requests the last event for the specified event type and symbol.
Definition DXFeed.hpp:608
std::shared_ptr< DXFeedTimeSeriesSubscription > createTimeSeriesSubscription(const EventTypesCollection &eventTypes) const
Creates new subscription for multiple event types that is attached to this feed.
Definition DXFeed.hpp:567
std::string toString() const override
Returns a string representation of the current object.
Definition DXFeed.cpp:226
std::shared_ptr< Promise< std::vector< std::shared_ptr< E > > > > getIndexedEventsPromise(const SymbolWrapper &symbol, const IndexedEventSource &source) const
Requests a container of indexed events for the specified event type, symbol and source.
Definition DXFeed.hpp:802
void detachSubscription(const std::shared_ptr< DXFeedSubscription > &subscription) const
Detaches the given subscription from this feed.
Definition DXFeed.cpp:48
std::vector< std::shared_ptr< E > > getIndexedEventsIfSubscribed(const SymbolWrapper &symbol, const IndexedEventSource &source) const
Returns a vector of indexed events for the specified event type, symbol and source if there is a subs...
Definition DXFeed.hpp:858
void attachSubscription(const std::shared_ptr< DXFeedSubscription > &subscription) const
Attaches the given subscription to this feed.
Definition DXFeed.cpp:28
std::shared_ptr< DXFeedTimeSeriesSubscription > createTimeSeriesSubscription(const EventTypeEnum &eventType) const
Creates a new subscription for a single event type that is attached to this feed.
Definition DXFeed.cpp:116
Provides API for publishing of events to local or remote DXFeed.
Definition DXPublisher.hpp:60
Mixin for wrapping Promise method calls for a single event.
Definition Promise.hpp:244
std::shared_ptr< E > getResult() const
Returns result of computation.
Definition Promise.hpp:252
std::shared_ptr< E > await() const
Wait for the computation to complete and return its result or throw an exception in case of exception...
Definition Promise.hpp:262
std::shared_ptr< E > await(const std::chrono::milliseconds &timeoutInMilliseconds) const &
Wait for computation to complete or timeout and return its result or throw an exception in case of ex...
Definition Promise.hpp:292
std::shared_ptr< E > await(std::int32_t timeoutInMilliseconds) const &
Wait for computation to complete or timeout and return its result or throw an exception in case of ex...
Definition Promise.hpp:277
Marks all event types that can be received via dxFeed API.
Definition EventType.hpp:37
std::string toString() const override
Returns a string representation of the current object.
Definition api.cpp:67
virtual std::int64_t getEventTime() const noexcept
Returns time when an event was created or zero when time is not available.
Definition api.cpp:54
virtual void assign(std::shared_ptr< EventType > event)
Replaces the contents of the event.
Definition api.cpp:63
virtual void setEventTime(std::int64_t eventTime) noexcept
Changes event creation time.
Definition api.cpp:58
The wrapper over CEntryPointErrorsEnum, the error code returned by GraalVM.
Definition GraalException.hpp:26
GraalException(CEntryPointErrorsEnum entryPointErrorsEnum)
Constructs an exception.
Definition GraalException.cpp:8
void handle(ArgTypes... args)
Calls the listeners and pass the args to them.
Definition Handler.hpp:122
std::size_t add(ListenerType &&listener)
Adds the listener to "main" group.
Definition Handler.hpp:156
std::size_t operator%=(ListenerType &&listener)
Adds the low priority listener (to the "low priority" group).
Definition Handler.hpp:208
std::size_t operator+=(ListenerType &&listener)
Adds the listener to "main" group.
Definition Handler.hpp:197
void operator()(ArgTypes... args)
Calls the listeners and pass the ars to them.
Definition Handler.hpp:146
Handler(std::size_t mainFuturesSize=MAIN_FUTURES_DEFAULT_SIZE) noexcept
Creates the new handler by specified size of circular buffer of futures.
Definition Handler.hpp:84
void operator-=(std::size_t id)
Removes a listener by the id.
Definition Handler.hpp:236
std::size_t addLowPriority(ListenerType &&listener)
Adds the low priority listener (to the "low priority" group) It will be called after the "main" liste...
Definition Handler.hpp:177
void remove(std::size_t id)
Removes a listener by the id.
Definition Handler.hpp:217
Represents an indexed collection of up-to-date information about some condition or state of an extern...
Definition IndexedEvent.hpp:46
Thrown to indicate that a method has been passed an illegal or inappropriate argument.
Definition InvalidArgumentException.hpp:23
A wrapper over the interceptable Java exceptions thrown by the dxFeed Native Graal SDK.
Definition JavaException.hpp:26
static void throwIfJavaThreadExceptionExists()
Throws a JavaException if it exists (i.e. intercepted by Graal SDK)
Definition JavaException.cpp:78
JavaException(const StringLike &message, const StringLike &className, const StringLike &stackTrace)
Creates an exception using Java message, className and stack trace.
Definition JavaException.cpp:52
static JavaException createAndRelease(void *exceptionHandle)
Creates an exception from a native Java exception handle and releases the native representation.
Definition JavaException.cpp:70
static JavaException create(void *exceptionHandle)
Creates an exception using native (GraalVM) Java exception handle.
Definition JavaException.cpp:60
Represents up-to-date information about some condition or state of an external entity that updates in...
Definition LastingEvent.hpp:33
Base class for all market events.
Definition MarketEvent.hpp:29
The listener interface for receiving notifications on the changes of observed subscription.
Definition ObservableSubscriptionChangeListener.hpp:32
Observable set of subscription symbols.
Definition ObservableSubscription.hpp:26
Provides on-demand historical tick data replay controls.
Definition OnDemandService.hpp:77
A list of event receiving results that will be completed normally or exceptionally in the future.
Definition Promise.hpp:442
Result of a computation that will be completed normally or exceptionally in the future.
Definition Promise.hpp:358
A class that represents a promise-based implementation often used for handling asynchronous operation...
Definition Promises.hpp:46
A helper class needed to construct smart pointers to objects and does not allow explicit construction...
Definition SharedEntity.hpp:89
static auto createShared(Args &&...args)
Creates a smart pointer to an object.
Definition SharedEntity.hpp:104
A runtime axception with stacktrace.
Definition RuntimeException.hpp:26
const std::string & getStackTrace() const &
Definition RuntimeException.cpp:83
RuntimeException(const StringLike &message, const StringLike &additionalStackTrace="")
Constructs a runtime exception.
Definition RuntimeException.cpp:67
A base abstract "shared entity" class. Has some helpers for dynamic polymorphism.
Definition SharedEntity.hpp:25
virtual std::string toString() const
Returns a string representation of the current object.
Definition SharedEntity.hpp:78
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>{nu...
Definition SharedEntity.hpp:69
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:58
bool is() const noexcept
Checks that the pointer to the current type could be converted to type T* In other words: whether typ...
Definition SharedEntity.hpp:39
std::size_t operator+=(ListenerType &&listener)
Adds the listener to "main" group.
Definition Handler.hpp:379
void remove(std::size_t id)
Removes a listener by the id.
Definition Handler.hpp:399
void handle(ArgTypes... args)
Calls the listeners and pass the args to them.
Definition Handler.hpp:317
void operator()(ArgTypes... args)
Calls the listeners and pass the ars to them.
Definition Handler.hpp:328
std::size_t addLowPriority(ListenerType &&listener)
Adds the low priority listener (to the "low priority" group) It will be called after the "main" liste...
Definition Handler.hpp:359
void operator-=(std::size_t id)
Removes a listener by the id.
Definition Handler.hpp:418
std::size_t operator%=(ListenerType &&listener)
Adds the low priority listener (to the "low priority" group).
Definition Handler.hpp:390
SimpleHandler() noexcept
Creates the new handler.
Definition Handler.hpp:289
std::size_t add(ListenerType &&listener)
Adds the listener to "main" group.
Definition Handler.hpp:338
Universal functional object that allows searching std::unordered_map for string-like keys.
Definition StringUtils.hpp:120
A simple wrapper around strings or something similar to strings to reduce the amount of code for meth...
Definition Common.hpp:728
A lightweight wrapper around strings or string-like inputs.
Definition StringUtils.hpp:28
Common string constants used across the library.
Definition StringUtils.hpp:137
static const std::string NUL
Textual representation of a null / missing string: "<null>".
Definition StringUtils.hpp:142
static const std::string EMPTY
Empty string constant: "".
Definition StringUtils.hpp:139
Value class for a period of time with support for ISO8601 duration format.
Definition TimePeriod.hpp:29
Represents time-series snapshots of some process that is evolving in time or actual events in some ex...
Definition TimeSeriesEvent.hpp:84
Mixin for wrapping Promise method calls for a void.
Definition Promise.hpp:185
void await(std::int32_t timeoutInMilliseconds) const &
Wait for the computation to complete or timeout and return its result or throw an exception in case o...
Definition Promise.hpp:217
void await(const std::chrono::milliseconds &timeoutInMilliseconds) const &
Wait for the computation to complete or timeout and return its result or throw an exception in case o...
Definition Promise.hpp:232
void await() const
Wait for the computation to complete and return its result or throw an exception in case of exception...
Definition Promise.hpp:202
void getResult() const
Returns result of computation.
Definition Promise.hpp:192
Whether T is std::shared_ptr<E>, where E is a descendant of LastingEvent (the elements of DXFeed::get...
Definition DXFeed.hpp:40
The simple key-value structure that represents an endpoint's property.
Definition api.h:184
const char * key
The property's key.
Definition api.h:186
const char * value
The property's value.
Definition api.h:188