Quickfix used to exchange the financial information between two organizations through TCP protocol. There are many language supports quickfix but most of them use java based application. Lets see hello world application in java.
Quick fix connection initiates based on the configuration. There are two parties involved in this connection, one called initiator and another party called acceptor. Initiator who starts the connection. In order to start the connection we need following details
1 . Acceptor host
2. Sender comp ID
3. Target Comp ID
4.User name and password.
We are not going to explain all the parameters can be configured in that file, We will explain only required information for this example.We can create two sessions,one for streaming and another one for trading. Sample configuration looks like below.
Now lets see how need to write java program to connect to the destination server. First we need to enable the socket connection to destination server. We should check we have telnet access destination server on ports.
Step 1 : Create class implements quickfix with default methods
Step 2 : Initiate Socket Connection
Step 3 : Logon
Each method call in quick has corresponding call back method. On successful login it will call back onLogon method for each session. Once logon is done it will start sending the heart beats in configured interval for both streaming and trading sessions. Now if we wanted to get the steaming price we need to subscribe for prices as per ROE provided by the acceptor. From now on any message is coming from destination server received through below method.
We can send messages to destination server is like below. We can use this methods to send order request/subscribe the currencies.
Each messages we are preparing and sending to the destinations based on the ROE provided by the acceptor server.
Quick fix connection initiates based on the configuration. There are two parties involved in this connection, one called initiator and another party called acceptor. Initiator who starts the connection. In order to start the connection we need following details
1 . Acceptor host
2. Sender comp ID
3. Target Comp ID
4.User name and password.
We are not going to explain all the parameters can be configured in that file, We will explain only required information for this example.We can create two sessions,one for streaming and another one for trading. Sample configuration looks like below.
[DEFAULT] ConnectionType=initiator SocketConnectHost=127.0.0.1 BeginString=FIX.4.4.xml HeartBtInt=60 CheckLatency=N StartTime=22:00:00 EndTime=22:05:00 StartDay=Sunday EndDay=Friday UseDataDictionary=Y ReconnectInterval=15 FileStorePath=C:/logs/session FileLogPath=C:/logs/client FileLogRollSize=1 FileStoreSync=N [SESSION] SenderCompID=SenderID TargetCompID=TargetID SocketConnectPort=1200 ResetOnLogon=Y ResetSeqNumFlag=Y [SESSION] SenderCompID=SenderID TargetCompID=TargetID SocketConnectPort=1201 ResetOnLogon=Y ResetSeqNumFlag=Y
Now lets see how need to write java program to connect to the destination server. First we need to enable the socket connection to destination server. We should check we have telnet access destination server on ports.
Step 1 : Create class implements quickfix with default methods
public class QuickFixHelloWorld implements Application{ @Override public void onCreate(SessionID sessionId) { // TODO Auto-generated method stub } @Override public void onLogon(SessionID sessionId) { // TODO Auto-generated method stub } @Override public void onLogout(SessionID sessionId) { // TODO Auto-generated method stub } @Override public void toAdmin(Message message, SessionID sessionId) { // TODO Auto-generated method stub } @Override public void fromAdmin(Message message, SessionID sessionId) throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue, RejectLogon { // TODO Auto-generated method stub } @Override public void toApp(Message message, SessionID sessionId) throws DoNotSend { // TODO Auto-generated method stub } @Override public void fromApp(Message message, SessionID sessionId) throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType { // TODO Auto-generated method stub } }
InputStream inputStream = new FileInputStream(new File(configFile)); SessionSettings settings = new SessionSettings(inputStream); inputStream.close(); MessageStoreFactory messageStoreFactory = new FileStoreFactory(settings); MessageFactory messageFactory = new DefaultMessageFactory(); Initiator initiator = new SocketInitiator(this, messageStoreFactory, settings, null, messageFactory); initiator.start();
Step 3 : Logon
Iterator<SessionID> sessionIds = initiator.getSessions().iterator(); while (sessionIds.hasNext()) { SessionID sessionId = (SessionID) sessionIds.next(); Session.lookupSession(sessionId).logon(); }
Each method call in quick has corresponding call back method. On successful login it will call back onLogon method for each session. Once logon is done it will start sending the heart beats in configured interval for both streaming and trading sessions. Now if we wanted to get the steaming price we need to subscribe for prices as per ROE provided by the acceptor. From now on any message is coming from destination server received through below method.
@Override public void fromAdmin(Message message, SessionID sessionId) throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue, RejectLogon { // TODO Auto-generated method stub }
We can send messages to destination server is like below. We can use this methods to send order request/subscribe the currencies.
private void send(quickfix.Message message, SessionID sessionID) { try { Session.sendToTarget(message, sessionID); } catch (SessionNotFound e) { } }
Each messages we are preparing and sending to the destinations based on the ROE provided by the acceptor server.
0 Comments
Post a Comment