Implementation of fix messages for fix 5.0 sp2 and fixt1.1 specification


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Implementation of fix messages for fix 5.0 sp2 and fixt1.1 specification

  1. 1. of FIX messages for Fix5.0 sp2 and FIXT1.1 specificationThis document will demonstrate how to connect with FIX5.0 server and FIXT1.1specification and uses of QuickFix/n (native .net FIX engine).IntroductionWith this release of FIX protocol version 5.0, a new Transport Independence framework (TI)introduced which separates the FIX Session Protocol from the FIX Application Protocol. Thisgives freedom to send message across different messaging technologies like MSMQ, messagebus etc.Because of different versions of transport and application protocol, we will have to explicitlydefine settings in config file.TransportDataDictionary is used for defining transport protocol version eg. FIXT.1.1.xmlAppDataDictionary is used for defining data dictionary for FIX application protocol versioneg. FIX50.xmlYou can read more about FIXT1.1 and FIX 5.0 Sp2 specification on demonstrate implementation of FIX 5.0 sp2, I’ll use open source FIX engine for .net(QuickFix/N) which is one of open source engine in native .net code. Code for isavailable on github and primarily contributed by Connamara System’s developers. Theseguys are doing commendable job.ImplementationFixInitiatorThis is client application which will connect with FIX server to send and receive FIXmessages. I am demonstrating implementation of MarketDataRequest and its responses(MarketDataSnapshot&MarketDataIncrementalRefresh). 1
  2. 2. with ConfigurationFirst we create configuration file for initiator.[default]PersistMessages=YConnectionType=initiatorUseDataDictionary=Y[SESSION]ConnectionType=initiatorFileStorePath=storeFileLogPath=fixlogBeginString=FIXT.1.1DefaultApplVerID=FIX.5.0TransportDataDictionary=FIXT.1.1.xmlAppDataDictionary=FIX50.xmlSenderCompID=ABCTargetCompID=FIXSERVERSocketConnectHost=*Note- AppDataDictionary is for application protocol eg. FIX 5.0 andTransportDataDictionary is for transport protocol.You can read more about configuration here.Create Application ClassBefore starting with implementation you would need to have quickFix.dll which is availableof github at connect with FIX session, you will have to implement QuickFix.Application interface.public interface Application{void FromAdmin(Message message, SessionIDsessionID);void FromApp(Message message, SessionIDsessionID);void OnCreate(SessionIDsessionID);void OnLogon(SessionIDsessionID);void OnLogout(SessionIDsessionID);void ToAdmin(Message message, SessionIDsessionID); 2
  3. 3. ToApp(Message message, SessionIDsessionId);}I create one class named FixClient50Sp2 which implements interface and inherit base classfor message cracking and getting message events.FIX Application SetupSetting up Initiator// FIX app settings and relatedvar settings = new SessionSettings("C:initiator.cfg");// FIX application setupMessageStoreFactorystoreFactory = new FileStoreFactory(settings);LogFactorylogFactory = new FileLogFactory(settings);_client = new FixClient50Sp2(settings);IInitiator initiator = new SocketInitiator(_client, storeFactory, settings, logFactory);_client.Initiator = initiator;* _client is instance of class FixClient50Sp2. 3
  4. 4. Initiator_client.Start();Implementation of QuickFix.Application Interface methods/// <summary>/// every inbound admin level message will pass through this method,/// such as heartbeats, logons, and logouts./// </summary>/// <param name="message"></param>/// <param name="sessionId"></param>public void FromAdmin(Message message, SessionIDsessionId){Log(message.ToString());}/// <summary>/// every inbound application level message will pass through this method,/// such as orders, executions, secutiry definitions, and market data./// </summary>/// <param name="message"></param>/// <param name="sessionID"></param>public void FromApp(Message message, SessionIDsessionID){Trace.WriteLine("## FromApp: " + message);Crack(message, sessionID);}/// <summary>/// this method is called whenever a new session is created./// </summary>/// <param name="sessionID"></param>public void OnCreate(SessionIDsessionID){if (OnProgress != null)Log(string.Format("Session {0} created", sessionID));}/// <summary>/// notifies when a successful logon has completed./// </summary>/// <param name="sessionID"></param>public void OnLogon(SessionIDsessionID){ActiveSessionId = sessionID;Trace.WriteLine(String.Format("==OnLogon: {0}==", ActiveSessionId)); 4
  5. 5. (LogonEvent != null)LogonEvent();}/// <summary>/// notifies when a session is offline - either from/// an exchange of logout messages or network connectivity loss./// </summary>/// <param name="sessionID"></param>public void OnLogout(SessionIDsessionID){// not sure how ActiveSessionID could ever be null, but it happened.string a = (ActiveSessionId == null) ? "null" : ActiveSessionId.ToString();Trace.WriteLine(String.Format("==OnLogout: {0}==", a));if (LogoutEvent != null)LogoutEvent();}/// <summary>/// all outbound admin level messages pass through this callback./// </summary>/// <param name="message"></param>/// <param name="sessionID"></param>public void ToAdmin(Message message, SessionIDsessionID){Log("To Admin : " + message);}/// <summary>/// all outbound application level messages pass through this callback before they are sent./// If a tag needs to be added to every outgoing message, this is a good place to do that./// </summary>/// <param name="message"></param>/// <param name="sessionId"></param>public void ToApp(Message message, SessionIDsessionId){Log("To App : " + message);}Callback to Subscriptionpublic void OnMessage(MarketDataIncrementalRefresh message, SessionID session){varnoMdEntries = message.NoMDEntries;varlistOfMdEntries = noMdEntries.getValue();//message.GetGroup(1, noMdEntries);var group = new MarketDataIncrementalRefresh.NoMDEntriesGroup();Group gr = message.GetGroup(1, group); 5
  6. 6. = message.MDReqID.getValue();var price = new MarketPrice();for (inti = 1; i<= listOfMdEntries; i++){group = (MarketDataIncrementalRefresh.NoMDEntriesGroup)message.GetGroup(i, group);price.Symbol = group.Symbol.getValue();MDEntryTypemdentrytype = group.MDEntryType;if (mdentrytype.getValue() == 0) //bid{decimal px = group.MDEntryPx.getValue();price.Bid = px;}else if (mdentrytype.getValue() == 1) //offer{decimal px = group.MDEntryPx.getValue();price.Offer = px;}price.Date = Constants.AdjustedCurrentUTCDate.ToString("yyyyMMdd");price.Time = group.MDEntryTime.ToString();}if (OnMarketDataIncrementalRefresh != null){OnMarketDataIncrementalRefresh(price);}}Code can be found at github. 6