I have a FixMessage
and I want to calculate the checksum manually.
8=FIX.4.2|9=49|35=5|34=1|49=ARCA|52=20150916-04:14:05.306|56=TW|10=157|
The body length here is calculated:
8=FIX.4.2|9=49|35=5|34=1|49=ARCA|52=20150916-04:14:05.306|56=TW|10=157|
0 + 0 + 5 + 5 + 8 + 26 + 5 + 0 = 49(correct)
The checksum is 157 (10=157). How to calculate it in this case?
You need to sum every byte in the message up to but not including the checksum field. Then take this number modulo 256, and print it as a number of 3 characters with leading zeroes (e.g. checksum=13 would become 013).
Link from the FIX wiki: FIX checksum
An example implementation in C, taken from onixs.biz:
char *GenerateCheckSum( char *buf, long bufLen )
{
static char tmpBuf[ 4 ];
long idx;
unsigned int cks;
for( idx = 0L, cks = 0; idx < bufLen; cks += (unsigned int)buf[ idx++ ] );
sprintf( tmpBuf, "%03d", (unsigned int)( cks % 256 ) );
return( tmpBuf );
}
"sum every byte in the message". Can you write it in this case?
I still dont understand that example. I write c#. If I have a FixMessage: {8=FIX.4.29=4935=534=149=ARCA52=20150916-04:14:05.30656=TW10=157}. How to count it to 157?
@ANguyen Quickfix is a library that can produce a FIX message for you. A FIX message is a string consisting of ASCII characters. To calculate the checksum, 1/ each byte in the message up to the checksum field is summed 2/ take the modulo 256 of that sum 3/ print that number as a number of 3 characters with leading zeros. I can't say it simpler that that. You can't simply dump a FIX message here and expect us to count it for you. You ask the QuickFIX library or any other FIX engine to do it for you.
@ANguyen For me it's been too long since I've done any C# coding, and I'm not proficient with QuickFIX/N. Look into converting a string to a byte stream or byte-array (ASCII encoding). Sum each byte in the array or stream to an unsigned int. Then take the modulo 256 of the total and print it as a 3 character string with leading zeroes.
When I compile that example C program and use the wiki page test case, it gives me 70, not 65 as wiki says