This sample demonstrates how to connect to the RDI and EMDI feeds.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
22
23#include "../Common/Signal.h"
24#include "../Common/Options.h"
25#include "../Common/Settings.h"
26#include "../Common/Utils.h"
27
28#include "MyListener.h"
29
31
33int main(int argc, char* argv[])
34{
35
36 const Samples::AppConfiguration<
37 Samples::NetworkInterfaceConfiguration
38 , Samples::EnvironmentConfiguration
39 , Samples::LogDirectoryConfiguration
40 > cfg{"Advanced", argc, argv};
41
42 try
43 {
44 Samples::SignalHelper::manageSignals();
45
49
50 auto rdiSettings = Samples::makeSettings<RdiHandlerSettings>(cfg);
51 fillEnvironment(rdiSettings, cfg);
52
53 MyListener myListener{rdiSettings.logDirectory};
54
55 auto rdiHandler = Samples::makeUnique<RdiHandler>(rdiSettings);
56
57 rdiHandler
58 ->bindFeedEngine(feedEngine)
59 .registerErrorListener(&myListener)
60 .registerWarningListener(&myListener)
61 .registerReferenceDataListener(&myListener);
62
63 std::clog << "Will start the RDI Handler ..." << std::endl;
64 rdiHandler->start();
65
66 myListener.waitUntilReferenceDataReceived();
67
68 auto emdiSettings = Samples::makeSettings<EmdiHandlerSettings>(cfg);
69 emdiSettings.buildInternalOrderBooks = true;
70 emdiSettings.lostPacketWaitTime = 500;
71
72 std::vector<std::unique_ptr<EmdiHandler>> handlers;
73
74 const auto descriptors = rdiHandler->findEmdiDescriptors({"FDAX", "FGBL", "FGBM", "FSMI"});
75 for(auto && descriptor : descriptors)
76 {
77 emdiSettings.logFileNamePrefix = std::string("Emdi_") + descriptor.productInfos[0].marketSegment;
78 emdiSettings.interfaceDescriptor.incrementalFeed = descriptor.incrementalFeed;
79 emdiSettings.interfaceDescriptor.snapshotFeed = descriptor.snapshotFeed;
80
81 handlers.emplace_back(Samples::makeUnique<EmdiHandler>(emdiSettings));
82
83 auto& handler = handlers.back();
84
85 handler->
86 bindFeedEngine(feedEngine)
87
88 .registerErrorListener(&myListener)
89 .registerWarningListener(&myListener)
90 .registerDepthListener(&myListener)
91 .registerTopOfBookImpliedListener(&myListener)
92 .registerProductStateChangeListener(&myListener)
93 .registerMassInstrumentStateChangeListener(&myListener)
94 .registerInstrumentStateChangeListener(&myListener)
95 .registerQuoteRequestListener(&myListener)
96 .registerCrossRequestListener(&myListener)
97 .registerComplexInstrumentUpdateListener(&myListener)
98 .registerFlexibleInstrumentUpdateListener(&myListener)
99 .registerOrderBookListener(&myListener)
100 .registerTradeListener(&myListener)
101
102 .setMarketSegmentId2Depth(descriptor.marketSegmentId2Depth)
103 .setPartitionIdFilters(descriptor.partitionIdFilters)
104 .setMarketSegmentIdFilters(descriptor.marketSegmentIdFilters);
105
106 handler->start();
107 }
108
109 Samples::SignalHelper::waitUntilKey("to stop the handlers");
110
111 std::clog << "Stopping..." << std::endl;
112
113 for(auto && handler : handlers)
114 handler->stop();
115
116 handlers.clear();
117 rdiHandler->stop();
118
119 std::clog << "All the Handlers are stopped." << std::endl;
120 }
121 catch (const std::exception& ex)
122 {
123 std::cerr << "EXCEPTION: " << ex.what() << std::endl;
124 }
125
126 return 0;
127}
A pool of threads executing feed engine tasks.
The given class implements feed engine concept using pool of working threads and standard socket API.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#pragma once
21
22#include <iostream>
23#include <fstream>
24
40
41
42class MyListener final
57{
58public:
60 explicit MyListener(const std::string& logDir);
61
63 ~MyListener() override;
64
67
69 void onWarning(
const std::string& description)
override;
70
73
76
79
82
85
88
91
94
96 void waitUntilReferenceDataReceived();
97
99
102
105
108
111
114
117
120
123
126
129
132
135
138
141
144
145private:
148
149 std::ofstream referenceDataLog_;
150};
Complex Instrument Update listener.
virtual void onComplexInstrumentUpdate(const ComplexInstrumentUpdate &update, const DataSource &dataSource)=0
Is called when complex instrument update is received.
Complex instrument update.
virtual void onCrossRequest(const CrossRequest &request, const DataSource &dataSource)=0
Is called when cross request is received.
virtual void onDepthReset(MarketSegmentId marketSegmentId)=0
Is called when all the books are reset for a given market segment.
virtual void onDepthOutOfDate(MarketSegmentId marketSegmentId)=0
virtual void onDepthSnapshot(const DepthSnapshot &snapshot, const DataSource &dataSource)=0
Is called when depth snapshot is received.
virtual void onDepthIncremental(const DepthIncremental &incremental, const DataSource &dataSource)=0
Is called when depth incremental is received.
virtual void onError(ErrorCode::Enum code, const std::string &description)=0
Flexible Instrument Update listener.
virtual void onFlexibleInstrumentUpdate(const FlexibleInstrumentUpdate &update, const DataSource &dataSource)=0
Is called when mass instrument state change is received.
Mass instrument state change.
Instrument State Change listener.
virtual void onInstrumentStateChange(const InstrumentStateChange &change, const DataSource &dataSource)=0
Is called when instrument state change is received.
Mass Instrument State Change listener.
virtual void onMassInstrumentStateChange(const MassInstrumentStateChange &change, const DataSource &dataSource)=0
Is called when mass instrument state change is received.
Mass instrument state change.
virtual void onOrderBookUpdated(const OrderBook &book)=0
virtual void onOrderBookOutOfDate(const OrderBook &book)=0
Product State Change listener.
virtual void onProductStateChange(const ProductStateChange &change, const DataSource &dataSource)=0
Is called when product state change is received.
virtual void onQuoteRequest(const QuoteRequest &request, const DataSource &dataSource)=0
Is called when quote request is received.
virtual void onTradeAtReferencePriceStatus(const TradeAtReferencePriceStatus &status, const DataSource &dataSource)=0
Is called when TradeAtReferencePriceStatus message is received.
virtual void onSnapshotCycleStart()=0
Is called when reference data snapshot cycle is started.
virtual void onVarianceFuturesStatus(const VarianceFuturesStatus &status, const DataSource &dataSource)=0
Is called when variance futures status is received.
virtual void onSnapshotCycleEnd()=0
Is called when reference data snapshot cycle is ended.
virtual void onInstrumentIncremental(const InstrumentIncremental &incremental, const DataSource &dataSource)=0
Is called when instrument incremental update is received.
virtual void onProduct(const ProductSnapshot &snapshot, const DataSource &dataSource)=0
Is called when product snapshot is received.
virtual void onTotalReturnFuturesStatus(const TotalReturnFuturesStatus &status, const DataSource &dataSource)=0
Is called when total return futures status message is received.
virtual void onInstrument(const InstrumentSnapshot &snapshot, const DataSource &dataSource)=0
Is called when instrument snapshot is received.
Top Of Book Implied listener.
virtual void onTopOfBookImplied(const TopOfBookImplied &msg, const DataSource &dataSource)=0
Is called when Top Of Book Implied message is received.
Total return futures status message.
Total return futures status message.
virtual void onSnapshotTrade(const SnapshotTrade &trade)=0
Is called when a snapshot trade market data entry is received.
virtual void onIncrementalTrade(const IncrementalTrade &trade)=0
Is called when a incremental trade market data entry is received.
Variance futures status message.
virtual void onWarning(const std::string &reason)=0
Is called when the Warning condition is detected.
UInt32 MarketSegmentId
Alias for Market Segment ID type.
Enum
Known (selected) error codes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <iostream>
20#include <sstream>
21#include <fstream>
22
23#include "MyListener.h"
24
26
27
28
29
30
31MyListener::MyListener(const std::string& logDir)
32 : referenceDataReady_(0)
33{
34 const std::string referenceDataLogName = logDir + "/ReferenceData.txt";
35 referenceDataLog_.open(referenceDataLogName.c_str());
36 if(!referenceDataLog_)
37 throw std::domain_error("Cannot open " + referenceDataLogName);
38}
39
40MyListener::~MyListener() = default;
41
42void MyListener::onError(
ErrorCode::Enum code,
const std::string& description)
43{
44 std::clog <<
"Error occurred, errorCode = " <<
enumToString(code) <<
". Description: '" << description <<
"'" << std::endl;
45}
46
47void MyListener::onWarning(const std::string& description)
48{
49 std::stringstream ss;
50 std::clog << "Warning occurred. Description: '" << description << "'" << std::endl;
51}
52
53void MyListener::onSnapshotCycleStart()
54{
55 referenceDataLog_ << "onSnapshotCycleStart" << std::endl;
56}
57
59{
61}
62
64{
66}
67
69{
71}
72
74{
76}
77
79{
81}
82
84{
86}
87
88void MyListener::onSnapshotCycleEnd()
89{
90 referenceDataLog_ << "onSnapshotCycleEnd" << std::endl;
91 referenceDataReady_.release();
92}
93
94void MyListener::waitUntilReferenceDataReceived()
95{
96 referenceDataReady_.acquire();
97}
98
100{
101}
102
104{
105}
106
108{
109}
110
112{
113}
114
116{
117}
118
120{
121}
122
124{
125}
126
128{
129}
130
132{
133}
134
136{
137}
138
140{
141}
142
144{
145}
146
147void MyListener::onOrderBookUpdated(
const OrderBook&)
148{
149}
150
151void MyListener::onOrderBookOutOfDate(
const OrderBook&)
152{
153}
154
156{
157}
158
160{
161}
std::string toStringWithFieldNames() const
std::string enumToString(HandlerState::Enum)
Returns string representation of HandlerState value.