A message can be created in two different ways:
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.addTag(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);
To get a FIX field value, use the FIXFieldList.getTagValueAsXXX(int tag) methods. For example, if you need a string value please use FIXFieldList.getTagValueAsString(int tag), if you need int - FIXFieldList.getTagValueAsInt(int tag), etc.
Please pay attention that FIXFieldList.getTagValueAsString(int tag) and FIXFieldList.getTagValueAsBytes(int tag) return a null if this tag is not present in message. The rest methods for accessing value as primitive type throw an FieldNotFoundException if there is no such tag.
To add a field to message please use a set of FIXFieldList.addTag() methods with different parameters.
To change a field value please use FIXFieldList.set() methods:
message.set(148, "Hello there");
Note: the tag will be added to the message if such tag is absent.
To remove a field by tag, use the FIXFieldList.removeTag(int tag) method. This method returns "true" if the given tag is found and the field is removed. Otherwise the method returns "false".
message.removeTag(148);
To get a value from repeating group use FIXFieldList.getTagValueAsXXX(int tag, int occurrence) Example:
FIXFieldList messageContent = new FIXFieldList(); // prepare message messageContent.addTag(148, "Hello there"); // Add Subject messageContent.addTag(33, 3); // Add Repeating group messageContent.addTag(58, "line1"); messageContent.addTag(58, "line2"); messageContent.addTag(58, "line3"); System.out.println(messageContent.getTagValueAsString(58, 2));
another more convenient option is to use FIXFieldList.split(int leadingTagNumber)
FIXFieldList messageContent = new FIXFieldList(); // prepare message messageContent.addTag(148, "Hello there"); // Add Subject messageContent.addTag(33, 3); // Add Repeating group messageContent.addTag(58, "line1"); messageContent.addTag(58, "line2"); messageContent.addTag(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.getTagValueAsString(58)); // line1 line2 line3 }
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.addTag(theCustomTag, "0.15"); // sets the tag value
To clone a FIX message, use the FIXFieldList.clone() method.