如何将字符串更改为 QuickFix 消息?

How to change string into a QuickFix message?

我正在尝试读取我的 FIX 日志并使用我在 python 中编写的破解程序来解析它们。但是,这不起作用,因为在我的 cracker 中,我有像 message.getHeader() 这样的调用,它们是 QuickFix 方法。他们不出所料 return 一个错误:

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

日志都是字符串,但破解程序嵌入在 QuickFix 中,因此使用 QF 方法。有没有什么方法可以获取字符串并将其转换为 QF 消息,这样我就可以对其调用 crack(message),或者我是否必须针对这种特殊情况重写破解程序?

我在 C# 中执行此操作的方法是读取标记 35 以查看我需要创建的消息类型。然后,我创建该消息类型,并使用 setString 方法填充它。像这样:

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

其中字典是我的数据字典。 Python 绑定中是否有类似的方法?

以下代码应该可以工作。

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

'message' 对象将就地更新,您应该能够将其用作 quickfix Message 对象

以下也适用,不需要事先了解消息类型。

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