How to Convert String FIX Message to FIX FIX50SP2 Format Using QuickFixJ

You need quick help. I am new to QuickFixJ. I have a FIX message in a txt file. I need to convert it to FIX50SP2 format. I am enclosing a 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 result:

 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 the MsgType field (field 35). Could you tell me where I am wrong? I noticed that after parsing in FIX50SP2 format, there is no data element in the FIX message for conversion (see the output for details)

thanks

+4
source share
4 answers

Like so many others, MsgType is the header field and you get it using the following

 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 items after parsing, maybe your message has some custom tags (for example, tag 2346) that are not defined in your data dictionary (FIXSP02.xml). therefore, parsing of these tags failed and was not output.

To fix this, get a data dictionary from the party sending you the message and use it to parse the message

+1
source

I am not familiar with the FIX and QuickFixJ posts, but looking at Javadoc it seems like you should use the identifyType method:

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

You may find the FixB framework useful, as it does a great job with non-standard use cases for FIX.

As in your case, to retrieve only the data you are interested in, you need to determine the class that will represent this data and associate it with FIX using annotations. For instance:.

 @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, the FixSerializer interface should be used, but this requires a message with the MsgType tag (35) and a class annotated with @FixMessage (type = "..."), respectively. For instance:.

 @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 find this helpful.

0
source

If you only need MsgTyp, you are sure that the message is correct, and you do not need any other field from the message, then I would recommend extracting MsgType from the string using regexp.

for example: \u000135=(\w+)\u0001

This is MUCH FASTER than parsing (and checking) strings through QuickFix.

0
source

Source: https://habr.com/ru/post/1495737/


All Articles