...
- Install FIX Antenna Java™
- Update your project to include FIX Antenna libraries
- Convert QuickFIX/J configuration files into FIX Antenna Java™ format
- Update your project to replace QuickFIX/J API with FIX Antenna API
- Optional. Convert the dictionaries into FIXDIC format
- Compile and run
1. Install FIX Antenna Java™
...
3. Convert QuickFIX/J configuration files into FIX Antenna Java™ format
QuickFIX/J | FIX Antenna Java |
---|
123456789101112131415161718192021222324
[
default
]
|
[default]
FileStorePath=target/data/app |
|
SocketConnectHost=localhost |
|
123456789101112131415161718192021222324sessionIDs=initiatorS, acceptorS
#Default session parameters
sessions | sessionIDs=initiatorS, acceptorS
#Default session parameters
sessions.default.storageDirectory=target/data/app |
|
sessions.default.heartbeatInterval=30 |
|
sessions.default.fixVersion=FIX.4.4 |
|
## Session initiatorS
## Session initiatorS
sessions.initiatorS.sessionType=initiator |
|
sessions.initiatorS.host=localhost |
|
sessions.initiatorS.port=9876 |
|
sessions.initiatorS.senderCompID=BANZAI |
|
sessions.initiatorS.targetCompID=EXEC |
|
//0 - infinitive autoreconnect |
|
sessions.initiatorS.autoreconnectAttempts=0 |
|
sessions.initiatorS.autoreconnectDelayInMs=5000 |
|
## Session acceptorS
## Session acceptorS
sessions.acceptorS.sessionType=acceptor |
|
sessions.acceptorS.senderCompID=EXEC |
|
sessions.acceptorS.targetCompID=BANZAI
|
|
44. Update your project to replace QuickFIX/J API with FIX Antenna API
4.1. Session configuration and start - Acceptor
QuickFIX/J | FIX Antenna Java |
---|
1234
56789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import
quickfix.*;
import
java.io.FileInputStream;
public
class
QFJApp {
public
static
void
main(String args[])
throws
Exception {
if
(args.length !=
1
) {
return
;
}
String fileName = args[
0
];
Application application =
new
FooApplication();
SessionSettings settings =
new
SessionSettings(
new
FileInputStream(fileName));
MessageStoreFactory storeFactory =
new
FileStoreFactory(settings);
MessageFactory messageFactory =
new
DefaultMessageFactory();
Acceptor acceptor =
new
SocketAcceptor(application, storeFactory, settings, messageFactory);
acceptor.start();
| import quickfix.*;
import java.io.FileInputStream;
public class QFJApp {
public static void main(String args[]) throws Exception {
if (args.length != 1) {
return;
}
// path to file with session's configuration
String fileName = args[0];
// FooApplication is your class that implements the Application interface
Application application = new FooApplication();
SessionSettings settings = new SessionSettings(new FileInputStream(fileName));
MessageStoreFactory storeFactory = new FileStoreFactory(settings);
MessageFactory messageFactory = new DefaultMessageFactory();
// start acceptor
Acceptor acceptor =
new SocketAcceptor(application, storeFactory, settings, messageFactory);
acceptor.start();
// preventing application from exiting
System.out.println("Press enter to exit"); |
|
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import
com.epam.fix.message.FIXFieldList;
import
com.epam.fixengine.*;
import
com.epam.fixengine.acceptor.DenyNonRegisteredAcceptorStrategyHandler;
import
com.epam.fixengine.configuration.Configuration;
import
java.io.IOException;
import
java.util.ArrayList;
import
java.util.List;
public
class
SimpleAcceptorServer
implements
FIXServerListener {
private
List<FIXSession> activeSessions =
new
ArrayList<FIXSession>();
public
static
void
main(String[] args)
throws
IOException {
if
(args.length !=
1
) {
return
;
}
String fileName = args[
0
];
Configuration globalServerConfig = Configuration.getGlobalConfiguration();
globalServerConfig.setProperty(Configuration.SERVER_ACCEPTOR_STRATEGY,
| Code Block |
---|
language | java |
---|
linenumbers | true |
---|
| import com.epam.fix.message.FIXFieldList;
import com.epam.fixengine.*;
import com.epam.fixengine.acceptor.DenyNonRegisteredAcceptorStrategyHandler;
import com.epam.fixengine.configuration.Configuration;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
// implements FIXServerListener to get notifications about new connections
public class SimpleAcceptorServer implements FIXServerListener {
// all active sessions should have references or will be GCed
private List<FIXSession> activeSessions = new ArrayList<FIXSession>();
public static void main(String[] args) throws IOException {
if (args.length != 1) {
return;
}
String fileName = args[0];
// enable server strategy for accepting only registered sessions
Configuration globalServerConfig = Configuration.getGlobalConfiguration();
globalServerConfig.setProperty(Configuration.SERVER_ACCEPTOR_STRATEGY,
DenyNonRegisteredAcceptorStrategyHandler.class.getCanonicalName()); |
|
// create server that will listen for TCP/IP |
|
connections
FIXServer server =
new
connections
FIXServer server = new FIXServer(); |
|
// setting listener for new |
|
connections
connections
server.setListener(new |
|
// setting path to properties file with sessions
server.setConfigPath(fileName); |
|
// starting new thread and listen for incoming |
|
connections
connections
server.start(); |
|
// preventing application from |
|
exiting
exiting
System.out.println("Press enter to exit"); |
|
// stop the thread that listens for new |
|
connections
connections
server.stop(); |
|
}
public
void
newFIXSession(FIXSession session) {
try
{
}
// this method is called for every new connection
public void newFIXSession(FIXSession session) {
try {
activeSessions.add(session); |
|
// setting listener for incoming messages; |
|
// MyFIXSessionListener is is your class that |
|
implements
implements
// the FIXSessionListener |
|
interface
interface
session.setFIXSessionListener(new |
|
MyFIXSessionListener(session)); |
|
session
session
session.connect(); |
|
}
catch
(IOException e) {
}
}
} catch (IOException e) {
}
}
} |
|
4.2. Session configuration and start - Initiator
QuickFIX/J | FIX Antenna Java |
---|
1234
56789101112131415161718192021222324252627282930313233343536373839import
quickfix.*;
import
java.io.FileInputStream;
public
class
QFJInitiator {
public
static
void
main(String args[])
throws
Exception {
if
(args.length !=
1
)
return
;
String fileName = args[
0
];
Application application =
new
FooApplication();
SessionSettings settings =
new
SessionSettings(
new
FileInputStream(fileName));
MessageStoreFactory storeFactory =
new
FileStoreFactory(settings);
MessageFactory messageFactory =
new
DefaultMessageFactory();
Initiator initiator =
new
SocketInitiator(application, storeFactory, settings, messageFactory);
initiator.start();
| import quickfix.*;
import java.io.FileInputStream;
public class QFJInitiator {
public static void main(String args[]) throws Exception {
if (args.length != 1) return;
// path to file with session's configuration
String fileName = args[0];
// FooApplication is your class that implements the Application interface
Application application = new FooApplication();
SessionSettings settings = new SessionSettings(new FileInputStream(fileName));
MessageStoreFactory storeFactory = new FileStoreFactory(settings);
MessageFactory messageFactory = new DefaultMessageFactory();
Initiator initiator =
new SocketInitiator(application, storeFactory, settings, messageFactory);
initiator.start();
// preventing application from exiting
System.out.println("Press enter to exit"); |
|
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import
| Code Block |
---|
language | java |
---|
linenumbers | true |
---|
| import com.epam.fix.message.FIXFieldList;
import com.epam.fix.message. |
|
FIXFieldList;import
com.epam.fix.message. com.epam.fixengine.session.util.SessionParametersBuilder; |
|
import
import java.io.IOException; |
|
public
class
SimpleInitiator {
public
static
void
public class SimpleInitiator {
public static void main(String[] args) |
|
{
if
{
return
;
}
String configFile = {
return;
}
String configFile = args[0]; |
|
configuration
SessionParameters details =
configuration
SessionParameters details =
SessionParametersBuilder.buildSessionParameters(configFile, |
|
// create session we intend to work |
|
with
final
FIXSession session = with
final FIXSession session = details.createNewFIXSession(); |
|
// setting listener for incoming messages; |
|
// MyFIXSessionListener is is your class that |
|
implements
implements
// the FIXSessionListener interface
session.setFIXSessionListener(new |
|
MyFIXSessionListener(session)); |
|
connection
try
{
connection
try {
session.connect(); |
|
}
catch
(IOException e) {
}
} catch (IOException e) {
}
// preventing application from exiting
System.out.println("Press enter to exit"); |
|
// stop the thread that listens for new |
|
connections
session connections
session.disconnect("user request"); |
|
}
4.3. Compose message: flat model
QuickFIX/J | FIX Antenna Java |
---|
1234Message message =
new
567891011121314 | Message message = new Message(); |
|
message.getHeader().setField(new |
|
message.getHeader().setField(new |
|
message.getHeader().setField(new |
|
message.getHeader().setField(new |
|
// Side, with value enumeration |
|
CharField(54, Side.BUY))); |
|
// ... and other fields as necessary ... |
|
1234567891011121314FIXFieldList messageContent =
new
| FIXFieldList messageContent = new FIXFieldList(); |
|
messageContent.addTag(49, |
|
messageContent.addTag(56, |
|
messageContent.addTag(35, |
|
message.addTag(54, Side.BUY.getValue()); |
|
// ... and other fields as necessary ... |
|
4.4. Compose message: object model (not recomened for FIXAJ due to low perfomance)
QuickFIX/J | FIX Antenna Java |
---|
123456quickfix.fix42.ExecutionReport message |
|
=
new
=
new quickfix.fix42.ExecutionReport |
|
(
new
new
new
new
123456// Create an "Execution Report" message for FIX 4.2 |
|
4.5. Create message with repeating groups
QuickFIX/J | FIX Antenna Java |
---|
1234public
void
createRG(){
567891011121314151617181920212223 | public void createRG(){
quickfix.fix42.MarketDataSnapshotFullRefresh message |
|
=
new
=
new quickfix.fix42.MarketDataSnapshotFullRefresh(new |
|
quickfix.fix42.MarketDataSnapshotFullRefresh.NoMDEntries group |
|
=
new
=
new quickfix.fix42.MarketDataSnapshotFullRefresh.NoMDEntries(); |
|
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | public
void
createRG(){
FIXFieldList message = FIXFieldListFactory.newInstanceFromPool();
| Code Block |
---|
language | java |
---|
linenumbers | true |
---|
| public void createRG(){
FIXFieldList message = FIXFieldListFactory.newInstanceFromPool();
message.addTag(Symbol, |
|
RepeatingGroup group =
RepeatingGroup group = message.addRepeatingGroup(NoMDEntries); |
|
RepeatingGroup.Entry entry1 = group.addEntry(); |
|
entry1.addTag(MDEntryType, |
|
entry1.addTag(MDEntrySize, |
|
RepeatingGroup.Entry entry2 = group.addEntry(); |
|
entry2.addTag(MDEntryType, |
|
entry2.addTag(MDEntrySize, |
|
pool
4.6. Reading message with repeating group
QuickFIX/J | FIX Antenna Java |
---|
1234public
void
56789101112131415161718192021 | public void processRG(quickfix.fix42.MarketDataSnapshotFullRefresh message) |
|
{
NoMDEntries noMDEntries =
new
{
NoMDEntries noMDEntries = new NoMDEntries(); |
|
message.get(noMDEntries); |
|
quickfix.fix42.MarketDataSnapshotFullRefresh.NoMDEntries group |
|
=
new
=
new quickfix.fix42.MarketDataSnapshotFullRefresh.NoMDEntries(); |
|
MDEntryType MDEntryType =
new
MDEntryType MDEntryType = new MDEntryType(); |
|
MDEntryPx MDEntryPx =
new
MDEntryPx MDEntryPx = new MDEntryPx(); |
|
MDEntrySize MDEntrySize =
new
MDEntrySize MDEntrySize = new MDEntrySize(); |
|
OrderID orderID =
new
OrderID orderID = new OrderID(); |
|
message.getGroup(1, group); |
|
message.getGroup(2, group); |
|
123456789101112131415161718192021public
void
| public void processRG(FIXFieldList message) |
|
{
RepeatingGroup group = {
RepeatingGroup group = message.getRepeatingGroup(NoMDEntries); |
|
RepeatingGroup.Entry entry = group.getEntry(0); |
|
byte
mdEntryType =
byte mdEntryType = entry.getTagValueAsByte(MDEntryType); |
|
double
mdEntryPx =
double mdEntryPx = entry.getTagValueAsDouble(MDEntryPx); |
|
long
mdEntrySize =
long mdEntrySize = entry.getTagValueAsLong(MDEntrySize); |
|
String orderId =
String orderId = entry.getTagValueAsString(OrderID); |
|
entry =
entry = group.getEntry(1); |
|
mdEntryType =
mdEntryType = entry.getTagValueAsByte(MDEntryType); |
|
mdEntryPx =
mdEntryPx = entry.getTagValueAsDouble(MDEntryPx); |
|
mdEntrySize =
mdEntrySize = entry.getTagValueAsLong(MDEntrySize); |
|
orderId =
orderId = entry.getTagValueAsString(OrderID); |
|
}
4.7. Sending message
QuickFIX/J | FIX Antenna Java |
---|
1234567891011void
| void sendOrderCancelRequest() |
|
{
{
quickfix.fix41.OrderCancelRequest message |
|
=
new
=
new quickfix.fix41.OrderCancelRequest( |
|
new
new
new
new
Text("Cancel My Order!")); |
|
Session.sendToTarget(message, |
|
1234567891011void
| void sendOrderCancelRequest(FIXSession session) |
|
{
FIXFieldList message = {
FIXFieldList message = FIXFieldListFactory.newInstanceFromPool(); |
|
message.addTag(OrigClOrdID, |
|
message
message.addTag(Side, BUY.getValue()); |
|
session.sendMessage("F", message); |
|
4.8. Receiving and cracking message
QuickFIX/J | FIX Antenna Java |
---|
12345678910private
static
class
FooApplication
implements
Application {
| private static class FooApplication implements Application {
//... other |
|
methods
methods
// here you can process incomming |
|
messages
public
void
messages
public void fromApp(Message message, SessionID sessionID) |
|
throws
throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue |
|
{
StringField field =
new
{
StringField field = new StringField(55); |
|
}
}
1 2 3 4 5 6 7 8 9 | class
MyFIXSessionListener
implements
FIXSessionListener {
| Code Block |
---|
language | java |
---|
linenumbers | true |
---|
| class MyFIXSessionListener implements FIXSessionListener {
//... other |
|
methods
methods
// here you can process incoming |
|
messages
public
void
messages
public void onNewMessage(FIXFieldList message) |
|
{
String symbol = {
String symbol = message.getTagValueAsString(55); |
|
// or other getTagValueAsXXX() |
|
methods
}
}
4.9. Minimal sample
QuickFIX/J | FIX Antenna Java |
---|
1234String fileName = args[
0
];
Application application =
new
FooApplication();
SessionSettings settings =
new
SessionSettings(
new
FileInputStream(fileName));
MessageStoreFactory storeFactory =
new
FileStoreFactory(settings);
MessageFactory messageFactory =
new
DefaultMessageFactory();
Acceptor acceptor =
new
SocketAcceptor(application, storeFactory, settings, messageFactory);
acceptor.start();
5678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485import
quickfix.*;
import
java.io.FileInputStream;
public
class
QFJApp {
public
static
void
main(String args[])
throws
Exception {
if
(args.length !=
1
) {
return
;
}
| import quickfix.*;
import java.io.FileInputStream;
public class QFJApp {
public static void main(String args[]) throws Exception {
if (args.length != 1) {
return;
}
// path to file with session's configuration
String fileName = args[0];
// FooApplication is your class that implements the Application interface
Application application = new FooApplication();
SessionSettings settings = new SessionSettings(new FileInputStream(fileName));
MessageStoreFactory storeFactory = new FileStoreFactory(settings);
MessageFactory messageFactory = new DefaultMessageFactory();
// start acceptor
Acceptor acceptor =
new SocketAcceptor(application, storeFactory, settings, messageFactory);
acceptor.start();
// preventing application from exiting
System.out.println("Press enter to exit"); |
|
}
private
static
class
FooApplication
implements
Application {
public
void
onCreate(SessionID sessionId) {}
public
void
onLogon(SessionID sessionId) {}
public
void
onLogout(SessionID sessionId) {}
public
void
toAdmin(Message message, SessionID sessionId) {}
public
void
toApp(Message message, SessionID sessionId)
throws
DoNotSend {}
public
void
fromAdmin(Message message, SessionID sessionId)
throws
FieldNotFound, IncorrectDataFormat,
IncorrectTagValue, RejectLogon {}
public
void
fromApp(Message message, SessionID sessionId)
throws
FieldNotFound, IncorrectDataFormat,
IncorrectTagValue, UnsupportedMessageType {
System.out.println(
"New message is accepted: "
+ message.toString());
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | import
}
private static class FooApplication implements Application {
public void onCreate(SessionID sessionId) {}
public void onLogon(SessionID sessionId) {}
public void onLogout(SessionID sessionId) {}
public void toAdmin(Message message, SessionID sessionId) {}
public void toApp(Message message, SessionID sessionId) throws DoNotSend {}
public void fromAdmin(Message message, SessionID sessionId)
throws FieldNotFound, IncorrectDataFormat,
IncorrectTagValue, RejectLogon {}
public void fromApp(Message message, SessionID sessionId)
throws FieldNotFound, IncorrectDataFormat,
IncorrectTagValue, UnsupportedMessageType {
System.out.println("New message is accepted: " + message.toString());
}
}
}
|
| Code Block |
---|
language | java |
---|
linenumbers | true |
---|
| import com.epam.fix.message.FIXFieldList; |
|
com.epam.fixengine.acceptor.DenyNonRegisteredAcceptorStrategyHandler; |
|
com.epam.fixengine.configuration.Configuration; |
|
import
import java.io.IOException; |
|
// implements FIXServerListener to get notifications about new connections |
|
class
SimpleAcceptorServer
implements
FIXServerListener {
private
List<FIXSession> activeSessions =
new
ArrayList<FIXSession>();
public
static
void
class SimpleAcceptorServer implements FIXServerListener {
// all active sessions should have references or will be GCed
private List<FIXSession> activeSessions = new ArrayList<FIXSession>();
public static void main(String[] args) |
|
{
if
{
return
;
}
String fileName = {
return;
}
String fileName = args[0]; |
|
// enable server strategy for accepting only registered |
|
sessions
Configuration globalServerConfig = sessions
Configuration globalServerConfig = Configuration.getGlobalConfiguration(); |
|
globalServerConfig.setProperty(Configuration.SERVER_ACCEPTOR_STRATEGY, |
|
DenyNonRegisteredAcceptorStrategyHandler.class.getCanonicalName()) |
|
;
;
// create server that will listen for TCP/IP |
|
connections
FIXServer server =
new
connections
FIXServer server = new FIXServer(); |
|
// setting listener for new |
|
connections
connections
server.setListener(new |
|
;
;
// setting path to properties file with |
|
sessions
sessions
server.setConfigPath(fileName); |
|
// starting new thread and listen for incoming |
|
connections
connections
server.start(); |
|
preventing application from exiting
preventing application from exiting
System.out.println("Press enter to exit"); |
|
// stop the thread that listens for new |
|
connections
connections
server.stop(); |
|
}
public
void
newFIXSession(FIXSession session) {
try
{
}
// this method is called for every new connection
public void newFIXSession(FIXSession session) {
try {
activeSessions.add(session); |
|
// setting listener for incoming messages; |
|
// MyFIXSessionListener is is your class that |
|
implements
implements
// the FIXSessionListener |
|
interface
interface
session.setFIXSessionListener(new |
|
MyFIXSessionListener(session)); |
|
session
session
session.connect(); |
|
}
catch
(IOException e) {
}
}
private
class
MyFIXSessionListener
implements
FIXSessionListener {
private
FIXSession session;
public
MyFIXSessionListener(FIXSession session) {
this
.session = session;
}
public
void
onSessionStateChange(SessionState sessionState) {
} catch (IOException e) {
}
}
// listener for incoming messages and session state changes
private class MyFIXSessionListener implements FIXSessionListener {
private FIXSession session;
public MyFIXSessionListener(FIXSession session) {
this.session = session;
}
// this method will be called every time session state is changed
public void onSessionStateChange(SessionState sessionState) {
System.out.println("Session state: " |
|
// if disconnected, dispose it to let GC collect |
|
it
if
(SessionState.DISCONNECTED == sessionState) {
it
if (SessionState.DISCONNECTED == sessionState) {
session.dispose(); |
|
System.out.println("Your session has been disconnected." |
|
+
" Press ENTER to exit the programm."
);
}
}
public
void
onNewMessage(FIXFieldList message) {
+ " Press ENTER to exit the programm.");
}
}
public void onNewMessage(FIXFieldList message) {
System.out.println("New message is accepted: " |
|
}
}
5. Optional. Convert the dictionaries into FIXDIC format
...