Preface
This article describes the FIX-over-FAST connectivity using the B2BITS FIX Antenna Java (tm) library.
Overview
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.
Quick start for CME
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.
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"));
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);
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);
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);
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");
final FIXSession session;
try {
session = details.createNewFIXSession();
} catch (IOException e) {
throw new RuntimeException(e);
}
FIXSessionListener application = new FIXSessionListener() {
public void onSessionStateChange(SessionState sessionState) {
System.out.println("Session state changed:" + sessionState);
if (sessionState == SessionState.DISCONNECTED) {
session.dispose();
}
}
public void onNewMessage(FIXFieldList message) {
System.out.println("New application level message type: " + message.getTag(FIXT11.Header.MsgType).getStringValue() + " received ");
}
};
session.setFIXSessionListener(application);
try {
snapshots.connect();
incremental.connect();
replay.connect();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
FIX to FAST mapping
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 | |
Advance start for CME
This sections explains how to create a CME application step-by step with samples. The usual scenario to get it to work is:
- Create a application parameters
- Creaet application listener
- Creaet application instance
- Subscribe to instarument
- Close application
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.
Createion of application parameters
The parameters is created in the following way:
ApplicationParams params = new ApplicationParams();
params.setUriToConfig(uriToConfig);
params.setUriToTemplates(uriToTemplates);
Createion an application listener
The application listener is created in the following way:
ApplicationListener cmeAppListener = new ApplicationListener() {
public void process(FIXFieldList message) {
}
public void onError(String secDesc, long secID, String error) {
}
};
Createion an application instance
The application instance is created in the following way:
Application application = new ApplicationImpl(params, cmeAppListener);
Subscribe to instrument
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) {
}
};
application.subscribeBySecurityDesc("SYMBOL", instrumentListener, RecoveryOptions.Market);
Close the application
The application is closed in the following way:
application.unsubscribeAll();
application.stop();
Quick start for BOVESPA
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";
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];
}
final FASTClientFactory clientFactory = FASTClientFactory.createFASTFactory(new FileInputStream(pathToTamplates));
final IFASTChannel fastChannel = clientFactory.createFASTChannel(new UDPTransport(host, port), new FIXFASTListener() {
public void onFIXMessage(FIXFieldList message) {
System.out.println(message);
}
}, ChanelVersion.BOVESPA);
try {
fastChannel.connect();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static void printUsage() {
System.out.println(BOVESPAFastClientSample.class.getSimpleName() + " <host> <port> [<template>]");
}
}
Advance start for BOVESPA
This sections explains how to create a BOVESPA channel step-by step with samples. The usual scenario to get it to work is:
- Create a channel parameters
- Creaet instrument listeners
- Creaet a channel instance
- Subscribe to instrument
- Close application
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.
Createion of application parameters
The parameters is created in the following way:
final ConfigurationParser configurationParser = new ConfigurationParser("../etc/config.xml);
final MDChannel mdChannel = configurationParser.getChannelId("050");
Createion an application listener
The instrument listener is created in the following way:
ChannelMessageListener implements InstrumentListener {
public void onIncrement(final long rptSeqNum, final FIXFieldList entry);
}
public void onSnapshot(final FIXFieldList message);
}
};
Creation of channel instance
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 to instrument
channel.subscribeSymbol("SYMBOL");
Close the application
The channel is closed in the following way:
channel.unsubscribeAll();