<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe"
                   package="com.okx.sbe.trade"
                   id="1"
                   version="0"
                   semanticVersion="1.0.0"
                   description="sbe trade schema: place/amend/cancel requests and batch response."
                   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="groupSizeEncoding" description="Repeating group dimensions.">
            <type name="blockLength" primitiveType="uint16"/>
            <type name="numInGroup" primitiveType="uint16" minValue="0" maxValue="20"/>
        </composite>

        <enum name="booleanEnum" encodingType="int8">
            <validValue name="FALSE">0</validValue>
            <validValue name="TRUE">1</validValue>
        </enum>

        <enum name="sideEnum" encodingType="int8">
            <validValue name="SELL">0</validValue>
            <validValue name="BUY">1</validValue>
        </enum>

        <enum name="ordTypeEnum" encodingType="int8">
            <validValue name="LIMIT">1</validValue>
            <validValue name="IOC">4</validValue>
            <validValue name="POST_ONLY">5</validValue>
            <validValue name="MMP_AND_POST_ONLY">14</validValue>
            <validValue name="RPI">17</validValue>
        </enum>

        <enum name="tdModeEnum" encodingType="int8">
            <validValue name="CASH">1</validValue>
            <validValue name="CROSS">2</validValue>
        </enum>

    </types>

    <sbe:message name="PlaceOrder" id="1" description="Single place order request (exactly one order).">
        <field name="id" id="1" type="int64" description="Numeric request identifier returned in the response."/>
        <field name="instIdCode" id="2" type="int64" description="Unique instrument code."/>
        <field name="side" id="3" type="sideEnum" description="Order side."/>
        <field name="ordType" id="4" type="ordTypeEnum" description="Order type."/>
        <field name="tdMode" id="5" type="tdModeEnum" description="Trade mode."/>
        <field name="szExponent" id="6" type="int8" description="Order size exponent."/>
        <field name="szMantissa" id="7" type="int64" description="Order size mantissa."/>
        <field name="pxExponent" id="8" type="int8" description="Order price exponent."/>
        <field name="pxMantissa" id="9" type="int64" description="Order price mantissa."/>
        <field name="clOrdId" id="10" type="int64" presence="optional" description="Client order ID; numeric values only for SBE."/>
        <field name="expTime" id="11" type="int64" presence="optional"
               description="Request expiry time in epoch microseconds."/>
        <field name="tag" id="12" type="int64" presence="optional" description="Numeric order tag."/>
        <field name="rpiTakerAccess" id="13" type="booleanEnum" presence="optional" description="Whether the order may access RPI liquidity."/>
    </sbe:message>

    <sbe:message name="PlaceOrderResponse" id="2" description="Single place response.">
        <field name="id" id="1" type="int64" description="Request identifier copied from the request."/>
        <field name="code" id="2" type="int32" description="Top-level response code."/>
        <field name="subCode" id="3" type="int32" presence="optional" description="Detailed status sub-code."/>
        <field name="ordId" id="4" type="int64" presence="optional" description="Order ID."/>
        <field name="instIdCode" id="5" type="int64" description="Unique instrument code."/>
        <field name="ts" id="6" type="int64" presence="optional" description="Order creation time in microseconds."/>
        <field name="clOrdId" id="7" type="int64" presence="optional" description="Client order ID."/>
        <field name="tag" id="8" type="int64" presence="optional" description="Numeric order tag."/>
        <field name="inTime" id="9" type="int64" description="WebSocket gateway receive time in microseconds."/>
        <field name="outTime" id="10" type="int64" description="WebSocket gateway response time in microseconds."/>
    </sbe:message>

    <sbe:message name="PlaceOrders" id="3" description="Batch place order request (max 20).">
        <field name="id" id="1" type="int64" description="Numeric request identifier returned in the response."/>
        <field name="expTime" id="2" type="int64" presence="optional"
               description="Request expiry time in epoch microseconds."/>
        <group name="orders" id="10" dimensionType="groupSizeEncoding">
            <field name="instIdCode" id="11" type="int64" description="Unique instrument code."/>
            <field name="side" id="12" type="sideEnum" description="Order side."/>
            <field name="ordType" id="13" type="ordTypeEnum" description="Order type."/>
            <field name="tdMode" id="14" type="tdModeEnum" description="Trade mode."/>
            <field name="szExponent" id="15" type="int8" description="Order size exponent."/>
            <field name="szMantissa" id="16" type="int64" description="Order size mantissa."/>
            <field name="pxExponent" id="17" type="int8" description="Order price exponent."/>
            <field name="pxMantissa" id="18" type="int64" description="Order price mantissa."/>
            <field name="clOrdId" id="19" type="int64" presence="optional" description="Client order ID; numeric values only for SBE."/>
            <field name="tag" id="20" type="int64" presence="optional" description="Numeric order tag."/>
            <field name="rpiTakerAccess" id="21" type="booleanEnum" presence="optional" description="Whether the order may access RPI liquidity."/>
        </group>
    </sbe:message>

    <sbe:message name="PlaceOrdersResponse" id="4" description="Batch place response.">
        <field name="id" id="1" type="int64" description="Request identifier copied from the request."/>
        <field name="code" id="2" type="int32" description="Top-level response code."/>
        <group name="data" id="10" dimensionType="groupSizeEncoding">
            <field name="sCode" id="11" type="int32" description="Order-level status code."/>
            <field name="subCode" id="12" type="int32" presence="optional" description="Detailed status sub-code."/>
            <field name="ordId" id="13" type="int64" presence="optional" description="Order ID."/>
            <field name="instIdCode" id="14" type="int64" description="Unique instrument code."/>
            <field name="ts" id="15" type="int64" presence="optional" description="Order creation time in microseconds."/>
            <field name="clOrdId" id="16" type="int64" presence="optional" description="Client order ID."/>
            <field name="tag" id="17" type="int64" presence="optional" description="Numeric order tag."/>
            <field name="inTime" id="18" type="int64" description="WebSocket gateway receive time in microseconds."/>
            <field name="outTime" id="19" type="int64" description="WebSocket gateway response time in microseconds."/>
        </group>
    </sbe:message>

    <sbe:message name="AmendOrder" id="5" description="Single amend order request (exactly one order).">
        <field name="id" id="1" type="int64" description="Numeric request identifier."/>
        <field name="instIdCode" id="2" type="int64" description="Unique instrument code."/>
        <field name="ordId" id="3" type="int64" presence="optional" description="Order ID; either ordId or clOrdId is required."/>
        <field name="clOrdId" id="4" type="int64" presence="optional" description="Client order ID; either ordId or clOrdId is required."/>
        <field name="newSzExponent" id="5" type="int8" presence="optional" description="New order size exponent; it must be provided with newSzMantissa."/>
        <field name="newSzMantissa" id="6" type="int64" presence="optional" description="New order size mantissa; it must be provided with newSzExponent."/>
        <field name="newPxExponent" id="7" type="int8" presence="optional" description="New order price exponent; it must be provided with newPxMantissa."/>
        <field name="newPxMantissa" id="8" type="int64" presence="optional" description="New order price mantissa; at least one complete price or size pair is required."/>
        <field name="reqId" id="9" type="int64" presence="optional" description="Numeric amendment request ID."/>
        <field name="expTime" id="10" type="int64" presence="optional"
               description="Request expiry time in epoch microseconds."/>
        <field name="rpiTakerAccess" id="11" type="booleanEnum" presence="optional" description="Whether the amended order may access RPI liquidity."/>
    </sbe:message>

    <sbe:message name="AmendOrderResponse" id="6" description="Single amend response.">
        <field name="id" id="1" type="int64" description="Request identifier copied from the request."/>
        <field name="code" id="2" type="int32" presence="optional" description="Top-level response code."/>
        <field name="subCode" id="3" type="int32" presence="optional" description="Detailed status sub-code."/>
        <field name="ordId" id="4" type="int64" presence="optional" description="Order ID."/>
        <field name="reqId" id="5" type="int64" presence="optional"
               description="Client amendment request ID echoed from the request."/>
        <field name="ts" id="6" type="int64" presence="optional" description="Amendment time in epoch microseconds."/>
        <field name="clOrdId" id="7" type="int64" presence="optional" description="Client order ID."/>
        <field name="inTime" id="8" type="int64" description="WebSocket gateway receive time in microseconds."/>
        <field name="outTime" id="9" type="int64" description="WebSocket gateway response time in microseconds."/>
    </sbe:message>

    <sbe:message name="AmendOrders" id="7" description="Batch amend order request (max 20).">
        <field name="id" id="1" type="int64" description="Numeric request identifier."/>
        <field name="expTime" id="2" type="int64" presence="optional"
               description="Request expiry time in epoch microseconds."/>
        <group name="orders" id="10" dimensionType="groupSizeEncoding">
            <field name="instIdCode" id="11" type="int64" description="Unique instrument code."/>
            <field name="ordId" id="12" type="int64" presence="optional" description="Order ID; either ordId or clOrdId is required."/>
            <field name="clOrdId" id="13" type="int64" presence="optional" description="Client order ID; either ordId or clOrdId is required."/>
            <field name="newSzExponent" id="14" type="int8" presence="optional" description="New order size exponent; it must be provided with newSzMantissa."/>
            <field name="newSzMantissa" id="15" type="int64" presence="optional" description="New order size mantissa; it must be provided with newSzExponent."/>
            <field name="newPxExponent" id="16" type="int8" presence="optional" description="New order price exponent; it must be provided with newPxMantissa."/>
            <field name="newPxMantissa" id="17" type="int64" presence="optional" description="New order price mantissa; at least one complete price or size pair is required."/>
            <field name="reqId" id="18" type="int64" presence="optional" description="Numeric amendment request ID."/>
            <field name="rpiTakerAccess" id="19" type="booleanEnum" presence="optional" description="Whether the amended order may access RPI liquidity."/>
        </group>
    </sbe:message>

    <sbe:message name="AmendOrdersResponse" id="8" description="Batch amend response.">
        <field name="id" id="1" type="int64" description="Request identifier copied from the request."/>
        <field name="code" id="2" type="int32" presence="optional" description="Top-level response code."/>
        <group name="data" id="10" dimensionType="groupSizeEncoding">
            <field name="sCode" id="11" type="int32" description="Amendment-level status code."/>
            <field name="subCode" id="12" type="int32" presence="optional" description="Detailed status sub-code."/>
            <field name="ordId" id="13" type="int64" presence="optional" description="Order ID."/>
            <field name="reqId" id="14" type="int64" presence="optional"
                   description="Client amendment request ID echoed from the request."/>
            <field name="ts" id="15" type="int64" description="Amendment time in epoch microseconds."/>
            <field name="clOrdId" id="16" type="int64" presence="optional" description="Client order ID."/>
            <field name="inTime" id="17" type="int64" description="WebSocket gateway receive time in microseconds."/>
            <field name="outTime" id="18" type="int64" description="WebSocket gateway response time in microseconds."/>
        </group>
    </sbe:message>

    <sbe:message name="CancelOrder" id="9" description="Single cancel order request (exactly one order).">
        <field name="id" id="1" type="int64" description="Numeric request identifier."/>
        <field name="instIdCode" id="2" type="int64" description="Unique instrument code."/>
        <field name="ordId" id="3" type="int64" presence="optional" description="Order ID; either ordId or clOrdId is required."/>
        <field name="clOrdId" id="4" type="int64" presence="optional" description="Client order ID; either ordId or clOrdId is required."/>
    </sbe:message>

    <sbe:message name="CancelOrderResponse" id="10" description="Single cancel response.">
        <field name="id" id="1" type="int64" description="Request identifier copied from the request."/>
        <field name="code" id="2" type="int32" presence="optional" description="Top-level response code."/>
        <field name="ordId" id="3" type="int64" presence="optional" description="Order ID."/>
        <field name="ts" id="4" type="int64" presence="optional" description="Cancellation time in epoch microseconds."/>
        <field name="clOrdId" id="5" type="int64" presence="optional" description="Client order ID."/>
        <field name="inTime" id="6" type="int64" description="WebSocket gateway receive time in microseconds."/>
        <field name="outTime" id="7" type="int64" description="WebSocket gateway response time in microseconds."/>
    </sbe:message>

    <sbe:message name="CancelOrders" id="11" description="Batch cancel order request (max 20).">
        <field name="id" id="1" type="int64" description="Numeric request identifier."/>
        <group name="orders" id="10" dimensionType="groupSizeEncoding">
            <field name="instIdCode" id="11" type="int64" description="Unique instrument code."/>
            <field name="ordId" id="12" type="int64" presence="optional" description="Order ID; either ordId or clOrdId is required."/>
            <field name="clOrdId" id="13" type="int64" presence="optional" description="Client order ID; either ordId or clOrdId is required."/>
        </group>
    </sbe:message>

    <sbe:message name="CancelOrdersResponse" id="12" description="Batch cancel response.">
        <field name="id" id="1" type="int64" description="Request identifier copied from the request."/>
        <field name="code" id="2" type="int32" presence="optional" description="Top-level response code."/>
        <group name="data" id="10" dimensionType="groupSizeEncoding">
            <field name="sCode" id="11" type="int32" description="Cancellation-level status code."/>
            <field name="ordId" id="12" type="int64" presence="optional" description="Order ID."/>
            <field name="ts" id="13" type="int64" presence="optional" description="Cancellation time in epoch microseconds."/>
            <field name="clOrdId" id="14" type="int64" presence="optional" description="Client order ID."/>
            <field name="inTime" id="15" type="int64" description="WebSocket gateway receive time in microseconds."/>
            <field name="outTime" id="16" type="int64" description="WebSocket gateway response time in microseconds."/>
        </group>
    </sbe:message>
</sbe:messageSchema>
