Skip to main content
 首页 » 编程设计

Python Quickfix之读取自定义重复组

2024年09月07日36birdshome

这个问题几乎与没有正确回答的问题相同:Reading Repeating Groups in Custom Messages using Python Quickfix

Windows 上的 python 2.7.15、quickfix 1.15.1、FIX 4.2

我有一个来 self 的交易平台提供商的自定义数据字典,它在执行报告中包含自定义字段和组。完整的 XML 可在此处获得:http://library.tradingtechnologies.com/tt-fix/System_Overview.html。特别是该组定义如下:

        <group name='NoSecurityAltID' required='N'> 
            <field name='SecurityAltID' required='N' /> 
            <field name='SecurityAltIDSource' required='N' /> 

我已经指定了自定义数据字典并设置了 UseDataDictionary=Y,尽管我认为这是默认设置。

group= quickfix42.ExecutionReport.NoSecurityAltID() 

返回属性错误。

奇怪的是,NoContraBrokers 可作为属性使用,但它不是自定义词典中的组之一,而是标准 4.2 词典中的组。因此,我认为存在一些错误,它没有解析自定义词典,但我已经验证它是。

我是 quickfix(和 python)的新手,所以可能犯了一个基本错误。但这已经阻碍了我很长时间,所以真的很感激一些指导。

更新:

所以我只能通过这种方法访问标准的 FIX 4.2 组。我现在创建了一个组:

group = quickfix.Group(454, 455) 

其中 454=NoSecurityAltID 和 455=SecurityAltID。

现在我正在努力读取我想要的特定 SecurityAltIDSource 的字符串。这是该组的概况:

Group overview

我想读取“别名”和“名称”,但只能通过以下方式访问 SecurityAltIDSource 的 TagNumber

message.getGroup(1, group) 
group.getField(456) 

如何访问所需字段的字符串?

谢谢

更新 2:

这是一个简单的错误(虽然不是很快就能解决的)。我能够通过以下方式访问我想要的字段:

group.getField(455) 

我担心使用字段整数可能不如另一种方法可靠。有没有更好的方法(除了重新编译引擎,这超出了我的能力范围)?

请您参考如下方法:

这可能是一个延迟很久的回复。我遇到了同样的问题,并能够通过以下方式解决。

除了使用字段编号,您还可以使用 quickfix 标签,它会在幕后使用正确的标签。我在这里使用示例标签“NoAlloc”,但您可以使用任何您想要的组。

import quickfix as qfix 
 
# how many items are in the group 
count = fixmsg.groupCount(qfix.NoAllocs().getTag()) 
 
# Getting the fields where 1 is the item in the list you want to retrieve 
# from the repeating group. Index starts from 1 (not 0) 
field_set = message.getGroupPtr(1, qfix.NoAllocs().getTag()) 
 
field_set.getField(qfix.AllocAccount()) 

注意:对于自定义组,您需要定义自己的字段和组。

# Sample Field Declaration 
class SampleField1(qfix.StringField): 
    def __init__(self, data=None): 
        if data is None: 
            qfix.StringField.__init__(self, 456) 
        else: 
            qfix.StringField.__init__(self, 456, data) 
 
# NoSampleGroup Field Declaration 
class NoSampleGroup(qfix.IntField): 
    def __init__(self, data=None): 
        if data is None: 
            qfix.StringField.__init__(self, 879) 
        else: 
            qfix.StringField.__init__(self, 879, data) 
 
# Sample Group Declaration 
class SampleGroup(qfix.Group): 
    def __init__(self): 
        order = qfix.IntArray(4) 
        order[0] = 879     # This is the NoSamppleGroup field 
        order[1] = 456     # This is the field in the repeating group 
        order[2] = 0 
        fix.Group.__init__(self, 879, 456, order)