如何使用QuickFixJ将String FIX消息转换为FIX FIX50SP2格式

需要快速帮助.我是QuickFixJ的新手.我在txt文件中有一条FIX消息.我需要将其转换为FIX50SP2格式.我附上了代码片段.

String fixMsg = "1128=99=25535=X49=CME34=47134052=20100318-03:21:11.36475=20120904268=2279=122=848=336683=607400107=ESU2269=1270=140575271=152273=121014000336=2346=521023=1279=122=848=336683=607401107=ESU2269=1270=140600271=206273=121014000336=2346=681023=210=159";

System.out.println("FixMsg String:"+fixMsg);
Message FIXMessage = new Message();
DataDictionary dd = new DataDictionary("FIX50SP2.xml");
FIXMessage.fromString(fixMsg, dd, false);
System.out.println("FIXMessage Output:" + FIXMessage.toString()); // Print message after parsing
MsgType msgType = new MsgType();
System.out.println(FIXMessage.getField(msgType));

这是输出:

FixMsg String:1128=99=15835=X49=CME34=47164052=2012090312102051175=20120904268=1279=122=848=336683=607745107=ESU2269=1270=140575271=123273=121020000336=2346=501023=110=205
FIXMessage Output:9=6135=X34=47164049=CME52=2012090312102051175=20120904268=110=117
quickfix.FieldNotFound: Field [35] was not found in message.
    at quickfix.FieldMap.getField(FieldMap.java:216)
    at quickfix.FieldMap.getFieldInternal(FieldMap.java:353)
    at quickfix.FieldMap.getField(FieldMap.java:349)
    at MainApp.main(MainApp.java:52)

我想提取MsgType字段(字段35).你能告诉我我哪里错了吗?我观察到的是,在解析为FIX50SP2格式之后,转换FIX消息缺少许多数据元素(有关详细信息,请参阅输出)

谢谢

解决方法:

与其他提到的一样,MsgType是一个标题字段,您可以使用以下内容获取它

String msgType = null;
if(FIXMessage.getHeader().isSetField(MsgType.FIELD)) {
    msgType = FIXMessage.getHeader().getString(MsgType.FIELD);
}
System.out.println("MsgType is " + msgType);`

解析后丢失许多数据元素的原因可能是您的消息有一些自定义标记(如标记2346),这些标记未在数据字典(FIXSP02.xml)中定义.因此,这些标签的解析在输出中失败并丢失.

要解决此问题,请从发送消息的一方获取数据字典,并使用它来解析消息

上一篇:MetaTrader 4使用Java修复协议


下一篇:Luogu P1273 有线电视网 树形DP