Search code examples
pythonquickfixfix-protocol

How to change string into a QuickFix message?


I am trying to read my FIX logs and to parse them with the cracker that I wrote in python. However, this does not work because in my cracker I have calls like message.getHeader() which are QuickFix methods. They unsurprisingly return an error:

AttributeError: 'str' object has no attribute 'getHeader'

The logs are all strings, but the cracker is embedded within QuickFix and so uses QF methods. Is there any way to take the string and transform it into a QF message so I can just call crack(message) on it, or do I have to rewrite my cracker for this special case?


Solution

  • The way that I do it in C# is to read tag 35 to see what message type I need to create. Then, I create that message type, and use the setString method to populate it. Something like this:

    if (line.Contains("35=8"))
    {
        message = new QuickFix44.ExecutionReport();
    }
    else if(line.Contains("35=AS"))
    {
        message = new QuickFix44.AllocationReport();
    }
     . . . . and so on
    
    message.setString(line, true, dictionary);
    application.fromApp(message, sessionId); //The cracker takes care of it from here
    

    where dictionary is my data dictionary. Is a similar method available in the Python bindings?