Skip to content

Simple Binary Encoding Quick Guide

William Cox edited this page Sep 23, 2024 · 1 revision

Overview:

SBE is designed by FIX Trading company, which is industry standard trading protocol designed for high frequency trading.

Index:

Dependencies for SBE

The SBE Tool does not have a dedicated Maven plugin. So we need to add few dependencies and configurations as follows:

  • Insert the agrona dependency in the pom.xml file to allow maven to run SBE.
    <dependency>
           <groupId>org.agrona</groupId>
           <artifactId>agrona</artifactId>
	   <version>1.9.0</version>
    </dependency>
  • Add the configuration in the pom.xml file as mentioned below, we use sbe 1.20.4 version in our project.

  • Refer how to add plugins in maven project.

How SBE works?

  • To use SBE tool we need to define the SBE message schema, which is an XML file.

  • SBE message schema contains the structure of the SBE message and defines all the possible attributes Marketpayloads-sbe.xml

  • We define the encode method, in which we use an unsafe buffer to encode the message and message header encoder to encode all the attributes of the message into a single SBE message.

  • To decode we use unsafebuffer to wrap the message into payloaddecoder and extract the message.

  • Further we get each value of the payloaddecoder and create transaction payload.

How SBE is defined:

Validation of Messages:

  • Validation of SBE messages is performed at every hop from creating a tender to finding a match and responding back with match id. We can achieve this by printing the message at every hop before encoding the message and after decoding the message.

  • To print the message we use toString method in payloads classes under controllers.

  • This will help us to track the message at every step, sample snapshot as follows.

  • Now if we cross verify we can validate the message at the encoder end. and the decoder end to validate the message.

Few useful references:

Clone this wiki locally