31

How do you parse a FIX message using python ? (FIX message as in the 'financial' FIX Protocol)

ap330
  • 3
  • 3
Chez
  • 313
  • 1
  • 3
  • 4
  • 6
    13 up votes and closed! Great job! – chrisapotek Jul 11 '12 at 16:39
  • 4
    this question interested me too, what a pity to see it closed. – Guillaume Paris Oct 01 '12 at 07:48
  • Although the question is specific to .NET, there are some generally applicable ideas here: http://stackoverflow.com/questions/4907848/whats-the-most-efficient-way-to-parse-fix-protocol-messages-in-net – paytools-steve Oct 01 '12 at 16:17
  • 2
    Wish this question wasn't closed. If you just want to parse some FIX text, take a look at this [fix parser](http://fixparser.targetcompid.com), view the source to see how a blob of FIX text is parsed. If you want to parse FIX for an actual trading app, take a look at open source projects (two of mine are https://github.com/falconair/fix.js and https://github.com/falconair/lowlevelfix) – Shahbaz Feb 07 '13 at 14:30

6 Answers6

12

do you mean by using QuickFIX ? (I can see QuickFIX in your tags)

if that is the case, I don't know. Generally it's not difficult to write a simple parser for a FIX message. I found that the web tools on valid fix do the job.

sergej
  • 152
  • 2
  • QuickFix is used as an underlying FIX parser by a number of companies that provide FIX parsers. Its pretty easy to get a QuickFIX parser running, I would suggest you give it a try. – Luhar Feb 25 '10 at 18:31
8

Apart from using the actual quickfixengine it's easy to parse fix message when you know it contains specific tags.

It contains 0x1 separated pairs of 'key=value' strings. One complication are groups because you have to figure out that the tag is the first in a group (group header) and then figure out when the group ends (when it hits another tag not in the group).

Another problematic field is the RawData which can contain anything including the field separator 0x1, but it is preceded by RawDataLength so you have to read that first and then read RawDataLength number of bytes after the RawData tag to get to the next field.

I believe quickfixengine uses the dictionary of tags where it can figure out that the tag is first of a group then keep adding until hitting tag that is not in a group.

When I need to do custom parsing of FIX messages I mostly know exactly what messages and what data we expect so I can tweak it for those messages.

stefanB
  • 77,323
  • 27
  • 116
  • 141
5

The FIX format is surprisingly annoying to parse (as the non-XML format, i.e. the one still used by pretty much everyone, has no subgroup start and end markers, instead you have to work it out based on tag ordering rules, and tags that are not in a subgroup, the header or the tail can be in any order).

So rather than parse it yourself I'd recommend you use an existing library to do so.

The only well maintained open source option is the Java QuickFIX/J library.

There are many commercial solutions, e.g. CameronFIX

George Hawkins
  • 37,044
  • 7
  • 30
  • 43
4

try http://fix.nowing.com

it's a web based fix message parser

Neo Wang
  • 47
  • 3
2

from the quickfixj source code, it uses treeMap to handle the FIX message.

regarding to XML format, i think FIX is better, though the parsing is harder in JAVA. coz XML is too heavy.

user462872
  • 323
  • 1
  • 4
  • 14
  • I agree on FIX over XML, except for the bloody repeating groups. – ProfK Apr 21 '11 at 16:50
  • I agree with ProfK. The repeating groups for parties etc is a pain. – Kelly Nov 18 '11 at 04:39
  • Also, most people attempt to "parse" a FIX message by splitting on SOH, which completely ignores the problem of RawData (tag 96). BTW, using TreeMap is probably not the best approach because it makes it difficult to recognize and support duplicate tags in your message. I think list is probably a better data structure representation. – noahlz Feb 21 '12 at 17:25
1

There is no one best way, but given the quickfix tag that either you or the SO system attached, a look at QuickFix open source FIX engine would be a good place to start.

There are many commercial vendors as well if you are at a company where that matters, or if you want more support and services.

Good Luck

sdg
  • 4,645
  • 3
  • 32
  • 26