This sample demonstrates how to create a repeating group, read repeating group values, create a nested repeating group and read nested repeating group values.
#include <OnixS/FIXEngine/FIX/FIX44.h>
#include "../../Common/Helpers.h"
#include "../../Common/Settings.h"
using namespace Settings;
namespace {
Message createMarketDataRequestMessage();
void processMarketDataRequestMessage(const Message & request);
Message createMessageWithNestedRepeatingGroups();
void processMessageWithNestedRepeatingGroups(const Message & order);
};
int main()
{
try {
EngineSettings settings;
settings.listenPort(-1)
.licenseStore(LicenseStore);
Engine::init(settings);
Message marketDataRequest = createMarketDataRequestMessage();
std::clog << "Created FIX message in the native (tag=value) format:\n\n" << marketDataRequest << std::endl;
std::clog << "\nThe same message in human-readable format:\n\n" << marketDataRequest.toString(' ',
MessageStringingFlag::IncludeFieldName) << std::endl;
processMarketDataRequestMessage(marketDataRequest);
Message order = createMessageWithNestedRepeatingGroups();
processMessageWithNestedRepeatingGroups(order);
}
catch(const std::exception & ex) {
processSampleException(ex.what());
}
Engine::shutdown();
return 0;
}
namespace {
Message createMarketDataRequestMessage()
{
Message request(FIX44::Values::MsgType::MarketDataRequest, ProtocolVersion::FIX_44);
request.set(FIX44::Tags::MDReqID, "1")
.set(FIX44::Tags::SubscriptionRequestType, FIX44::Values::SubscriptionRequestType::SnapshotUpdate)
.set(FIX44::Tags::MarketDepth, "0")
.set(FIX44::Tags::MDUpdateType, FIX44::Values::MDUpdateType::Full);
Group marketDataEntryTypes = request.setGroup(FIX44::Tags::NoMDEntryTypes, 3);
marketDataEntryTypes[0].set(FIX44::Tags::MDEntryType, FIX44::Values::MDEntryType::Bid);
marketDataEntryTypes[1].set(FIX44::Tags::MDEntryType, FIX44::Values::MDEntryType::Offer);
marketDataEntryTypes[2].set(FIX44::Tags::MDEntryType, FIX44::Values::MDEntryType::Trade);
Group relatedSymbols = request.setGroup(FIX44::Tags::NoRelatedSym, 2);
relatedSymbols[0].set(FIX44::Tags::Symbol, "EUR/USD");
relatedSymbols[1].set(FIX44::Tags::Symbol, "GPS/USD");
request.validate();
return request;
}
void processMarketDataRequestMessage(const Message & request)
{
if(FIX44::Values::MsgType::MarketDataRequest == request.type()) {
Group marketDataEntryTypes = request.getGroup(FIX44::Tags::NoMDEntryTypes);
std::clog << "\nProcessing " << request.toString(' ') << std::endl;
for(size_t index = 0; index < marketDataEntryTypes.size(); ++index)
std::clog << "Market Data Entry # " << index << " : MDEntryType = " <<
marketDataEntryTypes[index].getChar(FIX44::Tags::MDEntryType) << std::endl;
}
}
Message createMessageWithNestedRepeatingGroups()
{
Message order(FIX44::Values::MsgType::NewOrderSingle, ProtocolVersion::FIX_44);
order.
set(FIX44::Tags::ClOrdID,
"ClOrdID value");
Group partiesGroup = order.setGroup(FIX44::Tags::NoPartyIDs, 1);
partiesGroup[0].
set(FIX44::Tags::PartyID,
"Party ID value");
Group partiesSubGroup = partiesGroup[0].setGroup(FIX44::Tags::NoPartySubIDs, 3);
partiesSubGroup[0].
set(FIX44::Tags::PartySubID,
"PartySubID value0");
partiesSubGroup[1].
set(FIX44::Tags::PartySubID,
"PartySubID value1");
partiesSubGroup[2].
set(FIX44::Tags::PartySubID,
"PartySubID value2");
std::clog << "\n\nMessage with nested repeating group:\n" << order << std::endl;
return order;
}
void processMessageWithNestedRepeatingGroups(const Message & order)
{
if(FIX44::Values::MsgType::NewOrderSingle == order.type()) {
Group partiesGroup = order.
getGroup(FIX44::Tags::NoPartyIDs);
std::clog << "\nProcessing " + order.toString(' ') << std::endl;
for(size_t index = 0; index < partiesGroup.size(); ++index) {
Group partiesSubGroup = partiesGroup[index].getGroup(FIX44::Tags::NoPartySubIDs);
for(size_t nestedIndex = 0; nestedIndex < partiesSubGroup.size(); ++nestedIndex)
std::clog << "Parties SubGroup # " << nestedIndex << " : PartySubID = " <<
partiesSubGroup[nestedIndex].getStringRef(FIX44::Tags::PartySubID) << std::endl;
}
}
}
};