在Go中将FIX消息解析为Quickfix/Go中的json

问题描述 投票:0回答:1

我们使用 Quickfix/Go 作为 FIX 引擎,并希望将消息解析为人类可读的 json fieldName:value。

有一个已经回答的类似问题,但它只有 Java 和 C#,它们都提供了迭代字段组的函数: 如何以人类可读的格式记录 QuickFix 消息

我编写了一些代码来解析 xml 字典并从消息头、尾部和正文中获取 FieldMap。那么下面的这个函数应该打印 fieldMap,但是有组,我无法使用 Quickfix/Go 方法访问这些组

func PrintFieldMap(fieldMap quickfix.FieldMap, dd *datadictionary.DataDictionary) {
    for _, tag := range fieldMap.Tags() {
        value, _ := fieldMap.GetString(quickfix.Tag(tag))

        fieldType, ok := dd.FieldTypeByTag[int(tag)]

        if ok {
            fieldName := fieldType.Name()
            fieldType := fieldType.Type

            fmt.Printf("%s - %d :   %s \n", fieldName, tag, value)
            if fieldType == "NUMINGROUP" {
                fmt.Println("this is a group")
            }
        } else {
            fmt.Println("tag not in dict:", tag)
        }
    }

}

因此使用来自 stackoverflow 回答的帖子中的相同原始消息:

8=FIX.4.4\0019=247\00135=s\00134=5\00149=sender\00152=20060319-09:08:20.881\00156=target\00122=8\00140=2\00144=9\00148=ABC\00155=ABC\00160=20060319-09:08:19\001548=184214\001549=2\001550=0\001552=2\00154=1\001453=2\001448=8\001447=D\001452=4\001448=AAA35777\001447=D\001452=3\00138=9\00154=2\001453=2\001448=8\001447=D\001452=4\001448=aaa\001447=D\001452=3\00138=9\00110=056\001

我明白了:

******* Header *******
BodyLength - 9  :       247 
MsgType - 35    :       s 
MsgSeqNum - 34  :       5 
SenderCompID - 49       :       sender 
SendingTime - 52        :       20060319-09:08:20.881 
TargetCompID - 56       :       target 
BeginString - 8 :       FIX.4.4 
******* Body *******
OrdType - 40    :       2 
TransactTime - 60       :       20060319-09:08:19 
CrossPrioritization - 550       :       0 
NoSides - 552   :       2 
this is a group
Symbol - 55     :       ABC 
CrossType - 549 :       2 
PartyRole - 452 :       3 
PartyID - 448   :       aaa 
PartyIDSource - 447     :       D 
SecurityIDSource - 22   :       8 
SecurityID - 48 :       ABC 
CrossID - 548   :       184214 
NoPartyIDs - 453        :       2 
this is a group
Price - 44      :       9 
Side - 54       :       2 
OrderQty - 38   :       9 
******* Trailer *******
CheckSum - 10   :       056

要访问组,文档给出了方法:

func (m FieldMap) GetGroup(parser FieldGroupReader) MessageRejectError
但没有办法创建 FieldGroupReader,文档也没有介绍如何使用。

go parsing quickfix fix-protocol quickfixgo
1个回答
0
投票

查看 QuickFix/go 测试用例的源代码后,我找到了如何获取分组字段:

    template := quickfix.GroupTemplate{
        quickfix.GroupElement(448),
        quickfix.GroupElement(447),
        quickfix.GroupElement(452),
    }
    tag := quickfix.Tag(453)
    f := quickfix.NewRepeatingGroup(tag, template)
    err = bodyFieldMap.GetGroup(f)
    if err != nil {
        fmt.Println("some error:", err)
    }
    for i := 0; i < f.Len(); i++ {
        str448, _ := f.Get(0).GetString(448)
        str447, _ := f.Get(0).GetString(447)
        str452, _ := f.Get(0).GetString(452)

        fmt.Println("str448:", str448)
        fmt.Println("str447:", str447)
        fmt.Println("str452:", str452)
        fmt.Println("--------------")
    }

给出两组:

str448: 8
str447: D
str452: 4
--------------
str448: aaa
str447: D
str452: 3
--------------

但是仍然有一个令人困惑的问题是为什么字段 448 : aaa,而原始字符串是:448=AAA35777 ?

© www.soinside.com 2019 - 2024. All rights reserved.