FAST协议解析2 FIX Fast Tutorial翻译【PMap、copy操作符】

FIX Fast Tutorial

FIX Fast教程

(译注:本篇是对https://jettekfix.com/education/fix-fast-tutorial/翻译和解释,除了文本的直接翻译外,我还针对各点按我的理解进行了说明和验证,所以可以看到译文下会有很多译注,部分译注还会带有实例。建议看此篇前先看前一篇“FAST协议解析1 通过输入输出逆解析”。由于篇幅较长,我会根据实际内容进行章节截断)

1. Introduction

FAST (FIX Adapted for Streaming) was developed by the FIX Protocol organization to bring the greater benefits of standardization to market data and deliver optimized performance for the exchange of electronic financial information. Built around a data compression algorithm, it significantly reduces bandwidth requirements and latency between sender and receiver. FAST works particularly well at improving performance during periods of peak message rates. While FAST has grown out of market data, it is applicable and can be used with all FIX messages to offer flexibility in the way that FIX data is formatted for transmission.

FAST uses several techniques to reduce bandwidth. This FAST tutorial covers these techniques briefly on this page and in more detail in later sections.

1、简介

FAST(FIX Adapted for Streaming)是由FIX协议组织开发,旨在为市场数据(我理解是证券或期货市场的交易或行情数据)带来更大的标准化效益,并为金融电子信息交换提供更优秀的性能。FAST围绕数据压缩算法构建,显著降低了带宽需求和发送/接收方之间的延迟。FAST在提升消息速率的峰值上尤其有效(我理解是限定时间内可以传更多数据)。虽然FAST已脱离了市场数据(我理解这里指的是FAST压缩后的数据已无法直接阅读,而FIX可以),但它可以适用于所有FIX消息,并可以灵活的方式格式化传输FIX数据。

(译注:我理解FAST是基于FIX构建的,原因是FIX传输数据太多冗余信息,所以FAST进行了一定的压缩。我们可以将任意FIX消息压缩成FAST,或将FAST解压成FIX。)

FAST使用了几种技术来减少带宽。本FAST教程将在本页简要介绍这些技术,并在后面的部分详细介绍。

1.1. FAST Template

FAST Templates define the field layout of messages so the message itself does not describe individual field names or tags. Instead, fields’ identities are inferred from their position within the message as described by the template. This template is shared by both the sender and the receiver (that is, both the encoder and the decoder) and is usually held in an XML file.

Picture 1.1 – “Hello World message transfer”

1.1 FAST模版

FAST模板(template)定义了消息的字段布局(模版文件会描述各种消息有多少个字段,各字段的数值类型,各字段的先后顺序),因此传输的消息本身不描述各个字段的名称或标签。相反,字段的标识是通过它们在消息中的位置来推断的,如模板所描述的那样。此模板由发送方和接收方(即编码器和解码器)共享,并通常存储在XML文件中。

(译注:数据发送方和接收方通过“模版”来压缩和解压缩消息,模版中定义了各字段的先后顺序和含义,发送/接收方可以据此来进行数据压缩和还原。)

图 1.1-“hello world 消息转换”

1.2. FAST Presence Map (PMap)

The Presence Map (or PMap) is a variable length bit field used to indicate whether or not a particular field is present in a message.

This allows the encoder leave out fields from the message in certain cases, such as:

  • field value is the same as in the previous message (common in fields like trade date, settlement date, etc) or
  • is one greater that last message (common case for sequence number).

The template defines the rules to use when a field is not present in the message.

1.2 FAST 存在图(PMap)

存在图(PMap)是一种可变长度的bit域,用于指明消息中是否存在特定字段。

这允许编码器在某些情况下可以从消息中省略某些字段,例如:

1)字段值与前一条消息相同(在交易日、结算日等字段中常见)

2)字段值比上一条消息大1(在序列号等字段中常见)

模版中定义了当消息中不存在某个字段时使用的规则。

【译注:

简单来说,PMap标识了字段是否有填值,如果没有填值,则根据模版中对该字段的定义进行自动赋值,下面举例说明。由于重新赘述太麻烦,需要了解代码含义的同学请先看之前的文章。

1)FAST回顾

回顾一下上一篇我们总结出来的规律,数据按FAST压缩后,如果我们按二进制进行展示,会发现FAST数据可以分为三个区域,第一个区域就是PMap,第二个区域是模版ID,第三个区域是数值部分。

2)copy操作符

Copy操作符的含义是,当FAST数据对某字段没有赋值时,就沿用上一个FAST数据的值。我们新建一个简单模版,里面有2个字段,都使用copy操作符

对代码进行改造,实现2段数据的编码和解码

输出结果如下:

对原始编码进行解析:

需要注意到,在第二段的FAST编码中,省略了模版ID字段,同时将PMap的第二位置为0,表明模版ID字段无值(所以我认为模版ID字段默认就有copy操作符)复用之前的值。

接着我们减少第二段的赋值操作,代码修改如下:

再次运行输出结果如下:

会发现第二段的解析结果沿用了第一段的赋值。将原始编码进行解析:

可以看到PMap中模版ID字段和第二个数值字段均被置为0。

3)总结

综上,PMap结合模版内容可以对特定字段(重复、自增等)进行省略减少数据的总量,实现压缩。

猜你喜欢

转载自blog.csdn.net/weixin_40402375/article/details/130509203