What is the best way to parse a Fix Protocol message in C#

Joined
12/10/09
Messages
7
Points
11
Hi, good morning.

I'm trying to find a best way(with the best performance) to parse a Fix Protocol message.
Then I made some functions that return a value if I give a Fix Message and a Fix field. They work pretty well but I don't know if is the best way to do this.
See below:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FixField
{
class Program
{
private const char cEql = (char)61;
private const char cFixSep = (char)1;
private const string cFixMsg = @"8=FIX.4.29=27735=834=2489149=ABCD52=20100415-16:01:06.98256=FIX0999991=222222226=011=00500002000000097814=017=0101069762390120=031=032=037=2010041500578358587538=100039=040=241=00500002000000097744=000026.73054=255=IBM59=060=20100415-16:01:07150=0151=00000000100010=148";

static void Main(string[] args)
{
Console.WriteLine(FixField(cFixMsg,"9"));
Console.WriteLine(FixField2(cFixMsg, "9"));
}

static string FixField(string strFixMsg, string strField)
{
int intPos;
int intFieldLen;
int intEnd;
string strValue;

intFieldLen = strField.Length + 2;

intPos = strFixMsg.IndexOf(cFixSep + strField + cEql);

intEnd = strFixMsg.IndexOf(cFixSep, intPos + 1);

if (intPos == -1)
{
strValue = strFixMsg.Substring(2, intEnd - 2);
}
else
{
strValue = strFixMsg.Substring(intPos + intFieldLen, intEnd - intPos - intFieldLen);
}

return strValue;
}

static string FixField2(string strFixMsg, string strField)
{
string[] strValue = strFixMsg.Split(new char[] { cFixSep, cEql });

int i;

for (i = 0; strValue[I] != strField; i++)[/I]
 { }
 
return strValue[i + 1];
}

 }
}
best regards,

bruno
 
Have you looked around for any open-source .NET libraries for working with FIX? E.g., http://www.codeproject.com/KB/cs/fixprotocol.aspx

If you're only parsing one kind of message (what you posted above) and your code already works, then I wouldn't over-engineer the problem. I'm not very familiar with the FIX message format, but you might be able to parse it with a Regex as well (though if you do, test the performance against your existing code to see which is faster).
 
Back
Top Bottom