在quickfix/c++ 中重复组

发布于 2024-10-07 10:08:20 字数 134 浏览 3 评论 0原文

我正在编写一个使用快速修复库的程序。文档很差,所以我请求SO研究员的帮助。

我在 Group 类中看到有迭代器。所以我认为有一些类似 STL 的方法来解析重复组。我错了吗? 有人可以提供一个简单的例子吗?

预先非常感谢您。

I am writing a program that uses the quickfix library. The documentation is very poor, so I am requesting the help of SO fellows.

I have seen in the Group class that there are iterators. So I suppose that there is some STL-ish way of parsing repeating groups. Am I wrong?
Can anybody provide a simple example for doing that?

Thank you very much in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

◇流星雨 2024-10-14 10:08:20

使用 Quickfix 库以及有关如何构造 FIX 消息的文档。否则就很难破译这些消息是如何组织的。

这是来自 Quickfix 网站 的示例

您的消息是 MarketDataSnapshotFullRefresh 类对象。

FIX::NoMDEntries noMDEntries; 
message.get(noMDEntries); -> 

您可以获取重复组的计数,即需要迭代对象消息多少次才能获取所有条目。请记住 FIX::NoMDEntries 是一个字段。

FIX42::MarketDataSnapshotFullRefresh::NoMDEntries group; -> 

这有点棘手。您进入消息内部以获取组。这里,NoMDEntries 是 MarketDataSnapshotFullRefresh 类中的一个封闭类。请记住,这是将为您提供数据的类。现在,您可以运行一个循环,也可以多次编写相同的代码来提取每个组内的所有字段。 getGroup 为您提供从中提取字段的组。 getField 将为您提供字段数据。 Quickfix 的大部分术语都是 FIX 消息。因此,请参阅 Fiximate 等 FIX 消息网站,您的生活会轻松得多。

FIX::MDEntryType MDEntryType;
FIX::MDEntryPx MDEntryPx;
FIX::MDEntrySize MDEntrySize;
FIX::OrderID orderID;

message.getGroup(1, group);
group.get(MDEntryType);
group.get(MDEntryPx);
group.get(MDEntrySize);
group.get(orderID);

message.getGroup(2, group);
group.get(MDEntryType);
group.get(MDEntryPx);
group.get(MDEntrySize);
group.get(orderID);

Use Quickfix library alongwith the documentation of how FIX messages are constructed. Else it would be very difficult to decipher how the messages are organized.

This is an example from Quickfix website

Your message is the MarketDataSnapshotFullRefresh class object.

FIX::NoMDEntries noMDEntries; 
message.get(noMDEntries); -> 

You get the count of repeating groups, how many times you need to iterate over the object message to get all the entries. Remember FIX::NoMDEntries is a field.

FIX42::MarketDataSnapshotFullRefresh::NoMDEntries group; -> 

This is a little tricky. You go inside a message to get the groups. Here NoMDEntries is an enclosed class inside MarketDataSnapshotFullRefresh class. Remeber this is the class which will give you the data. Now either you run through a loop or write the same code multiple times to extract all the fields inside each group. getGroup gives you the group from which you extract fields. getField will give you the field data. Most of the nomenclature of Quickfix is FIX messages. So refer a FIX message website like Fiximate and your life will be much easier.

FIX::MDEntryType MDEntryType;
FIX::MDEntryPx MDEntryPx;
FIX::MDEntrySize MDEntrySize;
FIX::OrderID orderID;

message.getGroup(1, group);
group.get(MDEntryType);
group.get(MDEntryPx);
group.get(MDEntrySize);
group.get(orderID);

message.getGroup(2, group);
group.get(MDEntryType);
group.get(MDEntryPx);
group.get(MDEntrySize);
group.get(orderID);
夏日浅笑〃 2024-10-14 10:08:20

FieldMap 类中有迭代器,它是 MessageGroup 类的超类。

我不确定解析重复组是什么意思。

当原始修复消息到达时,修复引擎会为您解析原始修复消息,并且您的回调会获取已解析的 FIX 消息 - 该消息具有消息头、正文和尾部标签的内部标签映射(键/值)。

查看 1.13.2 版本的代码,当引擎从网络获取新的字符串消息时,它最终会创建一个 Message 并将该字符串传递给它。然后,Message 构造函数调用自身的 setString(),从而有效地解析接收到的字符串并创建标签映射。

如果您查看 Message::setString,您可以看到首先添加了新字段,然后在 setGroup 中检查该字段是否是该组的一部分。如果是,则此方法 setGroup 将接管对以下标记的解析,而这些标记是该组的一部分。一旦遇到不属于该组的标签,它就会停止解析该组,然后返回并继续解析消息中的字段。

现在,这一切都发生在回调到您处理收到消息的应用程序之前。

有一种方法可以迭代消息中的字段。您可以迭代标题、正文或组(以及每个组)的字段。

const FIX40::ExecutionReport& msg; // new incoming message

// iterate over header
FIX::FieldMap::iterator it;
FIX::FieldMap::iterator b = msg.getHeader().begin();
FIX::FieldMap::iterator e = msg.getHeader().end();

for(it = b; it != e; ++it)
{
    switch(it->first)
    {
        case FIX::FIELD::MsgSeqnum:
              /* it->second.getString() - do something with tag data*/ ;
              break;
        ...
    }
}

与正文类似:

FIX::FieldMap::iterator it;
FIX::FieldMap::iterator b = msg.begin();
FIX::FieldMap::iterator e = msg.end();

还有组迭代器(FieldMap::g_begin/g_end),因此您可以迭代消息或标题中的组,并且您可以类似地迭代或搜索每个组中的标签。

Group 和 Message 扩展了 FieldMap,因此所有 getField/setField 功能都可以共享。

内部...如果细节太多,请跳过。

在上面的示例中,此代码:

message.getGroup(1, group);
group.get(MDEntryType);

有效地传递来自 message.getGroup(1, group) -> 的调用FieldMap::getGroup(1, group.field(), group) -> getGroupRef(num,field) -> m_groups.find(field) 为您提供一个组向量 (vector) 并返回 num 元素,即消息中的 num 组(FieldMap)。

group.get(field) 是使用每个标签的宏创建的,它被有效地翻译为 (map).getField(field)
在初始化期间,组的 (map) 是对标签所属对象的引用,因此它从特定组返回标签(请参阅示例 src/C++/fix44/NewOrderSingle.h )有几个扩展 Group 的内部类)

希望它有一定的意义。

There are iterators in FieldMap class which is a super class of Message and Group class.

I'm not sure what do you mean by parsing repeating groups.

Fix engine parses raw fix messages for you when they arrive and your callback gets parsed FIX message - which has internal maps of tags (key/value) for tags in message header, body and tail.

Looking at 1.13.2 version of code, when the engine gets new string message from network it will eventually create a Message passing it the string. Message constructor then calls setString() on itself which effectively parses the received string and creates a map of tags.

If you look at Message::setString you can see that first the new field is added and then in setGroup it checks if the field is part of the group. If it is then this method, setGroup, takes over parsing of the following tags while those tags are part of the group. Once it comes across of tag that is not part of the group it stops parsing the group, it returns and continues parsing fields from message.

Now this all happens internally before the callback to your app where you handle received message.

There is a way to iterate over fields in a message. You can iterate over fields of header, body or over groups (and over each group).

const FIX40::ExecutionReport& msg; // new incoming message

// iterate over header
FIX::FieldMap::iterator it;
FIX::FieldMap::iterator b = msg.getHeader().begin();
FIX::FieldMap::iterator e = msg.getHeader().end();

for(it = b; it != e; ++it)
{
    switch(it->first)
    {
        case FIX::FIELD::MsgSeqnum:
              /* it->second.getString() - do something with tag data*/ ;
              break;
        ...
    }
}

And similarly for body:

FIX::FieldMap::iterator it;
FIX::FieldMap::iterator b = msg.begin();
FIX::FieldMap::iterator e = msg.end();

And there is groups iterator (FieldMap::g_begin/g_end) as well so you could iterate over groups in msg or header and you can similarly iterate, or search, tags within each group.

Group as well as Message extends FieldMap so all the getField/setField functionality is shared across.

Internals ... skip if too much detail.

In the above example this code:

message.getGroup(1, group);
group.get(MDEntryType);

Effectively passes the call from message.getGroup(1, group) -> FieldMap::getGroup(1, group.field(), group) -> getGroupRef(num,field) -> m_groups.find(field) which gives you a vector of groups (vector<FieldMap*>) and returns the num element, aka the num group from the message (a FieldMap).

group.get(field) is created using macros for each tag which is effectively translated as (map).getField(field).
During initialization the (map) for group is a reference to the object of which the tag is member of so it returns the tag from the specific group (see example src/C++/fix44/NewOrderSingle.h it has couple of internal classes which extend Group)

Hope that it makes some sense.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文