什么是QuickFIX/J
下面我们来看一下QuickFIX/J官网的介绍:
The Financial Information eXchange (FIX) protocol is a messaging standard developed specifically for the real-time electronic exchange of securities transactions. FIX is a public-domain specification owned and maintained by FIX Protocol, Ltd (FPL).
QuickFIX/J is a full featured messaging engine for the FIX protocol. It is a 100% Java open source implementation of the popular C++ QuickFIX engine.
简单来说,FIX协议就是金融信息交换协议,是专门为证券交易的实时电子交换而开发的消息传递标准,这是目前金融行业普遍采用的金融信息交换协议。
而QuickFIX/J就是一个100%由Java开发的开源FIX消息传递引擎,通过使用这个引擎就可以很方便地搭建出标准的FIX协议消息传递的服务。
在实际使用中遇到的问题
在最近的项目开发中,需要搭建一个FIX协议客户端接收第三方服务端推送来的行情信息。通过使用QuickFIX/J,很快就搭建出来了服务的雏形,但在进行联调测试的时候就傻眼了,服务运行起来就不停地报错:
“did not find checksum field, bad length?”。后来经过排查,发现是由于客户服务端发送来的FIX消息不标准导致的,具体来说就是FIX消息里的消息体长度字段(9=?)的数值是错误的,因此无法通过QuickFIX引擎反序列化出完整的消息,导致在消息末尾的校验和字段丢失,就会一直报错。
下面就是在quickfix.mina.message.FIXMessageDecoder中进行校验的地方:
if (position + CHECKSUM_PATTERN.getMinLength() <= in.limit()) {
// FEATURE allow configurable recovery position
// int recoveryPosition = in.position() + 1;
// Following recovery position is compatible with QuickFIX C++
// but drops messages unnecessarily in corruption scenarios.
int recoveryPosition = position + 1;
handleError(in, recoveryPosition,
"did not find checksum field, bad length?", isLogon(in));
continue;
} else