This article describes the FIX-over-FAST connectivity using the B2BITS FIX Antenna Java (tm) library.
The FAST protocol (FIX Adapted for STreaming) is a technology standard developed by FIX Protocol Ltd., specifically aimed at optimizing data representation on the network. It is used to support high-throughput, low latency data communications between financial institutions. In particular, it is a technology standard that offers significant compression capabillities for transporting high-volume market data feeds and creating ultra low latency applications.
Using B2BITS FIX Antenna Java(tm) a user can establish connection with a FIX-over-FAST oriented remote site. Current users are also able to migrate from FIX to FIX-over-FAST without significant code modifications.
This example provides a simple functionality for connecting to CME server and reading data from it. The data is converted from the FAST format to the FIX format. The converted data is printed to console.
{.java} package com.epam.example; import com.epam.common.transport.client.udp.UDPTransport; import com.epam.fast.full.session.client.*; import com.epam.fix.FIXVersion; import com.epam.fix.message.FIXFieldList; import com.epam.fix.message.constants.FIXT11; import com.epam.fixengine.*; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class CMEFastClientSample { public static void main(String[] args) throws FileNotFoundException { final FASTClientFactory clientFactory = FASTClientFactory.createFASTFactory(new FileInputStream("templates.xml")); // create one chanel for connecting to the CME // snapshots final IFASTChannel snapshots = clientFactory.createFASTChannel(new UDPTransport("224.0.26.1", 10001), new FIXFASTListener() { public void onFIXMessage(FIXFieldList message) { System.out.println(message); } }, ChanelVersion.CME); // incremental updates final IFASTChannel incremental = clientFactory.createFASTChannel(new UDPTransport("224.0.26.1", 10002), new FIXFASTListener() { public void onFIXMessage(FIXFieldList message) { System.out.println(message); } }, ChanelVersion.CME); //Instrumental Replay final IFASTChannel replay = clientFactory.createFASTChannel(new UDPTransport("224.0.26.1", 10003), new FIXFASTListener() { public void onFIXMessage(FIXFieldList message) { System.out.println(message); } }, ChanelVersion.CME); // TCP Replay SessionParameters details = new SessionParameters(); details.setFixVersion(FIXVersion.FIX42); details.setHost("224.0.26.1"); details.setHeartbeatInterval(30); details.setPort(10003); details.setSenderCompId("senderId"); details.setTargetCompId("targetId"); // create a session we intend to work with final FIXSession session; try { session = details.createNewFIXSession(); } catch (IOException e) { throw new RuntimeException(e); } // listener for incoming messages and session state changes FIXSessionListener application = new FIXSessionListener() { // this method will be called every time session state is changed public void onSessionStateChange(SessionState sessionState) { System.out.println("Session state changed:" + sessionState); // this callback is called upon session state change if (sessionState == SessionState.DISCONNECTED) { // end this session session.dispose(); } } // processing incoming messages public void onNewMessage(FIXFieldList message) { System.out.println("New application level message type: " + message.getTag(FIXT11.Header.MsgType).getStringValue() + " received "); // this callback is called upon a new message arrival } }; // setting listener for incoming messages session.setFIXSessionListener(application); try { // connect to the channels snapshots.connect(); incremental.connect(); replay.connect(); } catch (IOException e) { throw new RuntimeException(e); } } }
As far as FAST does not support the full range of FIX types, mapping between FAST and FIX types is needed. The following table lists all conversion paths.
FAST type | FIX application type | Comments |
u32 | i32 | Value must be in range [0, 2^31) |
u64 | i64 | Value must be in range [0, 2^63) |
u32 | i64 | Value must be in range [0, 2^32) |
u64 | u32 | |
u32 | u64 | Value must be in range [0, 2^32) |
i32 | u64 | Value must be in range [0, 2^31) |
i32 | i64 | Value must be in range (-2^31, 2^31) |
i64 | i32 | |
u64 | i32 | |
u32 | char | Value must be in range [0, 2^7) |
u32 | ascii | Value of string should be an integer in range [0, 2^32) |
u64 | ascii | Value of string should be an integer in range [0, 2^64) |
i64 | ascii | Value of string should be an integer in range (-2^64, 2^64) |
ascii | bool | The value of '\001' will be interpreted as true; otherwise it will be interpreted as false. |
ascii | char | |
ascii | i32 | |
ascii | i64 | |
i32 | char |
This sections explains how to create a CME application step-by step with samples. The usual scenario to get it to work is:
CME FAST Adaptor library allows application to subscribe to one or multiple instruments, supports all the features of CME market data channels including recovery. The CME distribution package includes the tool application. This is console application which supports market recovery and subcribtion to instruments.
The parameters is created in the following way:
// creates the application params ApplicationParams params = new ApplicationParams(); // sets uri to config file params.setUriToConfig(uriToConfig); // sets uri to templates file params.setUriToTemplates(uriToTemplates); // sets network interface name // params.setNetworkInterface("net1"); or params.setNetworkInterface("10.24.8.13");
The application listener is created in the following way:
// creates the application listener ApplicationListener cmeAppListener = new ApplicationListener() { public void process(FIXFieldList message) { // process message code here } public void onError(String secDesc, long secID, String error) { // process error code here } };
The application instance is created in the following way:
Application application = new ApplicationImpl(params, cmeAppListener);
// creates the instrument listener InstrumentListener instrumentListener = new InstrumentListener(){ public void onSubscribed(String secDesc, long secID) { } public void onUnsubscribed(String secDesc, long secID) { } ......... .................. public void process(FIXFieldList fixMessage) { } public void onSnapshot(String secDesc, long secID, FIXFieldList msg) { } public void onBookReset(String secDesc, long secID) { } public void onError(String secDesc, long secID, String error) { } }; // subscribe by 'SYMBOL' application.subscribeBySecurityDesc("SYMBOL", instrumentListener, RecoveryOptions.Market);
The application is closed in the following way:
application.unsubscribeAll(); application.stop();
This example provides a simple functionality for connecting to BOVESPA server and reading data from it. The data is converted from the FAST format to the FIX format. The converted data is printed to console.
public class BOVESPAFastClientSample { public static void main(String[] args) throws FileNotFoundException { if (args.length < 2) { printUsage(); System.exit(-1); } String host = args[0]; int port = 0; String pathToTamplates = "../etc/templates-UMDF.xml"; // default template try { port = Integer.parseInt(args[1]); } catch (Exception e) { throw new RuntimeException("Invalid value for port parameter.", e); } if (args.length == 3) { pathToTamplates = args[2]; } // Create factory for create FAST clients. final FASTClientFactory clientFactory = FASTClientFactory.createFASTFactory(new FileInputStream(pathToTamplates)); // create one chanel for connect to the CME final IFASTChannel fastChannel = clientFactory.createFASTChannel(new UDPTransport(host, port), new FIXFASTListener() { public void onFIXMessage(FIXFieldList message) { System.out.println(message); } }, ChanelVersion.BOVESPA); try { // Connect to the chanel fastChannel.connect(); } catch (IOException e) { throw new RuntimeException(e); } } private static void printUsage() { System.out.println(BOVESPAFastClientSample.class.getSimpleName() + " <host> <port> [<template>]"); } }
This sections explains how to create a BOVESPA channel step-by step with samples. The usual scenario to get it to work is:
BOVESPA FAST Adaptor library allows application to subscribe to one or multiple instruments, supports all the features of BOVESPA market data channels including recovery. The BOVESPA distribution package includes the tool application. This is console application which supports market recovery and subcribtion to instruments.
The parameters is created in the following way:
final ConfigurationParser configurationParser = new ConfigurationParser("../etc/config.xml); final MDChannel mdChannel = configurationParser.getChannelId("050");
The instrument listener is created in the following way:
// creates the instrument listener ChannelMessageListener implements InstrumentListener { // ..... .... public void onIncrement(final long rptSeqNum, final FIXFieldList entry); // process message code here } public void onSnapshot(final FIXFieldList message); // process code here } // ...... ..... };
The channel instance is created in the following way:
Channel channel = new ChannelImpl(mdChannel, RecoveryOptions.Market, ResourceLoader.DEFAULT_LOADER.loadResource(optionParams.getTemplateFileName())); channel.setMessageListener(new ChannelMessageListener());
// subscribe by 'SYMBOL' channel.subscribeSymbol("SYMBOL");
The channel is closed in the following way:
channel.unsubscribeAll();