简体   繁体   English

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

[英]How to convert a String FIX message to FIX FIX50SP2 format using QuickFixJ

Need a quick help. 需要快速帮助。 I am a newbie in QuickFixJ. 我是QuickFixJ的新手。 I have a FIX message in a txt file. 我在txt文件中有一条FIX消息。 I need to convert that into FIX50SP2 format. 我需要将其转换为FIX50SP2格式。 I am enclosing the code snippet. 我附上了代码片段。

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));

Here is the output: 这是输出:

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)

I want to extract MsgType field (field 35). 我想提取MsgType字段(字段35)。 Could you please tell me where I am wrong? 你能告诉我我哪里错了吗? The thing I have observed is that after parsing to FIX50SP2 format, the convert FIX message is missing many data element (for details see the output) 我观察到的是,在解析为FIX50SP2格式之后,转换FIX消息缺少许多数据元素(有关详细信息,请参阅输出)

Thanks 谢谢

Like others mentioned the MsgType is an header field and you get it by using the following 与其他提到的一样,MsgType是一个标题字段,您可以使用以下内容获取它

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

The reason you are missing many data element after parsing is, probably your message have some custom tags(like tag 2346), which is not defined in your data dictionary(FIXSP02.xml). 解析后丢失许多数据元素的原因可能是您的消息有一些自定义标记(如标记2346),这些标记未在数据字典(FIXSP02.xml)中定义。 hence the parsing of those tags failed and missing in the output. 因此,这些标签的解析在输出中失败并丢失。

To fix this, get the data dictionary from the party that is sending you the message and use it to parse the message 要解决此问题,请从发送消息的一方获取数据字典,并使用它来解析消息

I'm not familiar with FIX messages and QuickFixJ, but glancing at the Javadoc , it seems like you should use the identifyType method : 我不熟悉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);

You may find FixB framework useful as it deals well with non-standard use cases of FIX. 您可能会发现FixB框架很有用,因为它可以很好地处理FIX的非标准用例。

As in your case, to extract only data you are interested in, you need to define a class that will represent this data and to bind it to FIX using annotations. 在您的情况下,要仅提取您感兴趣的数据,您需要定义一个表示此数据的类,并使用注释将其绑定到FIX。 Eg: 例如:

@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))

In more common cases, FixSerializer interface should be used, but it requires a message with MsgType(35) tag and a class annotated with @FixMessage(type="...") accordingly. 在更常见的情况下,应该使用FixSerializer接口,但它需要一个带有MsgType(35)标记的消息和一个用@FixMessage(type =“...”)注释的类。 Eg: 例如:

@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);

I hope you will find it useful. 我希望你会发现它很有用。

If you need just a MsgTyp, you're sure the message is correct and you do not need any other field from the message, then I would recommend extracting MsgType from string using regexp. 如果您只需要一个MsgTyp,您确定该消息是正确的,并且您不需要该消息中的任何其他字段,那么我建议使用regexp从字符串中提取MsgType。

eg: \35=(\\w+)\ 例如: \35=(\\w+)\

It is MUCH FASTER than parsing (and validating) a string via QuickFix. 它是比分析(和验证)通过QuickFix的字符串更快

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM