FIX

FIX Protocol Message Containers – Lightweight low latency message encoder/decoder

Summary

The to-fix project is a low latency high performance FIX message containers written in Java. The message containers are generated based on an extended QuickFIX XML specification. The to-fix containers supports all FIX versions, 4.2,4.3, 4.4, 5.0, 5.0Sp1, 5.0,sp2, FIXT including adaptations like FIX 4.2 INET Nordic.

A user should modify the XML specification and generate containers for the particular FIX dialect used on the target exchange.

Performance

Fix message encoding and decoding latency; comparison of to-fix with quickFixj on a Intel Core i7 3..07GHz

Developers Guide

  1. Create Customized XML specification based fixprotocol.org FIX repository or by manually editing existing templates.
  2. Generate Message Containers using the to-fix-FixMessageGenerator.

Create Customized XML

Message java code is generated based on an XML specification following the format that extends theQuickFix XML format.

If the exchange provide a standerd FIX Repository the XML specification may be generated using the fix-repository-to-quickfix-xml. Else the specificaion need to be manually created. See extended QuickFix XML Format for details.

Sample of extended QuickFix XML specifications.

Generate Message Containers

Prerequisites Download the latest to-fix-FixMessageGenerator jar file from Downloads

Run the message generator:

java -jar to-fix-FixMessageGenerator-x.x.jar <my_xml_spec> <my_code>
# example
# java -jar to-fix-FixMessageGenerator.jar C:\Users\seto\Desktop\src\to-fix\repository\FIX42Nordic.xml 
# C:\Users\seto\Desktop\src\to-fix\src\main\java

Usage

For users of the to-fix FIX message containers.

Prerequisites

Create or download the protocol dialect jar at Downloads.

Simple Code Example

Simple example directly allocating the FIX message objects.

// allocate your out bound message
FixLogon logon = new FixLogon();
// populate the fields
logon.heartBtInt = 10;
// ...
// to get field values
long heartBtInt = logon.heartBtInt;
 
// In-bound message from raw fix message ByteBuffer in buf
ByteBuffer buf = ByteBuffer.wrap(new String("8=FIXT.1.1\u00019=82\u0001"+
"35=A\u000149=TOC\u000156=TOMAC\u000134=1\u000150=TOC\u0001"+
"57=S\u000152=20110211-05:40:09.425\u000198=0\u0001108=30\u0001"+
"1137=9\u000110=102\u0001").getBytes());
// In-bound message from raw fix message byte buffer
 
try {
        // Get the message type 
        FixMessage.crackMsgType(buf);
        // based on message type pares the message
        FixLogon logon = new FixLogon();
 
        // decode the message
        logon.setBuffer(buf);
        logon.getAll();
 
        // get field values
        long bodyLength = logon.bodyLength;
        // ...
} catch (FixGarbledException e) {
        // this message is garbled 
} catch (FixSessionException e) {
        // this message contins static fix session error(s)
        // like tag value, enumerated values, required tags.
}


Proper Example Message Listener

A proper example, using a message listener for inbound messages.

// create a listener, parser and error holder for in-bound FIX messages
MyFixMessageListener listener = new MyFixMessageListener();
FixMessageParser parser = new FixMessageParser();
 
ByteBuffer buf = ByteBuffer.wrap(new String("8=FIXT.1.1\u00019=82\u0001"+
"35=A\u000149=TOC\u000156=TOMAC\u000134=1\u000150=TOC\u0001"+
"57=S\u000152=20110211-05:40:09.425\u000198=0\u0001108=30\u0001"+
"1137=9\u000110=102\u0001").getBytes());
// the buf ByteBuffer contains the raw fix message
try {
        parser.parse(buf, listener);
} catch (FixSessionException e) {
        // this message is garbled
} catch (FixGarbledException e) {
        // this message contins static fix session error(s)
}

Validator

The FIX message parser exposes a validator, enabling dynamic session validation (like MsgSeqNum?, SendingTime?, validity of compIDs). Implement the interface FixSessionValidator?, and set it. The FixSessionValidator? has one method; public boolean validate(FixMessage? msg) throws FixSessionException? {return true;}. If session validation the implementation should throw a FixSessionException?. On successful session validation (e.g. no Exception thrown), the validator return value determines if the listener is called or not. If the validate returns false, the parser will not call the listener. If the parser returns true the listener will be called.