Saturday, December 3, 2011

Purpose of this post is to make available a simple sample application for the people who either wants to start learning or want to develop of FIX (FIX protocol) based trading client.

FIX Acceptor ( which acts as the Stock Exchange)
FIX Initiator ( which acts as the Trading Client)

Its just a simple client without any GUI.
People who are already aware about the FIX and just want to try the sample app in java can jump directly to the example, rest of all people can take a pain to read the following:

Some jargons about the FIX protocol:
The Financial Information eXchange ("FIX") Protocol is a series of messaging specifications for the electronic communication of trade-related messages. It has been developed through the collaboration of banks, broker-dealers, exchanges, industry utilities and associations, institutional investors, and information technology providers from around the world. These market participants share a vision of a common, global language for the automated trading of financial instruments ( from Fix Protocol Organization).

Some GYAAN:
If every exchange in the world communicates "ONLY" with their own developed messages (Proprietary Protocol ) than for every exchange there will be need to develop seperately the trading client infrastructure or trading client platform. This is a painful work as to maintain a client with the proprietary messaging or Proprietary Protocol (Message) for every exchange. And keeping the client in the accordance with the exchange notification(s) for upgrades of messages to communicate is a big problem.
And in that case doing a trade with client which supports multiple exchange at the same time seems far from the reality. Of course a client can manage support for few exchange but a large number of exchange will not be possible ( which is the need in the today's world).

With FIX based application its easy to develop OMS ( Order Management System) and EMS ( Execution Management System) faster and scalable. It can be used for Algo Trading but its gonig to be bit slower, so for Algorithmic Trading Proprietary Protocol is a good choice.

where every tag has a specific meaning, in the above tags are 8,9,35,34,49,52 etc.

Lets jump to the FIX based Acceptor and Iniator.

FixAcceptor: Which listens on a specific socket and works as a server. It is the Stock Exchange. Number of clients can connect to it. All the properties for the Acceptor is defined in the acceptor.cfg file.
FixInitiator: Which connects to the FixAcceptor on a specific port defined by Acceptor. It is a trading client. Client can connect with different fix implemenation versions which a client and exchange supports. I am using FIX.4.2 version for the example.

Explanation about the .cfg and fix message is beyond the scope of this blog. ha ha ha, i saved some time. Dirty trick to escape but i have no choice as this is a vast subject and neither i have time nor the experities to cover everything.

Create FixAcceptor.java and FixIniator.java either by implementing Application interface or
by extending ApplicationAdapter class.

exchange checks for the match for the requested order by the client and in case of match it process the order and updates the client with the execution report. Have a look in the example to see the implementation.

Now some snippet from Trading Client i.e. FixIniator.java
Here i am extending ApplicationAdapter instead of implementing Application as its done in FixAcceptor.java

public class FixInitator extends ApplicationAdapter

Start the initiatorr based on the configuration defined in initiator.cfg