FIX Message Object Model

In contrast to flat model the object model allows addressing messages and fields by names. This interface is slower than the flat model, however it may appear to be more user-friendly.

Creating messages

There is a dedicated package for each FIX protocol version and a dedicated class for each message type. To create a "new order single" message by means of the object model simply create an instance of the corresponding class.

import com.epam.fix.model.fix44.message.NewOrderSingle;
// ...

// Create a "New order single" message for FIX 4.4
NewOrderSingle order = new NewOrderSingle();

Accessing fields

Fields can be accessed by names.

// Create an "Execution Report" message for FIX 4.2
ExecutionReport exec = new ExecutionReport();

// Set ClOrdID field to "2247"
exec.setOrderID("2247");
// Set ExecType field to Fill
exec.setExecType('1');
exec.setOrdStatus('2');
exec.setLeavesQty(0.0);
exec.setTransactTime(new GregorianCalendar());
// Remove the OrderID field from message
exec.setOrderID(null);

Repeating groups

Repeating groups are represented as Collections.

final NewOrderSingle newOrderSingle = new NewOrderSingle();
final Collection<NewOrderSingle.AllocsGroup> allocsGroups = new ArrayList<NewOrderSingle.AllocsGroup>();
final int noAllocs = 1;
for (int indexOfLoop = 0; indexOfLoop < noAllocs; indexOfLoop++) {
    final NewOrderSingle.AllocsGroup allocsGroup = newOrderSingle.new AllocsGroup();
    allocsGroup.setAllocAccount("221");
    allocsGroup.setAllocQty((double)indexOfLoop);
    allocsGroups.add(allocsGroup);
}
newOrderSingle.setAllocsGroup(allocsGroups);

Combining the flat and object models

You can use a factory or the fromFIX(FIXFieldList fieldlist) method to create an object message from the flat one.

byte[] bytes =
    "8=FIX.4.4\u00019=140\u000135=D\u000149=TESTI\u000156=TESTA\u000134=4\u000150=30737\u000197=Y" +
        "\u000152=20030204-08:46:14\u000111=90001008\u000155=TESTB\u000154=1\u000160=20060217-10:00:00" +
        "\u000138=4000\u000140=1\u0001847=100000000000\u0001".getBytes();
FIXFieldList msg = RawFIXUtil.getFIXFieldList(bytes);

// fromFIX
NewOrderSingle order = new NewOrderSingle();
order.fromFIX(msg);

// factory
com.epam.fix.model.fix44.Factory factory = new com.epam.fix.model.fix44.Factory();
order = (NewOrderSingle) factory.fromFIX(msg)

You can use the void toFIX(FIXFieldList l) method to get a flat message from the object one.

FIXFieldList msg = new FIXFieldList();
order.toFix(msg); // adds fields from order to msg

Sending object messages

To send an object message get the flat representation and send it.

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