简体   繁体   English

QuickFIX/J 获取自定义数据字典的字段和组

[英]QuickFIX/J Get fields and groups for customized data dictionary

How can I get fields and groups using QuickFIX/J for customized data dictionary?如何使用 QuickFIX/J 获取自定义数据字典的字段和组?

I receive market data transmitted in customized MarketDataSnapshotFullRefresh (type W) FIX messages.我收到在自定义 MarketDataSnapshotFullRefresh(W 型)FIX 消息中传输的市场数据。 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:我对 Java 和 QuickFIX/J 不是很熟悉,但是当我使用 QuickFIX/n 和 Python 时,我可以像这样为字段和组定义类:

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:然后我可以像这样在fromApp(self, message, sessionID)方法中获取值:

# 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?如何使用 QuickFIX/J 在 Java 中实现相同的逻辑? Or maybe there is a better way to work with a custom data dictionary in Java?或者也许有更好的方法来使用 Java 中的自定义数据字典? Maybe you can refer to some examples?也许你可以参考一些例子?

QuickFIX/J use XML files as Dictionary. QuickFIX/J 使用 XML 文件作为字典。 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.存储在 quickfixj jar 资源中的标准字典。 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例如,FIX 4.4 的字典存储在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.对于自定义字典,您应该创建一个包含所有附加字段和组的 XML 文件。 You could copy the standard file, rename it, add group and use like: DataDictionary dataDictionary = new DataDictionary("/var/my_dict/myFIX44.xml");您可以复制标准文件,重命名它,添加组并使用如下: DataDictionary dataDictionary = new DataDictionary("/var/my_dict/myFIX44.xml");

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

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