Parse FIX Message

Parse FIX Message

As you saw in privious example you saw how to convert string to FIX message here I will show once you received the message how to parse it to get actual value:

Note: You could directly downlaed QuickFix jar from its web site here. To make this example work right away I have used quickfixj-all 1.6.0 version where you could convert your string message to any FIX version and for this example we are using FIX 4.2.

  • FixMessageTypeFields.Java:
package com.javahonk;

public enum FixMessageTypeFields {

	MSGTYPE(35),
	QTY(32),
	PRICE(31),
	EXECTRANSTYPE(20),
	EXECTYPE(150),
	EXECID(17),
	ORDERID(37),
	SIDE(54),
	UNDERLIERSTOCKSYMBOL(55),
	TRANSACTTIME(60),
	SENDINGTIME(52),
	FUTSETTDATE(64),
	SECURIRYTYPE(167),
	SEND(10335),
	TRADERID(11107),
	LEGALENTITIY(111320),
	ACCOUNTNAME(111321),
	
	//Assigned values	
	EXECTYPEVALUE(0),
	EXECTRANSTYPEVALUE(0),	
	MSGTYPEVALUE("D"),
	SECURITYTYPEVALUE("CS"),
	BUY("BUY"),
	SELL("SELL"),
	SENDVALUE("Y");
	
	private int value = 0;
	private String assignedValue = null;
	
	FixMessageTypeFields(int value) {
		this.value = value;
	}
	
	FixMessageTypeFields(String messageValue) {
		this.assignedValue = messageValue;
	}

	public int getValue() {
		return value;
	}

	public String getAssignedValue() {
		return assignedValue;
	}
	
}
  • ParseFIXMessage.java:
package com.javahonk;

import java.math.BigDecimal;
import java.time.LocalDateTime;

import quickfix.DoubleField;
import quickfix.IntField;
import quickfix.MessageParseError;
import quickfix.MessageUtils;
import quickfix.StringField;
import quickfix.fix42.Message;



public class ParseFIXMessage {

	public static void main(String[] args) throws MessageParseError {
		
		Message message = new Message();
		
		
		StringField msgType = new StringField(FixMessageTypeFields.MSGTYPE.getValue(), FixMessageTypeFields.MSGTYPEVALUE.getAssignedValue());
		DoubleField qty = new DoubleField(FixMessageTypeFields.QTY.getValue(), 100.00);
		DoubleField price = new DoubleField(FixMessageTypeFields.PRICE.getValue(), 59.99);
		IntField execTransType = new IntField(FixMessageTypeFields.EXECTRANSTYPE.getValue(), FixMessageTypeFields.EXECTRANSTYPEVALUE.getValue());
		IntField execType = new IntField(FixMessageTypeFields.EXECTYPE.getValue(), FixMessageTypeFields.EXECTYPEVALUE.getValue());
		StringField orderID = new StringField(FixMessageTypeFields.ORDERID.getValue(), "123456789");
		BigDecimal origQuantity = BigDecimal.valueOf(100.00);
		String sideTemp = origQuantity.compareTo(BigDecimal.valueOf(0.0)) < 0 ? FixMessageTypeFields.BUY.getAssignedValue() : FixMessageTypeFields.SELL.getAssignedValue();
		StringField side = new StringField(FixMessageTypeFields.SIDE.getValue(), sideTemp);
		StringField underlierStockSymbol = new StringField(FixMessageTypeFields.UNDERLIERSTOCKSYMBOL.getValue(), ".SPX");
		StringField transactTime = new StringField(FixMessageTypeFields.TRANSACTTIME.getValue(), LocalDateTime.now().toString());
		StringField sendingTime = new StringField(FixMessageTypeFields.SENDINGTIME.getValue(), LocalDateTime.now().toString());
		StringField futSettDate = new StringField(FixMessageTypeFields.FUTSETTDATE.getValue(), LocalDateTime.now().plusDays(2).toString());
		StringField securityType  = new StringField(FixMessageTypeFields.SECURIRYTYPE.getValue(), FixMessageTypeFields.SECURITYTYPEVALUE.getAssignedValue());
		StringField send  = new StringField(FixMessageTypeFields.SEND.getValue(), FixMessageTypeFields.SENDVALUE.getAssignedValue());
		StringField traderID  = new StringField(FixMessageTypeFields.TRADERID.getValue(), "Java Honk");
		StringField legalEntity  = new StringField(FixMessageTypeFields.LEGALENTITIY.getValue(), "Java Honk");
		StringField accountName  = new StringField(FixMessageTypeFields.ACCOUNTNAME.getValue(), "123456");
		StringField execID  = new StringField(FixMessageTypeFields.EXECID.getValue(), "123654987");
		
		message.setField(msgType);
		message.setField(qty);
		message.setField(price);
		message.setField(execTransType);
		message.setField(execType);
		message.setField(orderID);
		message.setField(side);
		message.setField(underlierStockSymbol);
		message.setField(transactTime);
		message.setField(sendingTime);
		message.setField(futSettDate);
		message.setField(securityType);
		message.setField(send);
		message.setField(traderID);
		message.setField(legalEntity);
		message.setField(accountName);
		message.setField(execID);		
		
		String fixMessage = message.toString();
		System.out.println("Origional FIX message:-->"+fixMessage+"\n");
		System.out.println(MessageUtils.getStringField(fixMessage, 8));
		System.out.println(MessageUtils.getStringField(fixMessage, 17));
		System.out.println(MessageUtils.getStringField(fixMessage, 20));
		System.out.println(MessageUtils.getStringField(fixMessage, 31));
		System.out.println(MessageUtils.getStringField(fixMessage, 32));
		System.out.println(MessageUtils.getStringField(fixMessage, 35));
		System.out.println(MessageUtils.getStringField(fixMessage, 37));
		System.out.println(MessageUtils.getStringField(fixMessage, 52));
		System.out.println(MessageUtils.getStringField(fixMessage, 54));
		System.out.println(MessageUtils.getStringField(fixMessage, 55));
		System.out.println(MessageUtils.getStringField(fixMessage, 60));
		System.out.println(MessageUtils.getStringField(fixMessage, 64));
		System.out.println(MessageUtils.getStringField(fixMessage, 150));		
		System.out.println(MessageUtils.getStringField(fixMessage, 167));
		System.out.println(MessageUtils.getStringField(fixMessage, 10335));
		System.out.println(MessageUtils.getStringField(fixMessage, 11107));
		System.out.println(MessageUtils.getStringField(fixMessage, 111320));
		System.out.println(MessageUtils.getStringField(fixMessage, 111321));
		System.out.println(MessageUtils.getStringField(fixMessage, 10));

	}

}
  • Output:

Parse FIX Message

Leave a Reply

Your email address will not be published. Required fields are marked *