dxFeed Graal CXX API v7.0.0
Loading...
Searching...
No Matches
DXFeedSubscription.hpp
1// Copyright (c) 2025 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 <type_traits>
26#include <unordered_set>
27
28/**
29 * \addtogroup dxfcpp_api
30 * @{
31 */
32
34
35struct DXFeed;
36struct MarketEvent;
37struct IndexedEvent;
38struct TimeSeriesEvent;
39struct LastingEvent;
40
41/**
42 * Subscription for a set of symbols and event types.
43 */
45 public:
46 static constexpr std::size_t FAKE_CHANGE_LISTENER_ID{static_cast<std::size_t>(-1)};
47
48 ///
49 using OnEventHandler = SimpleHandler<void(const std::vector<std::shared_ptr<EventType>> &)>;
50
51 // These constants are linked with the same ones in RecordBuffer - POOLED_CAPACITY and UNLIMITED_CAPACITY.
52 /**
53 * The optimal events' batch limit for a single notification in OnEventHandler.
54 */
55 static const std::int32_t OPTIMAL_BATCH_LIMIT = 0;
56
57 /**
58 * The maximum events' batch limit for a single notification in OnEventHandler.
59 */
61
62 protected:
63 friend struct DXFeed;
64
65 inline static std::atomic<std::size_t> lastChangeListenerId_{};
66
67 struct Impl;
68
69 std::unique_ptr<Impl> impl_;
70
71 std::unordered_set<EventTypeEnum> eventTypes_;
72 JavaObjectHandle<DXFeedSubscription> handle_;
73
74 std::mutex eventListenerMutex_{};
75 JavaObjectHandle<DXFeedEventListener> eventListenerHandle_;
76 OnEventHandler onEvent_{};
78 std::recursive_mutex changeListenersMutex_{};
79
80 static JavaObjectHandle<DXFeedSubscription>
81 createSubscriptionHandleFromEventClassList(const std::unique_ptr<EventClassList> &list);
82
83 void setEventListenerHandle(Id<DXFeedSubscription> id);
84
85 bool tryToSetEventListenerHandle();
86
87 void setSymbolsImpl(void *graalSymbolList) const;
88 void addSymbolsImpl(void *graalSymbolList) const;
89 void removeSymbolsImpl(void *graalSymbolList) const;
90
91 DXFeedSubscription();
92
93 DXFeedSubscription(const EventTypeEnum &eventType);
94
95 DXFeedSubscription(const EventTypeEnum &eventType, JavaObjectHandle<DXFeedSubscription> &&handle);
96
97 template <typename EventTypeIt>
98#if __cpp_concepts
99 requires requires(EventTypeIt iter) {
101 }
102#endif
104 if constexpr (Debugger::isDebug) {
105 // ReSharper disable once CppDFAUnreachableCode
106 Debugger::debug("DXFeedSubscription(eventTypes = " + namesToString(begin, end) + ")");
107 }
108
110
112
114 }
115
116 template <typename EventTypeIt>
117#if __cpp_concepts
118 requires requires(EventTypeIt iter) {
120 }
121#endif
124 if constexpr (Debugger::isDebug) {
125 // ReSharper disable once CppDFAUnreachableCode
126 Debugger::debug("DXFeedSubscription(eventTypes = " + namesToString(begin, end) + ")");
127 }
128
131 }
132
133 public:
134 /// The alias to a type of shared pointer to the DXFeedSubscription object
136
137 /// The alias to a type of unique pointer to the DXFeedSubscription object
139
140 DXFeedSubscription(LockExternalConstructionTag);
141
142 DXFeedSubscription(LockExternalConstructionTag, const EventTypeEnum &eventType);
143
144 template <typename EventTypeIt>
145#if __cpp_concepts
146 requires requires(EventTypeIt iter) {
148 }
149#endif
152 }
153
155
156 template <typename EventTypesCollection>
157 explicit DXFeedSubscription(LockExternalConstructionTag tag, EventTypesCollection &&eventTypes)
158#if __cpp_concepts
159 requires requires {
160 {
161 DXFeedSubscription(tag, std::begin(std::forward<EventTypesCollection>(eventTypes)),
162 std::end(std::forward<EventTypesCollection>(eventTypes)))
163 };
164 }
165#endif
166 : DXFeedSubscription(tag, std::begin(std::forward<EventTypesCollection>(eventTypes)),
167 std::end(std::forward<EventTypesCollection>(eventTypes))) {
168 }
169
170 ///
171 std::string toString() const override;
172
173 ~DXFeedSubscription() override;
174
175 /**
176 * Creates a <i>detached</i> subscription for a single event type.
177 *
178 * Example:
179 * ```cpp
180 * auto sub = dxfcpp::DXFeedSubscription::create(dxfcpp::Quote::TYPE);
181 * ```
182 *
183 * @param eventType the event type.
184 */
185 static std::shared_ptr<DXFeedSubscription> create(const EventTypeEnum &eventType);
186
187 /**
188 * Creates a <i>detached</i> subscription for the given collection of event types.
189 *
190 * Example:
191 * ```cpp
192 * auto eventTypes = {dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE};
193 *
194 * auto sub = dxfcpp::DXFeedSubscription::create(eventTypes.begin(), eventTypes.end());
195 * ```
196 *
197 * ```cpp
198 * std::vector types{dxfcpp::Quote::TYPE, dxfcpp::Trade::TYPE, dxfcpp::Summary::TYPE};
199 *
200 * auto sub = dxfcpp::DXFeedSubscription::create(types.begin(), types.end());
201 * ```
202 *
203 * @tparam EventTypeIt The collection's iterator type
204 * @param begin The beginning of the event type collection.
205 * @param end The end of an event type collection.
206 * @return The new <i>detached</i> subscription for the given collection of event types.
207 */
208 template <typename EventTypeIt>
209#if __cpp_concepts
210 requires requires(EventTypeIt iter) {
212 }
213#endif
215 if constexpr (Debugger::isDebug) {
216 // ReSharper disable once CppDFAUnreachableCode
217 Debugger::debug("DXFeedSubscription::create(eventTypes = " + namesToString(begin, end) + ")");
218 }
219
220 auto sub = createShared(begin, end);
222
224
225 return sub;
226 }
227
228 /**
229 * Creates a <i>detached</i> subscription for the given collection of event types.
230 *
231 * Example:
232 * ```cpp
233 * auto sub = dxfcpp::DXFeedSubscription::create({dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE});
234 * ```
235 *
236 * @param eventTypes The event type collection.
237 * @return The new <i>detached</i> subscription for the given collection of event types.
238 */
240
241 /**
242 * Creates a <i>detached</i> subscription for the given collection of event types.
243 *
244 * Example:
245 * ```cpp
246 * auto sub = dxfcpp::DXFeedSubscription::create(std::unordered_set{dxfcpp::Quote::TYPE,
247 * dxfcpp::TimeAndSale::TYPE});
248 * ```
249 *
250 * ```cpp
251 * std::vector types = {dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE};
252 * auto sub = dxfcpp::DXFeedSubscription::create(types);
253 * ```
254 *
255 * @tparam EventTypesCollection The type of the collection of event types
256 * @param eventTypes The event type collection.
257 * @return The new <i>detached</i> subscription for the given collection of event types.
258 */
259 template <typename EventTypesCollection>
260 static std::shared_ptr<DXFeedSubscription> create(EventTypesCollection &&eventTypes) {
261 auto sub = createShared(std::forward<EventTypesCollection>(eventTypes));
262 auto id = ApiContext::getInstance()->getManager<EntityManager<DXFeedSubscription>>()->registerEntity(sub);
263
264 dxfcpp::ignoreUnused(id);
265
266 return sub;
267 }
268
269 /**
270 * Attaches subscription to the specified feed.
271 *
272 * @param feed The feed to attach to.
273 */
274 void attach(std::shared_ptr<DXFeed> feed);
275
276 /**
277 * Detaches subscription from the specified feed.
278 *
279 * @param feed The feed to detach from.
280 */
281 void detach(std::shared_ptr<DXFeed> feed);
282
283 /**
284 * Returns `true` if this subscription is closed.
285 *
286 * @return `true` if this subscription is closed.
287 *
288 * @see DXFeedSubscription::close()
289 */
290 bool isClosed() override;
291
292 /**
293 * Closes this subscription and makes it <i>permanently detached</i>.
294 * This method notifies all installed instances of subscription change listeners by invoking `subscriptionClosed`
295 * while holding the lock for this subscription. This method clears lists of all installed
296 * event listeners and subscription change listeners and makes sure that no more listeners
297 * can be added.
298 */
299 void close() const;
300
301 /**
302 * Returns a set of subscribed event types.
303 *
304 * @return A set of subscribed event types.
305 */
307
308 /**
309 * Returns `true` if this subscription contains the corresponding event type.
310 *
311 * @param eventType The type of event that is checked.
312 * @return `true` if this subscription contains the corresponding event type.
313 *
314 * @see DXFeedSubscription::getEventTypes()
315 */
316 bool containsEventType(const EventTypeEnum &eventType) override;
317
318 /**
319 * Clears the set of subscribed symbols.
320 */
321 void clear() const;
322
323 /**
324 * Returns a set of subscribed symbols (depending on the actual implementation of the subscription).
325 *
326 * The resulting set is maybe either a snapshot of the set of the subscribed symbols at the time of invocation or a
327 * weakly consistent view of the set.
328 *
329 * @return A set of subscribed symbols.
330 */
332
333 /**
334 * Returns a set of decorated symbols (depending on the actual implementation of the subscription).
335 *
336 * The resulting set is maybe either a snapshot of the set of the subscribed symbols at the time of invocation or a
337 * weakly consistent view of the set.
338 *
339 * @return A set of decorated subscribed symbols.
340 */
342
343 /**
344 * Changes the set of subscribed symbols so that it contains just the symbols from the specified collection (using
345 * iterators).
346 *
347 * Example:
348 * ```cpp
349 * auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
350 *
351 * sub->setSymbols(v.begin(), v.end());
352 * ```
353 *
354 * @tparam SymbolIt The collection's iterator type
355 * @param begin The beginning of the symbol collection.
356 * @param end The end of the symbol collection.
357 */
358 template <typename SymbolIt> void setSymbols(SymbolIt begin, SymbolIt end) const {
359 if constexpr (Debugger::isDebug) {
360 // ReSharper disable once CppDFAUnreachableCode
361 Debugger::debug(toString() + "::setSymbols(symbols = " + elementsToString(begin, end) + ")");
362 }
363
364 auto list = SymbolWrapper::SymbolListUtils::toGraalListUnique(begin, end);
365
366 setSymbolsImpl(list.get());
367 }
368
369 /**
370 * Changes the set of subscribed symbols so that it contains just the symbols from the specified collection.
371 *
372 * Example:
373 * ```cpp
374 * auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
375 *
376 * sub->setSymbols(std::vector{"AAPL", "IBM"});
377 * sub->setSymbols(v);
378 * ```
379 *
380 * @tparam SymbolsCollection The symbol collection's type
381 * @param collection The symbol collection
382 */
383 template <ConvertibleToSymbolWrapperCollection SymbolsCollection>
384 void setSymbols(SymbolsCollection &&collection) const {
385 setSymbols(std::begin(collection), std::end(collection));
386 }
387
388 /**
389 * Changes the set of subscribed symbols so that it contains just the symbols from the specified collection
390 * (initializer list).
391 *
392 * Example:
393 * ```cpp
394 * sub->setSymbols({"AAPL", "IBM"sv, "TSLA"s, "GOOG"_s});
395 * ```
396 *
397 * @param collection The symbol collection
398 */
399 void setSymbols(std::initializer_list<SymbolWrapper> collection) const;
400
401 /**
402 * Adds the specified symbol to the set of subscribed symbols.
403 * This is a convenience method to subscribe to one symbol at a time that has a return fast-path for a case when
404 * the symbol is already in the set.
405 * When subscribing to multiple symbols at once, it is preferable to use @ref DXFeedSubscription::addSymbols(const
406 * SymbolsCollection &collection) "addSymbols(symbols)" method.
407 *
408 * Example:
409 * ```cpp
410 * sub->addSymbols("TSLA");
411 * sub->addSymbols("XBT/USD:GDAX"s);
412 * sub->addSymbols("BTC/EUR:CXBITF"sv);
413 * ```
414 *
415 * @param symbolWrapper The symbol.
416 */
417 void addSymbols(const SymbolWrapper &symbolWrapper) const;
418
419 /**
420 * Adds the specified collection (using iterators) of symbols to the set of subscribed symbols.
421 *
422 * Example:
423 * ```cpp
424 * auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
425 *
426 * sub->addSymbols(v.begin(), v.end());
427 * ```
428 *
429 * @tparam SymbolIt The collection's iterator type
430 * @param begin The beginning of the symbol collection.
431 * @param end The end of the symbol collection.
432 */
433 template <typename SymbolIt> void addSymbols(SymbolIt begin, SymbolIt end) const {
434 if constexpr (Debugger::isDebug) {
435 // ReSharper disable once CppDFAUnreachableCode
436 Debugger::debug(toString() + "::addSymbols(symbols = " + elementsToString(begin, end) + ")");
437 }
438
439 auto list = SymbolWrapper::SymbolListUtils::toGraalListUnique(begin, end);
440
441 addSymbolsImpl(list.get());
442 }
443
444 /**
445 * Adds the specified collection of symbols to the set of subscribed symbols.
446 *
447 * Example:
448 * ```cpp
449 * auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
450 *
451 * sub->addSymbols(std::vector{"AAPL", "IBM"});
452 * sub->addSymbols(v);
453 * ```
454 *
455 * @tparam SymbolsCollection The symbol collection's type
456 * @param collection The symbol collection
457 */
458 template <ConvertibleToSymbolWrapperCollection SymbolsCollection>
459 void addSymbols(const SymbolsCollection &collection) const {
460 addSymbols(std::begin(collection), std::end(collection));
461 }
462
463 /**
464 * Adds the specified collection (initializer list) of symbols to the set of subscribed symbols.
465 *
466 * Example:
467 * ```cpp
468 * sub->addSymbols({"AAPL", "IBM"sv, "TSLA"s, "GOOG"_s});
469 * ```
470 *
471 * @param collection The symbol collection
472 */
473 void addSymbols(std::initializer_list<SymbolWrapper> collection) const;
474
475 /**
476 * Removes the specified symbol from the set of subscribed symbols.
477 * To conveniently remove one or few symbols, you can use @ref DXFeedSubscription::removeSymbols(const
478 * SymbolsCollection &collection) "removeSymbols(symbols)" method.
479 *
480 * Example:
481 * ```cpp
482 * sub->removeSymbols("TSLA");
483 * sub->removeSymbols("XBT/USD:GDAX"s);
484 * sub->removeSymbols("BTC/EUR:CXBITF"sv);
485 * ```
486 *
487 * @param symbolWrapper The symbol.
488 */
489 void removeSymbols(const SymbolWrapper &symbolWrapper) const;
490
491 /**
492 * Removes the specified collection (using iterators) of symbols from the set of subscribed symbols.
493 *
494 * Example:
495 * ```cpp
496 * auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
497 *
498 * sub->removeSymbols(v.begin(), v.end());
499 * ```
500 *
501 * @tparam SymbolIt The collection's iterator type
502 * @param begin The beginning of the symbol collection.
503 * @param end The end of the symbol collection.
504 */
505 template <typename SymbolIt> void removeSymbols(SymbolIt begin, SymbolIt end) const {
506 if constexpr (Debugger::isDebug) {
507 // ReSharper disable once CppDFAUnreachableCode
508 Debugger::debug(toString() + "::removeSymbols(symbols = " + elementsToString(begin, end) + ")");
509 }
510
511 auto list = SymbolWrapper::SymbolListUtils::toGraalListUnique(begin, end);
512
513 removeSymbolsImpl(list.get());
514 }
515
516 /**
517 * Removes the specified collection of symbols from the set of subscribed symbols.
518 *
519 * Example:
520 * ```cpp
521 * auto v = std::vector<dxfcpp::SymbolWrapper>{"XBT/USD:GDAX"s, "BTC/EUR:CXBITF"sv, "TSLA", "GOOG"_s};
522 *
523 * sub->removeSymbols(std::vector{"AAPL", "IBM"});
524 * sub->removeSymbols(v);
525 * ```
526 *
527 * @tparam SymbolsCollection The symbol collection's type
528 * @param collection The symbol collection
529 */
530 template <ConvertibleToSymbolWrapperCollection SymbolsCollection>
531 void removeSymbols(SymbolsCollection &&collection) const {
532 removeSymbols(std::begin(collection), std::end(collection));
533 }
534
535 /**
536 * Removes the specified collection (initializer list) of symbols from the set of subscribed symbols.
537 *
538 * Example:
539 * ```cpp
540 * sub->removeSymbols({"AAPL", "IBM"sv, "TSLA"s, "GOOG"_s});
541 * ```
542 *
543 * @param collection The symbol collection
544 */
545 void removeSymbols(std::initializer_list<SymbolWrapper> collection) const;
546
547 /**
548 * Returns the aggregation period for data for this subscription instance.
549 *
550 * @return The aggregation period for data, represented as a TimePeriod object.
551 */
553
554 /**
555 * Sets the aggregation period for data.
556 * This method sets a new aggregation period for data, which will only take effect on the next iteration of
557 * data notification. For example, if the current aggregation period is 5 seconds, and it is changed
558 * to 1 second, the next call to the next call to the retrieve method may take up to 5 seconds, after which
559 * the new aggregation period will take effect.
560 *
561 * @param aggregationPeriod the new aggregation period for data
562 */
563 void setAggregationPeriod(const TimePeriod &aggregationPeriod) const;
564
565 /**
566 * Sets the aggregation period for data.
567 * This method sets a new aggregation period for data, which will only take effect on the next iteration of
568 * data notification. For example, if the current aggregation period is 5 seconds, and it is changed
569 * to 1 second, the next call to the next call to the retrieve method may take up to 5 seconds, after which
570 * the new aggregation period will take effect.
571 *
572 * @param aggregationPeriod the new aggregation period (in millis) for data
573 */
574 void setAggregationPeriod(std::chrono::milliseconds aggregationPeriod) const;
575
576 /**
577 * Sets the aggregation period for data.
578 * This method sets a new aggregation period for data, which will only take effect on the next iteration of
579 * data notification. For example, if the current aggregation period is 5 seconds, and it is changed
580 * to 1 second, the next call to the next call to the retrieve method may take up to 5 seconds, after which
581 * the new aggregation period will take effect.
582 *
583 * @param aggregationPeriod the new aggregation period (in millis) for data
584 */
585 void setAggregationPeriod(std::int64_t aggregationPeriod) const;
586
587 /**
588 * Adds listener for events.
589 * Event lister can be added only when the subscription is not producing any events.
590 * The subscription must be either empty
591 * (its set of @ref DXFeedSubscription::getSymbols() "symbols" is empty or not @ref DXFeedSubscription::attach()
592 * "attached" to any feed (its set of change listeners is empty).
593 *
594 * This method does nothing if this subscription is closed.
595 *
596 * Example:
597 * ```cpp
598 * auto sub = endpoint->getFeed()->createSubscription({dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE});
599 *
600 * sub->addEventListener([](auto &&events) {
601 * for (const auto &e : events) {
602 * if (auto quote = e->template sharedAs<dxfcpp::Quote>(); quote) {
603 * std::cout << "Q : " + quote->toString() << std::endl;
604 * } else if (auto tns = e->template sharedAs<dxfcpp::TimeAndSale>(); tns) {
605 * std::cout << "TnS : " + tns->toString() << std::endl;
606 * }
607 * }
608 * });
609 *
610 * sub->addSymbols({"$TOP10L/Q", "$SP500#45", "$TICK", "SPX"});
611 * ```
612 *
613 * @tparam EventListener The listener type. Listener can be callable with signature: `void(const
614 * std::vector<std::shared_ptr<EventType>&)`
615 * @param listener The event listener
616 * @return The listener id
617 */
618 template <typename EventListener>
619 std::size_t addEventListener(EventListener &&listener)
620#if __cpp_concepts
621 requires requires {
622 { listener(std::vector<std::shared_ptr<EventType>>{}) } -> std::same_as<void>;
623 }
624#endif
625 {
626 if (!tryToSetEventListenerHandle()) {
627 return OnEventHandler::FAKE_ID;
628 }
629
630 return onEvent_ += listener;
631 }
632
633 /**
634 * Adds typed listener for events.
635 * Event lister can be added only when the subscription is not producing any events.
636 * The subscription must be either empty
637 * (its set of @ref DXFeedSubscription::getSymbols() "symbols" is empty or not @ref DXFeedSubscription::attach()
638 * "attached" to any feed (its set of change listeners is empty).
639 *
640 * This method does nothing if this subscription is closed.
641 *
642 * Example:
643 * ```cpp
644 * auto sub = endpoint->getFeed()->createSubscription({dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE});
645 *
646 * sub->addEventListener(std::function([](const std::vector<std::shared_ptr<dxfcpp::Quotes>> &quotes) -> void {
647 * for (const auto &q : quotes) {
648 * std::cout << "Q : " + q->toString() << std::endl;
649 * }
650 * }));
651 *
652 * sub->addEventListener<dxfcpp::TimeAndSale>([](const auto &timeAndSales) -> void {
653 * for (const auto &tns : timeAndSales) {
654 * std::cout << "TnS : " + tns->toString() << std::endl;
655 * }
656 * });
657 *
658 * sub->addEventListener<dxfcpp::MarketEvent>([](const auto &marketEvents) -> void {
659 * for (const auto &me : marketEvents) {
660 * std::cout << "Market Event's symbol: " + me->getEventSymbol() << std::endl;
661 * }
662 * });
663 *
664 * sub->addSymbols({"$TOP10L/Q", "AAPL", "$TICK", "SPX"});
665 * ```
666 *
667 * @tparam EventT The event type (EventType's child with field TYPE, convertible to EventTypeEnum or MarketEvent
668 * or LastingEvent or TimeSeriesEvent or IndexedEvent)
669 * @param listener The listener. Listener can be callable with signature: `void(const
670 * std::vector<std::shared_ptr<EventT>&)`
671 * @return The listener id
672 */
673 template <typename EventT>
674 std::size_t addEventListener(std::function<void(const std::vector<std::shared_ptr<EventT>> &)> &&listener)
675#if __cpp_concepts
676 requires std::is_base_of_v<EventType, EventT> &&
677 (requires {
681#endif
682 {
684 return SimpleHandler<void(const std::vector<std::shared_ptr<EventType>> &)>::FAKE_ID;
685 }
686
687 return onEvent_ += [l = listener](auto &&events) {
689
691
692 for (const auto &e : events) {
693 if (auto expected = e->template sharedAs<EventT>(); expected) {
695 }
696 }
697
699 };
700 }
701
702 /**
703 * Removes listener for events.
704 *
705 * Example:
706 * ```cpp
707 * auto id = sub->addEventListener([](auto){});
708 *
709 * sub->removeEventListener(id);
710 * ```
711 *
712 * @param listenerId The listener id
713 */
715
716 /**
717 * Returns a reference to an incoming events' handler (delegate), to which listeners can be added and removed.
718 * Listener can be callable with signature: `void(const std::vector<std::shared_ptr<EventType>&)`
719 *
720 * Example:
721 * ```cpp
722 * auto sub = endpoint->getFeed()->createSubscription({dxfcpp::Quote::TYPE, dxfcpp::TimeAndSale::TYPE});
723 * auto id = sub->onEvent() += [](auto &&events) {
724 * for (const auto &e : events) {
725 * if (auto quote = e->template sharedAs<dxfcpp::Quote>(); quote) {
726 * std::cout << "Q : " + quote->toString() << std::endl;
727 * } else if (auto tns = e->template sharedAs<dxfcpp::TimeAndSale>(); tns) {
728 * std::cout << "TnS : " + tns->toString() << std::endl;
729 * }
730 * }
731 * };
732 *
733 * sub->addSymbols({"$TOP10L/Q", "$SP500#45", "$TICK", "SPX"});
734 * sub->onEvent() -= id;
735 * ```
736 *
737 * @return The incoming events' handler (delegate)
738 */
739 OnEventHandler &onEvent();
740
741 std::size_t addChangeListener(std::shared_ptr<ObservableSubscriptionChangeListener> listener) override;
742
743 void removeChangeListener(std::size_t changeListenerId) override;
744
745 /**
746 * @return maximum number of events in the single notification of OnEventHandler.
747 * Special cases are supported for constants ::OPTIMAL_BATCH_LIMIT and ::MAX_BATCH_LIMIT.
748 */
750
751 /**
752 * Sets maximum number of events in the single notification of OnEventHandler.
753 * Special cases are supported for constants ::OPTIMAL_BATCH_LIMIT and ::MAX_BATCH_LIMIT.
754 *
755 * @param eventsBatchLimit the notification events limit
756 * @throws JavaException if eventsBatchLimit < 0 (see ::OPTIMAL_BATCH_LIMIT or ::MAX_BATCH_LIMIT)
757 */
758 void setEventsBatchLimit(std::int32_t eventsBatchLimit) const;
759};
760
761/**
762 * Extends DXFeedSubscription to conveniently subscribe to time-series of events for a set of symbols and event types.
763 * This class decorates symbols that are passed to `xxxSymbols` methods in DXFeedSubscription by wrapping them into
764 * TimeSeriesSubscriptionSymbol instances with the current value of
765 * @ref DXFeedTimeSeriesSubscription::getFromTime() "fromTime" property. While
766 * @ref DXFeedSubscription::getSymbols() "getSymbols" method returns original (undecorated) symbols, any installed
767 * ObservableSubscriptionChangeListener will see decorated ones.
768 *
769 * <p> Only events that implement the TimeSeriesEvent interface can be subscribed to with DXFeedTimeSeriesSubscription.
770 *
771 * <h3>From time</h3>
772 *
773 * The value of @ref DXFeedTimeSeriesSubscription::getFromTime() "fromTime" property defines the time-span of events
774 * that are subscribed to. Only events that satisfy `event.getEventTime() >= thisSubscription->getFromTime()` are
775 * looked for.
776 *
777 * <p> The value `fromTime` is initially set to `std::numeric_limits<std::int64_t>::max()` with a special meaning that
778 * no events will be received until `fromTime` is changed with
779 * @ref DXFeedTimeSeriesSubscription::setFromTime() "setFromTime" method.
780 *
781 * <h3>Threads and locks</h3>
782 *
783 * This class is thread-safe and can be used concurrently from multiple threads without external synchronization.
784 */
786 std::atomic<std::int64_t> fromTime_{std::numeric_limits<std::int64_t>::max()};
787
788 static void registerEntity();
789
790 public:
791 DXFeedTimeSeriesSubscription(RequireMakeShared<DXFeedTimeSeriesSubscription>::LockExternalConstructionTag lockTag);
792
793 DXFeedTimeSeriesSubscription(RequireMakeShared<DXFeedTimeSeriesSubscription>::LockExternalConstructionTag lockTag,
794 const EventTypeEnum &eventType, JavaObjectHandle<DXFeedSubscription> &&handle);
795
796 ~DXFeedTimeSeriesSubscription() override;
797
798 template <typename EventTypeIt>
799#if __cpp_concepts
800 requires requires(EventTypeIt iter) {
802 }
803#endif
808 }
809
814 }
815
816 template <typename EventTypesCollection>
820#if __cpp_concepts
821 requires requires {
822 {
825 std::move(handle))
826 };
827 }
828#endif
831 }
832
833 ///
834 std::string toString() const override;
835
836 /**
837 * Returns the earliest timestamp from which time-series of events shall be received.
838 * The timestamp is in milliseconds from midnight, January 1, 1970 UTC.
839 *
840 * @return the earliest timestamp from which time-series of events shall be received.
841 */
843
844 /**
845 * Sets the earliest timestamp from which time-series of events shall be received.
846 * The timestamp is in milliseconds from midnight, January 1, 1970 UTC.
847 *
848 * @param fromTime the timestamp.
849 */
850 void setFromTime(std::int64_t fromTime);
851
852 /**
853 * Sets the earliest timestamp from which time-series of events shall be received.
854 * The timestamp is in milliseconds from midnight, January 1, 1970 UTC.
855 *
856 * @param fromTime the timestamp.
857 */
858 void setFromTime(std::chrono::milliseconds fromTime);
859};
860
862
863/// @}
864
#define DXFCPP_MACRO_CONCAT_INNER(a, b)
Definition Common.hpp:129
#define DXFCPP_MACRO_CONCAT(a, b)
Definition Common.hpp:128
#define DXFCPP_MACRO_UNIQUE_NAME(base)
Definition Common.hpp:130
#define DXFCXX_DISABLE_MSC_WARNINGS_POP()
Definition Conf.hpp:31
#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_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:692
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:725
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_password(dxfc_dxendpoint_t endpoint, const char *password)
Changes password for this endpoint.
Definition DXEndpoint.cpp:973
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_publisher(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxpublisher_t *publisher)
Definition DXEndpoint.cpp:1163
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:752
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:1109
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_disconnect(dxfc_dxendpoint_t endpoint)
Terminates all remote network connections.
Definition DXEndpoint.cpp:1024
#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:922
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:1075
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:811
#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:1092
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:708
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_builder_free(dxfc_dxendpoint_builder_t builder)
Removes a builder from the registry.
Definition DXEndpoint.cpp:799
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:990
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:1135
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:73
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:769
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_get_feed(dxfc_dxendpoint_t endpoint, DXFC_OUT dxfc_dxfeed_t *feed)
Definition DXEndpoint.cpp:1158
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:1058
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_close(dxfc_dxendpoint_t endpoint)
Closes this endpoint.
Definition DXEndpoint.cpp:905
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:659
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:1007
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:939
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_user(dxfc_dxendpoint_t endpoint, const char *user)
Changes username for this endpoint.
Definition DXEndpoint.cpp:956
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:858
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:834
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:675
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:881
DXFCPP_EXPORT dxfc_error_code_t dxfc_dxendpoint_free(dxfc_dxendpoint_t endpoint)
Removes the dxFeed endpoint from the registry.
Definition DXEndpoint.cpp:1168
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:1041
Builder class for DXEndpoint that supports additional configuration properties.
Definition DXEndpoint.hpp:850
std::shared_ptr< DXEndpoint > build()
Builds DXEndpoint instance.
Definition DXEndpoint.cpp:335
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:378
bool supportsProperty(const StringLike &key) const
Checks if a property is supported.
Definition DXEndpoint.cpp:325
std::shared_ptr< Builder > withProperties(Properties &&properties)
Sets all supported properties from the provided properties object.
Definition DXEndpoint.hpp:939
~Builder() noexcept override
Releases the GraalVM handle.
Definition DXEndpoint.cpp:367
std::shared_ptr< Builder > withRole(Role role)
Sets role for the created DXEndpoint.
Definition DXEndpoint.cpp:297
std::shared_ptr< Builder > withProperty(const StringLike &key, const StringLike &value)
Sets the specified property.
Definition DXEndpoint.cpp:310
Subscription for a set of symbols and event types.
Definition DXFeedSubscription.hpp:44
bool containsEventType(const EventTypeEnum &eventType) override
Returns true if this subscription contains the corresponding event type.
Definition DXFeedSubscription.cpp:227
std::size_t addChangeListener(std::shared_ptr< ObservableSubscriptionChangeListener > listener) override
Adds subscription change listener.
Definition DXFeedSubscription.cpp:318
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:433
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:356
std::unordered_set< EventTypeEnum > getEventTypes() override
Returns a set of subscribed event types.
Definition DXFeedSubscription.cpp:223
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:258
void removeSymbols(SymbolIt begin, SymbolIt end) const
Removes the specified collection (using iterators) of symbols from the set of subscribed symbols.
Definition DXFeedSubscription.hpp:505
void removeSymbols(SymbolsCollection &&collection) const
Removes the specified collection of symbols from the set of subscribed symbols.
Definition DXFeedSubscription.hpp:531
static const std::int32_t MAX_BATCH_LIMIT
The maximum events' batch limit for a single notification in OnEventHandler.
Definition DXFeedSubscription.hpp:60
void removeSymbols(const SymbolWrapper &symbolWrapper) const
Removes the specified symbol from the set of subscribed symbols.
Definition DXFeedSubscription.cpp:277
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:292
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:55
std::size_t addEventListener(std::function< void(const std::vector< std::shared_ptr< EventT > > &)> &&listener)
Adds typed listener for events.
Definition DXFeedSubscription.hpp:674
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:273
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:384
void setAggregationPeriod(const TimePeriod &aggregationPeriod) const
Sets the aggregation period for data.
Definition DXFeedSubscription.cpp:296
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:352
std::size_t addEventListener(EventListener &&listener)
Adds listener for events.
Definition DXFeedSubscription.hpp:619
static std::shared_ptr< DXFeedSubscription > create(EventTypesCollection &&eventTypes)
Creates a detached subscription for the given collection of event types.
Definition DXFeedSubscription.hpp:260
OnEventHandler & onEvent()
Returns a reference to an incoming events' handler (delegate), to which listeners can be added and re...
Definition DXFeedSubscription.cpp:312
void addSymbols(const SymbolsCollection &collection) const
Adds the specified collection of symbols to the set of subscribed symbols.
Definition DXFeedSubscription.hpp:459
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:358
void setAggregationPeriod(std::int64_t aggregationPeriod) const
Sets the aggregation period for data.
Definition DXFeedSubscription.cpp:304
void removeChangeListener(std::size_t changeListenerId) override
Removes subscription change listener by id.
Definition DXFeedSubscription.cpp:335
std::vector< SymbolWrapper > getDecoratedSymbols() const
Returns a set of decorated symbols (depending on the actual implementation of the subscription).
Definition DXFeedSubscription.cpp:249
void clear() const
Clears the set of subscribed symbols.
Definition DXFeedSubscription.cpp:231
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:262
void setAggregationPeriod(std::chrono::milliseconds aggregationPeriod) const
Sets the aggregation period for data.
Definition DXFeedSubscription.cpp:300
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:288
std::vector< SymbolWrapper > getSymbols() const
Returns a set of subscribed symbols (depending on the actual implementation of the subscription).
Definition DXFeedSubscription.cpp:240
Extends DXFeedSubscription to conveniently subscribe to time-series of events for a set of symbols an...
Definition DXFeedSubscription.hpp:785
std::int64_t getFromTime()
Returns the earliest timestamp from which time-series of events shall be received.
Definition DXFeedSubscription.cpp:384
void setFromTime(std::chrono::milliseconds fromTime)
Sets the earliest timestamp from which time-series of events shall be received.
Definition DXFeedSubscription.cpp:395
void setFromTime(std::int64_t fromTime)
Sets the earliest timestamp from which time-series of events shall be received.
Definition DXFeedSubscription.cpp:388
The enumeration type that provides additional information about the dxFeed Graal C++-API event type.
Definition EventTypeEnum.hpp:26
Mixin for wrapping calls to common promise methods.
Definition Promise.hpp:79
JavaException getException() const
Returns exceptional outcome of computation.
Definition Promise.hpp:127
void cancel() const
This method cancels computation.
Definition Promise.hpp:174
bool hasResult() const
Returns true when computation has completed normally.
Definition Promise.hpp:95
bool isCancelled() const
Returns true when computation was cancelled.
Definition Promise.hpp:114
bool hasException() const
Returns true when a computation has completed exceptionally or was canceled.
Definition Promise.hpp:104
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:161
bool isDone() const
Returns true when a computation has completed normally, or exceptionally, or was canceled.
Definition Promise.hpp:85
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:144
Manages network connections to feed or publisher.
Definition DXEndpoint.hpp:179
bool isClosed() const
Definition DXEndpoint.cpp:511
SimpleHandler< void(DXEndpoint::State, DXEndpoint::State)> & onStateChange() noexcept
Returns the onStateChange handler that can be used to add or remove listeners.
Definition DXEndpoint.cpp:523
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:498
std::shared_ptr< DXFeed > getFeed() const
Definition DXEndpoint.cpp:224
std::shared_ptr< DXEndpoint > password(const StringLike &password)
Changes password for this endpoint.
Definition DXEndpoint.cpp:151
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:144
void reconnect() const
Terminates all established network connections and initiates connecting again with the same address.
Definition DXEndpoint.cpp:170
static std::shared_ptr< DXEndpoint > create()
Creates an endpoint with FEED role.
Definition DXEndpoint.cpp:489
void removeStateChangeListener(std::size_t listenerId) noexcept
Removes a listener notified about changes in state property.
Definition DXEndpoint.cpp:519
const std::string & getName() const &noexcept
Definition DXEndpoint.cpp:515
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:388
void awaitProcessed() const
Waits until this endpoint stops processing data (becomes quiescent).
Definition DXEndpoint.cpp:206
std::shared_ptr< DXPublisher > getPublisher() const
Definition DXEndpoint.cpp:233
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:140
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:197
static std::shared_ptr< DXEndpoint > getInstance(Role role)
Returns a default application-wide singleton instance of DXEndpoint for a specific role.
Definition DXEndpoint.cpp:471
static const std::string DXFEED_AGGREGATION_PERIOD_PROPERTY
"dxfeed.aggregationPeriod"
Definition DXEndpoint.hpp:265
void close() const
Closes this endpoint.
Definition DXEndpoint.cpp:527
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:179
void closeAndAwaitTermination() const
Closes this endpoint and wait until all pending data processing tasks are completed.
Definition DXEndpoint.cpp:215
static std::shared_ptr< DXEndpoint > getInstance()
Returns a default application-wide singleton instance of DXEndpoint with a FEED role.
Definition DXEndpoint.cpp:462
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
void disconnectAndClear() const
Terminates all remote network connections and clears stored data.
Definition DXEndpoint.cpp:188
Role getRole() const noexcept
Returns the role of this endpoint.
Definition DXEndpoint.cpp:507
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:480
std::shared_ptr< DXEndpoint > connect(const StringLike &address)
Connects to the specified remote address.
Definition DXEndpoint.cpp:158
Main entry class for dxFeed API (read it first).
Definition DXFeed.hpp:119
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
std::vector< std::shared_ptr< E > > getTimeSeriesIfSubscribed(const SymbolWrapper &symbol, std::int64_t fromTime) const
Returns time series of events for the specified event type, symbol and a range of time (without an up...
Definition DXFeed.hpp:1006
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:722
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:990
std::vector< std::shared_ptr< E > > getTimeSeriesIfSubscribed(const SymbolWrapper &symbol, std::int64_t fromTime, std::int64_t 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:938
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< Promise< std::vector< std::shared_ptr< E > > > > getTimeSeriesPromise(const SymbolWrapper &symbol, std::int64_t fromTime, std::int64_t toTime) const
Requests time series of events for the specified event type, symbol and a range of time.
Definition DXFeed.hpp:886
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:361
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:676
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:308
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:1021
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:473
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:248
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:629
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:411
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:581
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:540
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:775
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:831
const Collection & getLastEvents(const Collection &events)
Returns the last events for the specified list of event instances.
Definition DXFeed.hpp:269
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:243
std::shared_ptr< E > getResult() const
Returns result of computation.
Definition Promise.hpp:251
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:261
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:291
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:276
Marks all event types that can be received via dxFeed API.
Definition EventType.hpp:36
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:25
static void throwIfJavaThreadExceptionExists()
Throws a JavaException if it exists (i.e. intercepted by Graal SDK)
Definition JavaException.cpp:31
static JavaException create(void *exceptionHandle)
Creates an exception using native (GraalVM) Java exception handle.
Definition JavaException.cpp:21
JavaException(const StringLike &message, const StringLike &className, const StringLike &stackTrace)
Creates an exception using Java message, className and stack trace.
Definition JavaException.cpp:13
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:29
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:441
Result of a computation that will be completed normally or exceptionally in the future.
Definition Promise.hpp:357
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:25
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:111
A simple wrapper around strings or something similar to strings to reduce the amount of code for meth...
Definition Common.hpp:842
A lightweight wrapper around strings or string-like inputs.
Definition StringUtils.hpp:27
Common string constants used across the library.
Definition StringUtils.hpp:128
static const std::string NUL
Textual representation of a null / missing string: "<null>".
Definition StringUtils.hpp:133
static const std::string EMPTY
Empty string constant: "".
Definition StringUtils.hpp:130
Value class for a period of time with support for ISO8601 duration format.
Definition TimePeriod.hpp:27
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:184
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:216
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:231
void await() const
Wait for the computation to complete and return its result or throw an exception in case of exception...
Definition Promise.hpp:201
void getResult() const
Returns result of computation.
Definition Promise.hpp:191
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