<?xml version="1.0" encoding="UTF-8"?>
<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe"
                   package="com.okx.sbe"
                   id="1"
                   version="0"
                   semanticVersion="1.0.0"
                   description="streams SBE message schema"
                   byteOrder="littleEndian">
    <types>
        <composite name="messageHeader" description="Template ID and length of message root">
            <type name="blockLength" primitiveType="uint16"/>
            <type name="templateId" primitiveType="uint16"/>
            <type name="schemaId" primitiveType="uint16"/>
            <type name="version" primitiveType="uint16"/>
        </composite>
        <composite name="groupSize16Encoding" description="Repeating group dimensions.">
            <type name="blockLength" primitiveType="uint16"/>
            <type name="numInGroup" primitiveType="uint16"/>
        </composite>
        <enum name="sideEnum" encodingType="int8">
            <validValue name="SELL">0</validValue>
            <validValue name="BUY">1</validValue>
        </enum>
       <enum name="sourceEnum" encodingType="int8">
            <validValue name="NORMAL">0</validValue>
            <validValue name="ELP">1</validValue>
        </enum>
    </types>
    <!-- Event for bbo-tbt channel -->
    <sbe:message name="BboTbtChannelEvent" id="1000">
        <field id="1" name="instIdCode" type="int64" description="Instrument ID code"/>
        <field id="2" name="tsUs" type="int64" description="Timestamp in microseconds when the update was generated"/>
        <field id="3" name="outTime" type="int64" description="Gateway timestamp in microseconds when the update is sent"/>
        <field id="4" name="seqId" type="int64" description="Sequence ID of the current message"/>
        <field id="5" name="askPxMantissa" type="int64" description="Mantissa for the best ask price"/>
        <field id="6" name="askSzMantissa" type="int64" description="Mantissa for the best ask size"/>
        <field id="7" name="bidPxMantissa" type="int64" description="Mantissa for the best bid price"/>
        <field id="8" name="bidSzMantissa" type="int64" description="Mantissa for the best bid size"/>
        <field id="9" name="askOrdCount" type="int32" description="Number of orders at the ask price"/>
        <field id="10" name="bidOrdCount" type="int32" description="Number of orders at the bid price"/>
        <field id="11" name="pxExponent" type="int8" description="Price exponent for decimal point positioning"/>
        <field id="12" name="szExponent" type="int8" description="Size exponent for decimal point positioning"/>
    </sbe:message>
    <!-- Event for books-l2-tbt channel -->
    <sbe:message name="BooksL2TbtChannelEvent" id="1001">
        <field id="1" name="instIdCode" type="int64" description="Instrument ID code"/>
        <field id="2" name="tsUs" type="int64" description="Timestamp in microseconds when the update was generated"/>
        <field id="3" name="outTime" type="int64" description="Gateway timestamp in microseconds when the update is sent"/>
        <field id="4" name="seqId" type="int64" description="Sequence ID of the current message"/>
        <field id="5" name="prevSeqId" type="int64" description="Sequence ID of the last sent message"/>
        <field id="6" name="pxExponent" type="int8" description="Price exponent for decimal point positioning"/>
        <field id="7" name="szExponent" type="int8" description="Size exponent for decimal point positioning"/>
        <group id="8" name="asks" dimensionType="groupSize16Encoding" description="Sell side order book updates">
            <field id="1" name="pxMantissa" type="int64" description="Price mantissa"/>
            <field id="2" name="szMantissa" type="int64" description="Size mantissa"/>
            <field id="3" name="ordCount" type="int32" description="Number of orders at the price level"/>
        </group>
        <group id="9" name="bids" dimensionType="groupSize16Encoding" description="Buy side order book updates">
            <field id="1" name="pxMantissa" type="int64" description="Price mantissa"/>
            <field id="2" name="szMantissa" type="int64" description="Size mantissa"/>
            <field id="3" name="ordCount" type="int32" description="Number of orders at the price level"/>
        </group>
    </sbe:message>
    <!-- Event books-l2-tbt channel exponent update  -->
    <sbe:message name="BooksL2TbtExponentUpdateEvent" id="1002">
        <field id="1" name="instIdCode" type="int64" description="Instrument ID code"/>
        <field id="2" name="tsUs" type="int64" description="Timestamp in microseconds when the update was generated"/>
        <field id="3" name="outTime" type="int64" description="Gateway timestamp in microseconds when the update is sent"/>
        <field id="4" name="seqId" type="int64" description="Sequence ID of the current message"/>
        <field id="5" name="prevSeqId" type="int64" description="Sequence ID of the last sent message"/>
        <field id="6" name="pxExponent" type="int8" description="New price exponent for decimal point positioning"/>
        <field id="7" name="szExponent" type="int8" description="New size exponent for decimal point positioning"/>
    </sbe:message>
    <!-- Event for books-l2-tbt-elp channel -->
    <sbe:message name="BooksL2TbtElpChannelEvent" id="1003">
        <field id="1" name="instIdCode" type="int64" description="Instrument ID code"/>
        <field id="2" name="tsUs" type="int64" description="Timestamp in microseconds when the update was generated"/>
        <field id="3" name="outTime" type="int64" description="Gateway timestamp in microseconds when the update is sent"/>
        <field id="4" name="seqId" type="int64" description="Sequence ID of the current message"/>
        <field id="5" name="prevSeqId" type="int64" description="Sequence ID of the last sent message"/>
        <field id="6" name="pxExponent" type="int8" description="Price exponent for decimal point positioning"/>
        <field id="7" name="szExponent" type="int8" description="Size exponent for decimal point positioning"/>
        <group id="8" name="asks" dimensionType="groupSize16Encoding" description="Sell side order book updates">
            <field id="1" name="pxMantissa" type="int64" description="Price mantissa"/>
            <field id="2" name="szMantissa" type="int64" description="Size mantissa"/>
            <field id="3" name="ordCount" type="int32" description="Number of orders at the price level"/>
        </group>
        <group id="9" name="bids" dimensionType="groupSize16Encoding" description="Buy side order book updates">
            <field id="1" name="pxMantissa" type="int64" description="Price mantissa"/>
            <field id="2" name="szMantissa" type="int64" description="Size mantissa"/>
            <field id="3" name="ordCount" type="int32" description="Number of orders at the price level"/>
        </group>
    </sbe:message>
    <!-- Event books-l2-tbt-elp channel exponent update  -->
    <sbe:message name="BooksL2TbtElpExponentUpdateEvent" id="1004">
        <field id="1" name="instIdCode" type="int64" description="Instrument ID code"/>
        <field id="2" name="tsUs" type="int64" description="Timestamp in microseconds when the update was generated"/>
        <field id="3" name="outTime" type="int64" description="Gateway timestamp in microseconds when the update is sent"/>
        <field id="4" name="seqId" type="int64" description="Sequence ID of the current message"/>
        <field id="5" name="prevSeqId" type="int64" description="Sequence ID of the last sent message"/>
        <field id="6" name="pxExponent" type="int8" description="New price exponent for decimal point positioning"/>
        <field id="7" name="szExponent" type="int8" description="New size exponent for decimal point positioning"/>
    </sbe:message>
    <!-- Event for trades channel -->
    <sbe:message name="TradesChannelEvent" id="1005">
        <field id="1" name="instIdCode" type="int64" description="Instrument ID code"/>
        <field id="2" name="tsUs" type="int64" description="Timestamp in microseconds when the update was generated"/>
        <field id="3" name="outTime" type="int64" description="Gateway timestamp in microseconds when the update is sent"/>
        <field id="4" name="seqId" type="int64" description="Sequence ID of the current message"/>
        <field id="5" name="pxMantissa" type="int64" description="Trade price mantissa"/>
        <field id="6" name="szMantissa" type="int64" description="Trade size mantissa"/>
        <field id="7" name="tradeId" type="int64" description="Trade ID"/>
        <field id="8" name="count" type="int16" description="The count of trades aggregated in this message"/>
        <field id="9" name="side" type="sideEnum" description="Trade direction"/>
        <field id="10" name="pxExponent" type="int8" description="Price exponent for decimal point positioning"/>
        <field id="11" name="szExponent" type="int8" description="Size exponent for decimal point positioning"/>
        <field id="12" name="source" type="sourceEnum" description="Source of trade"/>
    </sbe:message>
    <!-- Event for snapshot depth response from "GET /api/v5/market/books-sbe" request -->
    <sbe:message name="SnapshotDepthResponseEvent" id="1006">
        <field id="1" name="instIdCode" type="int64" description="Instrument ID code"/>
        <field id="2" name="tsUs" type="int64" description="Timestamp in microseconds when the update was generated"/>
        <field id="3" name="seqId" type="int64" description="Sequence ID of the current message"/>
        <field id="4" name="pxExponent" type="int8" description="Price exponent for decimal point positioning"/>
        <field id="5" name="szExponent" type="int8" description="Size exponent for decimal point positioning"/>
        <group id="6" name="asks" dimensionType="groupSize16Encoding" description="Sell side order book levels">
            <field id="1" name="pxMantissa" type="int64" description="Price mantissa"/>
            <field id="2" name="szMantissa" type="int64" description="Size mantissa"/>
            <field id="3" name="ordCount" type="int32" description="Number of orders at the price level"/>
        </group>
        <group id="7" name="bids" dimensionType="groupSize16Encoding" description="Buy side order book levels">
            <field id="1" name="pxMantissa" type="int64" description="Price mantissa"/>
            <field id="2" name="szMantissa" type="int64" description="Size mantissa"/>
            <field id="3" name="ordCount" type="int32" description="Number of orders at the price level"/>
        </group>
    </sbe:message>
</sbe:messageSchema>