How to parse a string FIXMessage into a FIXMessage object in c#

Ishwar Jindal picture Ishwar Jindal · May 10, 2013 · Viewed 14.2k times · Source

I have string FIX message as input and I want to convert it into a FIX Message. I am using QuickFix 1.13.3 (which I downloaded few days back from quickfix website)

I am quite new to QuickFix. Most of the sample code/help that google returned is for Java and that too no straight forward way is suggested when an application has FIXMessage payload as string.

Most of the samples which I have seen on web are the cases where people are using QuickFix for end to end i.e. from communication over socket to get message and cracking it.

In my case I have my own communication layer which just deliver me a string payload represent a full fledge FIX message. All I need is to parse the string and get a list of all tag/values.

Though I wrote a small utility myself to parse the FIX message using standard string.split().... but someone suggested me to use QuickFix as it support everything.

But I am quite struggling to start even for a very basic task on QuickFix so any help re parsing a string payload will be much appreciated.

Below is what I am looking for

//Convertor or cracker

public QuickFix44.Message GetMessage(string payload);

//Caller

string newOrderSinglePayload = "8=FIX.4.49=13635=D..............";

QuickFix44:Message message = GetMessage(newOrderSinglePayload);

if (message is QuickFix44.NewOrderSingle)

{ 
   //I am happy
}

If QuickFix is too much for this simple work then I am open to use anyother tool (free & opensource)

Answer

Grant Birchmeier picture Grant Birchmeier · May 10, 2013

QuickFIX is definitely designed for end-to-end. Some of its classes can be used for other purposes, but there is not much documentation for these less-common use-cases.

You can pass FIX strings into the Message constructor.

// Uses default DataDictionary (e.g. message definitions from FIX spec)
Message::Message( const std::string& string, bool validate )

// Uses a DataDictionary that you supply.
// If your msg has custom fields, you need this one.
// (You'll create a DD from a custom msg definition XML file that
// you'll also need to create)
Message::Message( const std::string& string,
                  const DataDictionary& dataDictionary,
                  bool validate )

To convert that Message to a more specific type, you can feed it to a more-specific-type constructor, such as ExecutionReport(Message).

Have you considered QuickFIX/n, the native C# port?

This will work with QuickFIX/n:

IMessageFactory _defaultMsgFactory = new DefaultMessageFactory();

var dd = new QuickFix.DataDictionary.DataDictionary();
dd.Load("../../../spec/fix/FIX44.xml");

var msg = new QuickFix.FIX44.ExecutionReport();
msg.FromString(msg_string, false, dd, dd, _defaultMsgFactory);

If your XML has heavy customizations, you will probably want to regenerate source and rebuild the libraries first.