5

需要快速帮助。我是 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 消息缺少许多数据元素(详细信息请参见输出)

谢谢

4

4 回答 4

2

像其他人提到的 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)中定义。因此,这些标签的解析失败并在输出中丢失。

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

于 2013-08-07T15:20:41.180 回答
1

我不熟悉 FIX 消息和 QuickFixJ,但看了一眼Javadoc,您似乎应该使用以下identifyType方法:

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";
MsgType msgType = Message.identifyType(fixMsg);
于 2013-08-07T12:54:09.477 回答
0

如果您只需要一个 MsgTyp,您确定该消息是正确的并且您不需要消息中的任何其他字段,那么我建议使用正则表达式从字符串中提取 MsgType。

例如:\u000135=(\w+)\u0001

它比通过QuickFix 解析(和验证)字符串要快得多。

于 2014-02-26T13:14:16.793 回答
0

您可能会发现FixB框架很有用,因为它可以很好地处理 FIX 的非标准用例。

与您的情况一样,要仅提取您感兴趣的数据,您需要定义一个表示该数据的类并使用注释将其绑定到 FIX。例如:

@FixBlock
public class MDEntry {    
    @FixField(tag=269) public int    entryType; // you could define an enum type for it as well
    @FixField(tag=278) public String entryId;
    @FixField(tag=55)  public String symbol;
}
...

FixFieldExtractor fixExtractor = new NativeFixFieldExtractor();
List<MDEntry> mdEntries = fixExtractor.getGroups(fixMsg, List.class, 268, FixMetaScanner.scanClass(MDEntry.class))

在更常见的情况下,应该使用 FixSerializer 接口,但它需要一个带有 MsgType(35) 标签的消息和一个相应地用 @FixMessage(type="...") 注释的类。例如:

@FixMessage(type="X")
public class MarketData {
    @FixGroup(tag=268) public List<MDEntry> entries;
}
...

FixMetaDictionary fixMetaDictionary = FixMetaScanner.scanClassesIn("my.fix.classes.package");
FixSerializer fixSerializer = new NativeFixSerializer("FIX.5.0.SP2", fixMetaDictionary);
MarketData marketData = fixSerializer.deserialize(fixMsg);

我希望你会发现它很有用。

于 2013-10-31T23:41:23.177 回答