FIX Message

Create

A message can be created in two different ways:

  1. Create a skeleton and set fields
  2. Parse a raw FIX message (byte array)

To create a framework for a FIX application-level message, use the FIXFieldList constructor. Thereafter you can set the desired field values of a message and send it to the counter-party. In general FIXFieldList is just a List <FIXField> so it contains all the methods from java.util.List plus a few convenient methods to manipulate tags and groups of tags.

For example:

FIXFieldList messageContent = new FIXFieldList();
messageContent.add(148, "Hello there"); // or longer version: messageContent.add(new FIXField(148, "Hello there"));

To parse a string containing a raw FIX message into the FIXMessage class, use the RawFIXUtil.getFIXFieldList(byte[]) method.

For example:

byte[] bytes =
    "8=FIX.4.3\u00019=94\u000135=A\u000149=target\u000156=sender\u0001115=onBehalf\u000134=1\u000150=senderSub" +
    "\u000152=20080212-04:15:18.308\u000198=0\u0001108=600\u000110=124\u0001".getBytes();

FIXFieldList msg = RawFIXUtil.getFIXFieldList(bytes);

Get field

To get a FIX field value as string, use the FIXFieldList.getTagStringValue(int tag) method. Or use message.getTag(tag).getValue() to get a byte array .

This method retrieves the field value by tag number or returns null if this tag is not present in message.

Add field

To add a field to message use the FIXFieldList.add(FIXField field) method.

Set field

To change a field value get the tag and use setValue:

message.getTag(148).setValue("Hello there");

Note: you will get NullPointerException if this field is not present in message.

Remove field

To remove a field by tag, use the FIXFieldList.getTag(int tag) method to get FIXField and use FIXFieldList.remove(Object field) to remove it from message.

This method returns "true" if the given tag is found and the field is removed. Otherwise the method returns "false".

message.remove(message.getTag(148));

Repeating group

To get a value from repeating group use FIXFieldList.getTag(int tag, int occurence) Example:

FIXFieldList messageContent = new FIXFieldList(); // prepare message
messageContent.add(new FIXField(148, "Hello there")); // Add Subject
messageContent.add(new FIXField(33, 3)); // Add Repeating group
messageContent.add(new FIXField(58, "line1"));
messageContent.add(new FIXField(58, "line2"));
messageContent.add(new FIXField(58, "line3"));

System.out.println(messageContent.getTag(58, 2).getStringValue());

another more convenient option is to use FIXFieldList.split(int leadingTagNumber)

FIXFieldList messageContent = new FIXFieldList(); // prepare message
messageContent.add(new FIXField(148, "Hello there")); // Add Subject
messageContent.add(new FIXField(33, 3)); // Add Repeating group
messageContent.add(new FIXField(58, "line1"));
messageContent.add(new FIXField(58, "line2"));
messageContent.add(new FIXField(58, "line3"));
List<FIXFieldList> repeatingGroups= messageContent.split(58);
// we have a list of 3 groups and each group in our case
// contains a repeating group with single 58 tag.
for (FIXFieldList repeatingGroup:repeatingGroups){
    System.out.println(repeatingGroup.getTag(58).getValue()); // line1 line2 line3
}

User defined fields

User Defined Fields (tag numbers from 5000 to 9999) are handled like ordinary fields.

For example:

int theCustomTag = 5000; // reserved for user defined fields
// generates a new FIX message
FIXFieldList messageContent = new FIXFieldList();
messageContent.add(new FIXField(theCustomTag, "0.15")); // sets the tag value

Clone message

To clone a FIX message, use the FIXFieldList.clone() method.

Generated on Wed Jun 8 16:39:30 2011 for FIXAntennaJava by  doxygen 1.6.3