I receive the following message from counterparty:
8=FIX.4.4|9=219|35=W|34=4|49=id|52=20200618-14:34:20.738|56=id1|42=20200618-14:34:20.688|55=EUR/USD|262=1|268=2|269=0|270=1.12083|271=500000|269=1|270=1.12084|271=500000|10094=2020.06.18 14:34:20.688|10=141|
The message contains the field 268 = 2, and both groups begin with the field 269, and I am trying to extract fields 270. My code looks like this:
message= quickfix.Message('8=FIX.4.4\x019=219\x0135=W\x0134=4\x0149=id\x0152=20200618-14:34:20.738\x0156=id1\x0142=20200618-14:34:20.688\x0155=EURUSD\x01262=1\x01268=2\x01269=0\x01269=1\x01270=1.12083\x01270=1.12084\x01271=500000\x01271=500000\x0110094=2020.06.18 14:34:20.688\x0110=141\x01')
group = quickfix44.MarketDataSnapshotFullRefresh.NoMDEntries()
fix_no_entries = quickfix.NoMDEntries()
message.getField(fix_no_entries)
no_entries = fix_no_entries.getValue() # print = 2 as expected
message.getGroup(1, group)
However, when running the getGroup line, I get the error:
FieldNotFound: Field not found
Any idea on what is going wrong?
Thank you again guys!
Quickfix doesn't know about your message structure, so you need to provide some info about how to parse the message, otherwise it's just a bunch of fields without groups.
<message>
<header>
<field number="8"><![CDATA[FIX.4.4]]></field>
<field number="9"><![CDATA[183]]></field>
<field number="35"><![CDATA[W]]></field>
<field number="34"><![CDATA[4]]></field>
<field number="49"><![CDATA[id]]></field>
<field number="52"><![CDATA[20200618-14:34:20.738]]></field>
<field number="56"><![CDATA[id1]]></field>
</header>
<body>
<field number="42"><![CDATA[20200618-14:34:20.688]]></field>
<field number="55"><![CDATA[EURUSD]]></field>
<field number="262"><![CDATA[1]]></field>
<field number="268"><![CDATA[2]]></field>
<field number="269"><![CDATA[0]]></field>
<field number="269"><![CDATA[1]]></field>
<field number="270"><![CDATA[1.12083]]></field>
<field number="270"><![CDATA[1.12084]]></field>
<field number="271"><![CDATA[500000]]></field>
<field number="271"><![CDATA[500000]]></field>
<field number="10094"><![CDATA[2020.06.18 14:34:20.688]]></field>
</body>
<trailer>
<field number="10"><![CDATA[182]]></field>
</trailer>
</message>
Quickfix data dictionaries are the way to configure the message parser. Quickfix already comes along with some pre-configured dictionaries, you can customize it according with your needs.
data_dictionary = quickfix.DataDictionary("quickfix/FIX44.xml")
message= quickfix.Message('...', data_dictionary, True)
print(message.toXML())
Now the message is structured and it's possible to retrieve groups data:
<message>
<header>
<field number="8"><![CDATA[FIX.4.4]]></field>
<field number="9"><![CDATA[183]]></field>
<field number="35"><![CDATA[W]]></field>
<field number="34"><![CDATA[4]]></field>
<field number="49"><![CDATA[id]]></field>
<field number="52"><![CDATA[20200618-14:34:20.738]]></field>
<field number="56"><![CDATA[id1]]></field>
</header>
<body>
<field number="42"><![CDATA[20200618-14:34:20.688]]></field>
<field number="55"><![CDATA[EURUSD]]></field>
<field number="262"><![CDATA[1]]></field>
<field number="268"><![CDATA[2]]></field>
<field number="10094"><![CDATA[2020.06.18 14:34:20.688]]></field>
<group>
<field number="269"><![CDATA[0]]></field>
</group>
<group>
<field number="269"><![CDATA[1]]></field>
<field number="270"><![CDATA[1.12083]]></field>
</group>
<group>
<field number="270"><![CDATA[1.12084]]></field>
<field number="271"><![CDATA[500000]]></field>
</group>
<group>
<field number="271"><![CDATA[500000]]></field>
</group>
</body>
<trailer>
<field number="10"><![CDATA[182]]></field>
</trailer>
</message>