Python Quickfix - reading custom repeating groups

后端 未结 1 618
再見小時候
再見小時候 2021-01-15 14:45

This issue is almost identical to this which was not answered properly: Reading Repeating Groups in Custom Messages using Python Quickfix

python 2.7.15 on Windows, q

相关标签:
1条回答
  • 2021-01-15 15:46

    This may be a much delayed reply. I came across the same issue and was able to resolve it the following way.

    Instead of using the field numbers, you can use the quickfix tags which will use the correct tags behind the scenes. I am using a sample tag 'NoAlloc' here but you can use any group you want.

    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())
    

    NOTE: For custom groups, you will need to define your own fields and groups.

    # 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)
    
    0 讨论(0)
提交回复
热议问题