Skip to content
ashelleyhft edited this page Apr 27, 2015 · 12 revisions

TransFix

Overview

TransFix is a Fix4.2 version fast fix parser for parsing inbound fix messages. It can also be used by a OMS/EMS to send out FIX messages. This is a standard Fix4.2 implementation and at this time does not allow custom fix message configurations. Since TransFix is used in the eco-system of Chronicle, all message transactions can be persisted. TransFix uses a fast, off-heap object pool for Fix message sessions. This is useful when there is a need to read/send multiple FIX messages during transactions with multiple clients.

Object Construction

To download the JAR which contains TransFix package, we recommend you use maven, which will download it from Maven Central, once you have installed maven, all you have to do is add the following to your projects pom.xml :

<dependency>
  <groupId>net.openhft</groupId>
  <artifactId>fix-compiler</artifactId>
  <version><!--replace with the latest version--></version>
</dependency>

In order to create an instance of TransFix, its recommended to use the FixMessageBuilder

net.openhft.fix.include.v42;
...........

FixMessagePool fmp = new FIXMessageBuilder().initFixMessagePool(true, fixMsgCount);
FixMessageContainer<FixMessage> fmc = fmp.getFixMessageContainer();
FixMessage fm = fmc.getFixMessage();

For initFixMessagePool(boolean default, int fixMsgCount); method, if default variable is true, then FIXMessageBuilder loads pre-defined configuration as per FIX 4.2 version schema. Using default config, all FIX 4.2 protocol version fields are loaded for each FixMessage inside FixMessagePool. All FIX fields are accessibly by passing the exact field ID. For example, in order to set or get the message type (FIX 35=??), fm.getField(35).getFieldData() or fm.setField(35).setFieldData(6) for "Indication of interest". Each of the corresponding Field loaded in a FixMessage contains its own ByteBufferBytes data field of default size 1024 bytes. For multiple values, the data is separated by default delimiter "|" which is set to SOH (0x01) value while sent back on wire. Since the default config will load all of the described fields (1-436) for each FixMessage inside FixMessagePool, its recommended to custom load fields of necessity while constructing via FixMessageBuilder. This flexibility allows to control the size of FixMessage object.

Following is an example:

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import net.openhft.fix.include.util.FixMessagePool;
import net.openhft.fix.include.util.FixMessagePool.FixMessageContainer;
import net.openhft.fix.include.v42.FIXMessageBuilder;
import net.openhft.fix.include.v42.Field;
import net.openhft.fix.include.v42.FixMessage;
import net.openhft.fix.include.v42.FixMessageReader;
import net.openhft.lang.io.ByteBufferBytes;
import net.openhft.lang.io.DirectStore;
import net.openhft.lang.io.NativeBytes;

public class TestTransFix {
	
	
	public static void main (String[] args) throws Exception{
		
		TestTransFix ttf = new TestTransFix();
		ttf.readEditModifyFixMsg();	
		
	}
	
	private void readEditModifyFixMsg() throws Exception {
		String sampleFixMessage = "8=FIX.4.2|9=154|35=6|49=BRKR|56=INVMGR|34=238|52=19980604-07:59:56|23=115686|28=N|55=AXX.AX|54=2|27=250000|44=7900.000000|25=H|10=231|";
		
		int fixMsgCount = Runtime.getRuntime().availableProcessors();
		
		//create fix message pool with default configuration for each FixMessage
		FixMessagePool fmp = new FIXMessageBuilder().initFixMessagePool(true, fixMsgCount);
		FixMessageContainer<FixMessage> fmc = fmp.getFixMessageContainer();
		
		//check out a FixMessage object
		FixMessage fm = fmc.getFixMessage();
		
		//create an instance of FixMessageReader instance for parsing
		FixMessageReader fmr = new FixMessageReader(fm);
		
		//An instance of NativeBytes for converting a String to bytes data 
		byte [] msgBytes = sampleFixMessage.replace('|', '\u0001').getBytes();
		ByteBufferBytes byteBufBytes = new ByteBufferBytes(ByteBuffer.allocate(msgBytes.length).order(ByteOrder.nativeOrder()));
		byteBufBytes.write(msgBytes);
	   	
		//setting and parsing the fix message
		fmr.setFixBytes(byteBufBytes);		
        fmr.parseFixMsgBytes();
        
        //gets a Field array with parsed data
        Field[] field = fmr.getFixMessage().getField();
        
        //Sets a checkedout FixMessage instance object with the FIX message information.
        for (int i=0;i<field.length;i++){
        	fm.getField(i).setFieldData(field[i].getFieldData());
        }   
         		
	}
         		
		
}

Performance

TransFix supports java.lang.String or ByteBufferBytes as input data to FixMessageBuilder. Its recommended to use ByteBufferBytes for maximum performance even though a basic String will work ok. The average ByteBufferBytes message parsing time is 0.05us while for transmitting a FixMessage the average latency is about 1.5us. Refer to the link below for examples of tests

Clone this wiki locally