简体   繁体   English

"使用 QuickFIX 获取接收到的 FIX 消息的所有现有字段"

[英]Getting all existing fields of a received FIX message with QuickFIX

Does QuickFIX provide the possibility of getting ALL existing fields of an incoming FIX message in a single step? QuickFIX 是否提供了在一个步骤中获取传入 FIX 消息的所有现有字段的可能性? (I use version 1.14.3 for Python.) (我为 Python 使用 1.14.3 版本。)

According to QuickFIX documentation, it's possible to get a field value in a certain way:根据 QuickFIX 文档,可以通过某种方式获取字段值:

price = quickfix.Price()
field = message.getField(price)
field.getValue()

Various message types contain different fields, so doing that for every field would be awkward.各种消息类型包含不同的字段,因此对每个字段都这样做会很尴尬。 What is more, sometimes it's unknown whether some fields exist in a message.更重要的是,有时不知道消息中是否存在某些字段。 How do I get all fields of a message not knowing what fields it contains?如何在不知道消息包含哪些字段的情况下获取消息的所有字段?

I wasnt able to find a Quickfix API function for this either, but here is something straightforward which splits the raw message up by field separator 0x01 and then by '=':我也无法为此找到 Quickfix API 函数,但这里有一些简单的方法,它通过字段分隔符 0x01 将原始消息拆分,然后按“=”:

for field in message.toString().split(chr(1)):
    field = field.split('=', 1)
    if len(field) == 2:
        print(f"{field[0]} = {field[1]}")

This prints something like:这会打印出类似的内容:

8 = FIX.4.2
9 = 231
35 = 8
34 = 4
49 = Target
52 = 20220122-01:11:51.340
56 = 1234
17 = 9a1d510c-0cfa-43f6-9f6c-e713e5fb2954
20 = 0
37 = 5985669f-2dcf-46de-9f49-70a3a10e392e
38 = 0
39 = 3
54 = 1
55 = SPY
60 = 20220122-01:11:51.336
150 = 3
151 = 0
10 = 238

I'm not aware of a method.我不知道一种方法。 This is what I do, with message the incoming FIX message:这就是我所做的, message是传入的 FIX 消息:

tags = re.findall(r'(?<=\\x01).*?(?==)', str(message))

Then, where FIX = {'1':fix.Account(), '2':fix.AdvId(), ...} , you can get all values by doing然后,在FIX = {'1':fix.Account(), '2':fix.AdvId(), ...} ,您可以通过执行获取所有值

for tag in set(tags)&set(FIX.keys()):
    message.getField(FIX[tag])

Obviously you must import the re module.显然,您必须导入re模块。

My way to parse FIX message:我解析 FIX 消息的方法:

tagd = {">>".join((str(n),x)):y for n,[x,y] in enumerate([b.split("=") for b in message.toString().split(chr(1)) if len(b)>1])}

Resulting in dict() with FIX code keys:使用 FIX 代码键生成 dict():

{'0>>8': 'FIX.4.4', '1>>9': '125', '2>>35': 'W', '3>>34': '3', '4>>49': 'CSERVER', '5>>50': 'QUOTE', '6>>52': '20200212-12:18:56.328', '7>>56': 'unique_string_id', '8>>55': '1', '9>>268': '2', '10>>269': '0', '11>>270': '1.08716', '12>>269': '1', '13>>270': '1.08718', '14>>10': '067'}

Enumeration is for repeated fields like 269 and 270. Cheers.枚举用于重复字段,如 269 和 270。干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM