简体   繁体   中英

QuickFIX/J Get fields and groups for customized data dictionary

How can I get fields and groups using QuickFIX/J for customized data dictionary?

I receive market data transmitted in customized MarketDataSnapshotFullRefresh (type W) FIX messages. As I understood, I can't use the crack method for this. I'm not quite familiar with Java and QuickFIX/J, but when I use QuickFIX/n and Python, I can define classes for fields and groups like that:

class CustomField(fix.StringField):
    tag_number = *SomeTagNumber*

    def __init__(self, data=None):
        args = (self.tag_number,) if data is None else (self.tag_number, data)
        super(CustomField, self).__init__(*args)

    def getValue(self, message: object) -> str:
        try:
            if message.getField(self.tag_number):
                return message.getField(self.tag_number)
        except fix.FieldNotFound:  
            return None
        else: raise

class CustomGroupField(fix.StringField):
    tag_number = *SomeTagNumber*

    def __init__(self, data=None):
        args = (self.tag_number,) if data is None else (self.tag_number, data)
        super(CustomGroupField, self).__init__(*args)

    def getValue(self, message: object) -> str:
        try:
            if message.getField(self.tag_number):
                return message.getField(self.tag_number)
        except fix.FieldNotFound:  
            return None
        else: raise

class XXXGroup(fix.Group):
    def __init__(self):
        order = fix.IntArray(4)
        order[0] = No_XXX_UMD_Entries.tag_number    # This is the NoGroup field
        order[1] = XXX_UMD_Entry_ID.tag_number      # This is the field in the repeating group
        order[2] = CustomGroupField.tag_number
        order[3] = 0
        # fix.Group.__init__(self, order[0], order[1], order)
        args = (order[0], order[1], order)
        super(XXXGroup, self).__init__(*args)

    def getValue(self, field: object) -> str:
        try:
           if group.getField(tag_number):
                return group.getField(tag_number)
        except fix.FieldNotFound:  
            return None
        else: raise

And then I can get value inside the fromApp(self, message, sessionID) method like this:

# Get value of the field
some_custom_field = CustomField().getValue(message)

# Get value in the group
group = XXXGroup()
    for idx in range(1, no_entries+1):
        message.getGroup(idx,group)
        custom_gr_field = group.getValue(CustomGroupField)

How can I achieve the same logic in Java using QuickFIX/J? Or maybe there is a better way to work with a custom data dictionary in Java? Maybe you can refer to some examples?

QuickFIX/J use XML files as Dictionary. To parse message you should create dictionary and use it. The code looks like:

DataDictionary dataDictionary = new DataDictionary("FIX44.xml");
Message message = new Message();
message.fromString(text, dataDictionary, false);

Standard dictionary stored in quickfixj jars resources. For example, dictionary for FIX 4.4 stores in https://github.com/quickfix-j/quickfixj/blob/master/quickfixj-messages/quickfixj-messages-fix44/src/main/resources/FIX44.xml

For custom dictionary you should create a XML file with all additional fields and groups. You could copy the standard file, rename it, add group and use like: DataDictionary dataDictionary = new DataDictionary("/var/my_dict/myFIX44.xml");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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