Rivu
Rivu

Reputation: 177

How to convert a String FIX message to FIX FIX50SP2 format using QuickFixJ

Need a quick help. I am a newbie in QuickFixJ. I have a FIX message in a txt file. I need to convert that into FIX50SP2 format. 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). 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)

Thanks

Upvotes: 5

Views: 7352

Answers (4)

Konstantin Pavlov
Konstantin Pavlov

Reputation: 985

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.

e.g.: \u000135=(\w+)\u0001

It is MUCH FASTER than parsing (and validating) a string via QuickFix.

Upvotes: 0

Vlad
Vlad

Reputation: 1763

You may find FixB framework useful as it deals well with non-standard use cases of 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. E.g.:

@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. E.g.:

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

Upvotes: 0

Kalatta
Kalatta

Reputation: 466

Like others mentioned the MsgType is an header field and you get it by 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 element after parsing is, probably your message have some custom tags(like tag 2346), which is not defined in your data dictionary(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

Upvotes: 2

Miklos Aubert
Miklos Aubert

Reputation: 4575

I'm not familiar with FIX messages and QuickFixJ, but glancing at the 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);

Upvotes: 1

Related Questions