我有一个FixMessage
我想手动计算校验和。
8=FIX.4.2|9=49|35=5|34=1|49=ARCA|52=20150916-04:14:05.306|56=TW|10=157|
这里的体长是这样计算的:
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)
校验和为 157 (10=157)。在这种情况下如何计算呢?
您需要对消息中的每个字节求和,但不包括校验和字段。然后将此数字模 256,并将其打印为带有前导零的 3 个字符的数字(例如 checksum=13 将变为 013)。
来自 FIX wiki 的链接:修复校验和 https://en.wikipedia.org/wiki/Financial_Information_eXchange#Trailer:_Checksum
C 中的示例实现,取自奥尼克斯网站 http://www.onixs.biz/fix-dictionary/4.2/app_b.html:
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 );
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)