这个问题与没有正确回答的问题几乎相同:Reading Repeating Groups in Custom Messages using Python Quickfix
Windows 上的 python 2.7.15、quickfix 1.15.1、FIX 4.2
我有一个来自交易平台提供商的自定义数据字典,其中在执行报告中具有自定义字段和组。完整的 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' />
Run Code Online (Sandbox Code Playgroud)
我已指定自定义数据字典并按其他地方指定的方式设置 UseDataDictionary=Y,尽管我认为这是默认值。
group= quickfix42.ExecutionReport.NoSecurityAltID()
Run Code Online (Sandbox Code Playgroud)
返回属性错误。
奇怪的是,NoContraBrokers 可作为属性使用,但它不是自定义词典中的组之一,而是在标准 4.2 词典中。因此,我认为存在一些错误,并且它没有解析自定义字典,但我已经验证它是。
我是quickfix(和python)的新手,所以可能犯了一个基本错误。但这已经让我坚持了很长一段时间,所以我真的很感激一些指导。
更新:
所以我只能通过这种方法访问标准FIX 4.2组。我现在创建了一个群组:
group = quickfix.Group(454, 455)
Run Code Online (Sandbox Code Playgroud)
其中 454=NoSecurityAltID 且 455=SecurityAltID。
现在我正在努力读取我想要的特定 SecurityAltIDSource 的字符串。这是该小组的概况:
我想读取“别名”和“名称”,但只能通过以下方式访问 SecurityAltIDSource 的 TagNumber
message.getGroup(1, group)
group.getField(456)
Run Code Online (Sandbox Code Playgroud)
如何访问我想要的字段的字符串?
谢谢
更新2:
这是一个简单的错误(尽管不是很快就能解决的)。我能够通过以下方式访问我想要的领域:
group.getField(455)
Run Code Online (Sandbox Code Playgroud)
我担心使用字段整数不如其他方法那么强大。有没有更好的方法来做到这一点(除了重新编译引擎,这超出了我的能力)?
这可能是一个延迟很长时间的回复。我遇到了同样的问题,并能够通过以下方式解决它。
您可以使用快速修复标签,而不是使用字段编号,该标签将在幕后使用正确的标签。我在这里使用示例标签“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())
Run Code Online (Sandbox Code Playgroud)
注意:对于自定义组,您需要定义自己的字段和组。
# 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)
Run Code Online (Sandbox Code Playgroud)