Technology weblog

Thursday Jan 05, 2012

A collection of useful FIX protocol links

This post summarizes some useful links I have collected during my experiences with QuickFix/J:

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));
  entryTypeGroup.setField(new MDEntryType(MDEntryType.OFFER));

  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));
  return request;

Reading repeating groups in FIX market data reponse

This short post details how to read out repeating groups in a FIX 4.4 MsgType.MARKET_DATA_SNAPSHOT_FULL_REFRESH message using QuickFix/J. In the example below I have requested the bid and offer prices, which implies that I get returned two repeating groups. First all groups are retrieved, and then we loop through the groups to extract the subsequent fields:

final String symbol = message.getString(Symbol.FIELD);

final List<Group> groups = message.getGroups(NoMDEntries.FIELD);
BigDecimal bidPrice = null;
BigDecimal offerPrice = null;
BigDecimal bidSize = null;
BigDecimal offerSize = null;
for (final Group oneGroup : groups) {
  final char type = oneGroup.getChar(MDEntryType.FIELD);
  if (type == MDEntryType.OFFER) {
    offerPrice = oneGroup.getDecimal(MDEntryPx.FIELD);
    offerSize = oneGroup.getDecimal(MDEntrySize.FIELD);
  } else if (type == MDEntryType.BID) {
    bidPrice = oneGroup.getDecimal(MDEntryPx.FIELD);
    bidSize = oneGroup.getDecimal(MDEntrySize.FIELD);

Thursday Dec 22, 2011

Youtube tutorials on the FIX protocol

Today I found a post on another weblog, referring to 4 concise introductory tutorials on the FIX protocol. For those who are interested, check it out!

Hire us