FIX Prepared Message

Create

A prepared message can be created in three different ways:

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

To create a FIX prepared message please use the FIXSession.prepareMessage() and FIXSession.prepareMessageFromString() methods. Thereafter you can set/change the desired field values of a message and send it to the counter-party many times.

For example:

MessageStructure ms = new MessageStructure();
ms.reserveString(148, 11);
FIXFieldList pm = null;
try {
pm = session.prepareMessage("B", ms);
} catch (PreparedMessageException e) {
//handle error of building prepared message
}
pm.set(148, "Hello there");
session.sendMessage(pm);

To parse a string containing a raw FIX message into the FIXPreparedMessage class, use the FIXSession.prepareMessageFromString(byte[] message, String type, MessageStructure structure) method.

For example:

String message = "5=ABRA\u00016=KADABRA\u0001";
MessageStructure ms = new MessageStructure();
ms.reserve(5,4);
ms.reserve(6,7);
FIXFieldList pm = null;
try {
pm = session.prepareMessageFromString(message.getBytes(), "A", ms);
} catch (PreparedMessageException e) {
//handle error of building prepared message
}
session.sendMessage(pm);

To create prepared message from FIXFieldList object please use FIXSession.prepareMessage(FIXFieldList message, String type, MessageStructure structure) method

FIXFieldList list = new FIXFieldList();
list.addTag(1, "TestValue");
MessageStructure ms = new MessageStructure();
ms.reserve(1,9);
FIXFieldList pm = null;
try {
pm = session.prepareMessage(list,"A", ms);
} catch (PreparedMessageException e) {
//handle error of building prepared message
}
session.sendMessage(pm);

Add field

To add a field to message use the MessageStructure.reserve(int tagId, int length) method. Also you can give a hit to builder about field type with similar methods methods MessageStructure.reserveString(int tagId, int length) and MessageStructure.reserveLong(int tagId, int length). In the last case builder will be able to prepare more optimized structure for a new message. Keep in mind, all tags in message will be in order in which you have reserved it. Length is strictly fixed. If length of the tag is undetermined, you can use MessageStructure.VARIABLE_LENGTH constant as a length parameter in reserve(int,int) method. In such case length will be auto adjusted. But keep in mind such way is much more slower then fixed size for field. You will get a best perfomance if you prepared message will have only fixed length fields.

If you reserved 5 bytes, content length of this tag should be equal to 5 bytes too. Otherwise engine will mark the length for such field as undetermined (MessageStructure.VARIABLE_LENGTH) automatically. But there is an exception from this rule: if you try to set a numeric value (int, long, double) with a lover length, engine will automatically fill the tag value with leading "0" to the required length.

Fixed tag value length:

MessageStructure ms = new MessageStructure();
ms.reserve(1,9);
ms.reserveLong(54,1);

Variable tag value length:

MessageStructure ms = new MessageStructure();
ms.reserveString(58, MessageStructure.VARIABLE_LENGTH);

Set field

To change a field value use FIXFieldList.set() method:

message.set(148,"Hello there");
message.set(54,1;

In case of repeating groups you can use such way to set concrete tag value:

message.set(58,1,"Hello there");
message.set(58,2,"Hello there again");

Entries in repeating group have a numbers starting from 1.

Generated on Wed Aug 22 17:11:17 2018 for FIXAntennaJava by  doxygen 1.6.3