4

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?

Wapiti
  • 1,851
  • 2
  • 20
  • 40

3 Answers3

3

The following code should work.

import quickfix as qfix
import quickfix44 as q44
message = q44.ExecutionReport()
message.setString(input_string, True, qfix.DataDictionary('CustomDictionary.xml'))

'message' object will be updated in place and you should be able to use it as a quickfix Message object

smart.aleck
  • 195
  • 1
  • 7
  • Thanks a lot, that saved me! Not using a Data Dictionary with a repeating group was completely messing up the message I was recreating from the original FIX message... Out of curiosity, how did you know to pass `True` and the DataDictionary as the second argument? Where is the documentation for that? Thanks! – Greg Sadetsky Sep 02 '21 at 02:09
2

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?

dsolimano
  • 8,870
  • 3
  • 48
  • 63
2

The following also works and doesn't require prior knowledge of message type.

import quickfix as fix

string = "8=FIX.4.49=24735=s34=549=sender52=20060319-09:08:20.88156=target22=840=244=948=ABC55=ABC60=20060319-09:08:19548=184214549=2550=0552=254=1453=2448=8447=D452=4448=AAA35777447=D452=338=954=2453=2448=8447=D452=4448=aaa447=D452=338=910=056"

data_dictionary = fix.DataDictionary("FIX44.xml")
message = fix.Message(string, data_dictionary, True)

print(message.toXML())
GratefulGuest
  • 777
  • 7
  • 15