Creating a FIX market data request message
This post details the composition of a FIX 4.4 market data request message using the QuickFix/J framework (MsgType.MARKET_DATA_REQUEST), which entails the composition of repeated groups. In this example we illustrate this with the implementation of a method that requests market data for a list of instruments:
private static final MessageFactory messageFactory = new quickfix.fix44.MessageFactory();
private Message createMarketDataRequest(SessionID sessionIds, List symbols, String exchange) {
Message request = messageFactory.create("FIX.4.4", messageType);
request.setField(new MarketDepth(1)); // Top of book
request.setField(new MDReqID(UUID.randomUUID().toString()));
request.setChar(SubscriptionRequestType.FIELD, SubscriptionRequestType.SNAPSHOT);
Group entryTypeGroup =
messageFactory.create("FIX.4.4", MsgType.MARKET_DATA_REQUEST, NoMDEntryTypes.FIELD);
entryTypeGroup.setField(new MDEntryType(MDEntryType.BID));
request.addGroup(entryTypeGroup);
entryTypeGroup.setField(new MDEntryType(MDEntryType.OFFER));
request.addGroup(entryTypeGroup);
int numSymbols = symbols.size();
if (numSymbols == 0) {
request.setInt(NoRelatedSym.FIELD, numSymbols);
}
for (final String symbol : symbols) {
if (StringUtils.isNotBlank(symbol)) {
Group symbolGroup =
messageFactory.create("FIX.4.4", MsgType.MARKET_DATA_REQUEST, NoRelatedSym.FIELD);
symbolGroup.setField(new Symbol(symbol));
if (StringUtils.isNotBlank(exchange)) {
symbolGroup.setField(new SecurityExchange(exchange));
}
request.addGroup(symbolGroup);
}
}
return request;
}
Posted at
03:56PM Jan 05, 2012
by Zeger Hendrikse in Finance |