<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
*
 * Copyright (C) 2015 MarketFactory, Inc. All rights reserved.
 * Use in source and binary forms, with or without modification, is permitted provided that the following conditions are met:
 * 1. You may only use this software for internal evaluation and testing purposes and may not use the software for engaging
 * in live trades, unless and until you have entered into a separate agreement with MarketFactory governing the use of
 * MarketFactory software in a production environment.
 * 2. You may not distribute the software (in either source or binary forms) to third parties.
 * 3. All copies of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 *    THIS SOFTWARE IS PROVIDED BY MARKETFACTORY AND ITS LICENSORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
 *    BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
 *    NO EVENT SHALL MARKETFACTORY OR ITS LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 *    OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 *    ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 -->
<sbe:messageSchema xmlns:sbe="http://www.fixprotocol.org/ns/simple/RC3"
                   package="mfstp_booking"
                   id="3"
                   version="1"
                   semanticVersion="MF-FIX5.0SP2"
                   description="Schema for order messages to MF.  Based on FIX5.0SP2 spec. The protocol supports TCP, UDP unicast, shared memory, and reliable UDP multicast transports."
                   byteOrder="littleEndian">
    <!-- SBE defined types -->
    <types>
        <composite name="messageHeader" description="The SBE header that is part of each message.">
            <type name="blockLength" primitiveType="uint16" description=" The length of the message root block before repeating groups or variable data commences."/>
            <type name="templateId"  primitiveType="uint16" description="The identifier for the template type of the message that is to follow."/>
            <type name="schemaId"    primitiveType="uint16" description="The identifier for the schema that defines the message."/>
            <type name="version"     primitiveType="uint16" description="The version of the schema allowing for extension."/>
        </composite>
        <composite name="varDataEncoding" description="Definition for a variable length string.">
            <type name="length"  primitiveType="uint8" description="Length of string." maxValue="1300"/>
            <type name="varData" primitiveType="uint8" description="Array of UTF-8 characters." length="0" characterEncoding="UTF-8"/>
        </composite>
        <composite name="groupSizeEncoding" description="Repeating group dimensions." semanticType="NumInGroup">
            <type name="blockLength" description="Length of element."                  primitiveType="uint8"/>
            <type name="numInGroup"  description="Number of items in repeating group." primitiveType="uint8"/>
        </composite>
    </types>
    <!-- Primitive types -->
    <types>
        <type name="CharNULL" presence="optional" nullValue="0" primitiveType="char" semanticType="char"/>
        <type name="Int32NULL" presence="optional" nullValue="-2147483648" primitiveType="int32" semanticType="int"/>
        <type name="Int8NULL" presence="optional" nullValue="-128"        primitiveType="int8"/>
        <type name="uInt32NULL" presence="optional" nullValue="4294967295"  primitiveType="uint32"/>
        <type name="uInt8NULL" presence="optional" nullValue="255"         primitiveType="uint8"/>
        <type name="LocalMktDate" description="Local calendar date in days since epoch."   presence="optional" nullValue="65535"       primitiveType="uint16" semanticType="LocalMktDate"/>
        <type name="SeqNum" description="" primitiveType="uint32" semanticType="SeqNum"/>
        <type name="MDComponentValue" description="An untyped array for storing a value." primitiveType="uint8" length="32"/>
        <type name="SecurityID"   description="Numeric ID of a given security." primitiveType="uint32"/>
        <type name="Timestamp"    description="Number of nanoseconds since epoch" primitiveType="uint64"/>
        <type name="OrderID" presence="optional" nullValue="18446744073709551615"   description="Order ID assigned by client." primitiveType="uint64"/>
    </types>
    <!-- String types -->
    <types>
        <type name="Text"              description="Free format text string."                  length="64"  primitiveType="char" semanticType="String"/>
        <type name="SecurityRequestID" description="UniqueID for security definition request." length="32"  primitiveType="char" semanticType="String"/>
        <type name="Symbol"            description="Identifier for a security."                length="32"  primitiveType="char" semanticType="String"/>
        <type name="Username"          description="Id given to user for logging on."          length="32"  primitiveType="char" semanticType="String"/>
        <type name="Password"          description="Password used to logon."                   length="32"  primitiveType="char" semanticType="String"/>
    </types>
    <!-- Price and Qty types -->
    <types>
        <composite name="DecimalQtyNULL" description="A number representing quantity" semanticType="Qty">
            <type name="mantissa" description="The significant digits of the quantity value with an optional NULL value." primitiveType="int64" presence="optional" nullValue="-9223372036854775807"/>
            <type name="exponent" description="The scale of the decimal number as a power of 10."                         primitiveType="int8"  presence="constant">-5</type>
        </composite>
        <composite name="PriceNULL" description="Price NULL" semanticType="Price">
            <type name="mantissa" description="The significant digits of the price value with an optional NULL value." primitiveType="int64" presence="optional" nullValue="-9223372036854775807"/>
            <type name="exponent" description="The scale of the decimal number as a power of 10."                      primitiveType="int8"  presence="constant">-9</type>
        </composite>
    </types>
    <types>
        <type name="ClOrdIDString" description="ID constructed by client to build order.  It is restricted in the following ways:
                                                     1.  Must be less than 20 characters.
                                                     2.  All valid ASCII from decimal 32 to decimal 126 excluding
                                                         ~`_!*,-:=[]" primitiveType="char" length="32"/>
        <type name="OrderIDString" description="Fixed length string type for IDs assigned by venues." primitiveType="char" length="32"/>
        <type name="ConfirmationIDString" description="Fixed length string type for IDs assigned by booking party." primitiveType="char" length="32"/>
        <!-- FIX types -->
        <enum name="SubscriptionRequestType" description="Type of subscription request." encodingType="char">
          <validValue name="Subscribe">1</validValue>
          <validValue name="Unsubscribe">2</validValue>
        </enum>

        <set name="Flags" encodingType="uint8">
            <choice name="possDupFlag" description="Set to true if this is in response to replay.">0</choice>
            <choice name="isBaseSpecified" description="Set to true if the dealt currency is base, false means dealt currency is term.">1</choice>
        </set>

        <enum name="Side" description="The side of the order from the client/taker perspective" encodingType="char" >
            <validValue name="Buy">1</validValue>
            <validValue name="Sell">2</validValue>
        </enum>
        <enum name="TrdRptStatus" encodingType="int8">
            <validValue name="Accepted">0</validValue>
            <validValue name="Rejected">1</validValue>
        </enum>
        <enum name="TradeReportRejectReason" encodingType="int8">
            <validValue name="UnknownInstrument">2</validValue>
            <validValue name="Other">99</validValue>
            <validValue name="ExceedsNopLimit">100</validValue>
            <validValue name="ExceedsPendingLimit">101</validValue>
            <validValue name="ExceedsSingleLimit">102</validValue>
            <validValue name="ExceedsDslLimit">103</validValue>
            <validValue name="ExceedsPositionLimit">104</validValue>
            <validValue name="InvalidTradeCaptureReport">105</validValue>
            <validValue name="DuplicateExecID">106</validValue>
            <validValue name="UnknownCounterParty">107</validValue>
            <validValue name="InvalidSecurityID">108</validValue>
        </enum>
        <enum name="ExecType" description="Execution Type." encodingType="char">
            <validValue name="New">0</validValue>
            <validValue name="Rejected">8</validValue>
            <validValue name="Canceled">4</validValue>
            <validValue name="Trade">F</validValue>
            <validValue name="AllocateCredit" description="Used when the booking session is configured for credit checking .">W</validValue>
        </enum>
        <enum name="PartyRole" description="Identifies the type or role of the PartyID (448) specified." encodingType="uint8">
            <validValue name="ClientID" description="Client ID (formerly FIX 4.2 ClientID)">3</validValue>
            <validValue name="OrderOriginationTrader" description="Order Origination Trader (associated with Order Origination Firm - i.e. trader who initiates/submits the order)">11</validValue>
            <validValue name="CustomerAccount" description="Customer Account">24</validValue>
            <validValue name="ExecutionVenue" description="Execution Venue">73</validValue>
            <validValue name="HedgingVenue" description="Hedging Venue - Custom Role">254</validValue>
        </enum>
        <enum name="OrdRejReason" description="Order Rejection Reason." encodingType="uint8">
            <validValue name="UnknownSymbol">1</validValue>
            <validValue name="IncorrectQuantity">13</validValue>
            <validValue name="ExceedsNopLimit">100</validValue>
            <validValue name="ExceedsPendingLimit">101</validValue>
            <validValue name="ExceedsSingleLimit">102</validValue>
            <validValue name="ExceedsDslLimit">103</validValue>
            <validValue name="ExceedsPositionLimit">104</validValue>
            <validValue name="UnknownCounterParty">107</validValue>
        </enum>
        <type name="PartyID" description="Party ID Data" presence="optional" primitiveType="char" length="128" semanticType="String"/>
    </types>

    <!-- Session messages -->
    <sbe:message name="Logon" id="0" description="Used to logon to a trading data session." semanticType="A">
        <field name="Username" id="533" type="Username" semanticType="String"/>
        <field name="Password" id="554" type="Password" semanticType="String"/>
        <field name="NextExpectedMsgSeqNum" id="789" type="SeqNum" semanticType="SeqNum"/>
    </sbe:message>
    <sbe:message name="LogonResponse" id="1" description="An acknowledgement from the server that the logon was successful as well as the expected heartbeat interval." semanticType="A">
        <field name="NextExpectedMsgSeqNum" id="789" type="SeqNum" semanticType="SeqNum"/>
    </sbe:message>
    <sbe:message name="Heartbeat" id="2" description="This is sent from each side of the connection every 3 seconds." semanticType="0">
        <field name="CurrentSeqNum" id="20019" type="SeqNum" description="This is the last sequence number sent.  Used to detect message drops." />
    </sbe:message>
    <sbe:message name="Logout" id="3" description="A request to stop the session." semanticType="5">
        <field name="Text" id="58" type="Text" description="Free format text string. May include reason for logout" semanticType="String"/>
    </sbe:message>
    <sbe:message name="LogoutResponse" id="4" description="An acknowledgement that the session has been terminated." semanticType="5"/>

    <sbe:message name="SecurityDefinitionRequest" id="5" description="A request for a list of a venue's securities and their attributes." semanticType="a"/>

    <sbe:message name="SecurityDefinition" id="6" description="Describes the attributes of a given security." semanticType="d">
        <field name="TotNumReports" id="911" type="uint32" description="The total number of security definitions in group.  This is used in the multicast stream so the application can detect the receipt of all security definitions."  semanticType="int"/>
        <field name="Symbol" id="55" type="Symbol" semanticType="String"/>
        <field name="SecurityID"  id="48" type="SecurityID"/>
        <field name="MinPriceIncrement" id="969" type="PriceNULL" description="The minimum price movement." semanticType="Price"/>
        <field name="BigPriceIncrement" id="20004" type="PriceNULL" description="PIP position" semanticType="Price"/>
    </sbe:message>

    <sbe:message name="TradeCaptureReportRequest" id="7" description="Sent from MF to client to initiate the reporting of trade captures.
                                                                      This will be sent after logon and once the client is synched with the
                                                                      server by replaying any dropped messages." semanticType="AD">
      <field name="SendingTime" id="52" type="Timestamp" description="Time when the trade capture is generated." semanticType="UTCTimestamp"/>
      <field name="SubscriptionRequestType" id="263" type="SubscriptionRequestType" semanticType="char"/>
    </sbe:message>

    <sbe:message name="TradeCaptureReportSpotForward" id="8" description="Sent to the venue in order to report spot trades." semanticType="AE">
        <field name="MsgSeqNum" id="34" type="SeqNum"/>
        <field name="Flags" id="20028" type="Flags"/>
        <field name="SendingTime" id="52" type="Timestamp" description="Time when the trade capture is generated." semanticType="UTCTimestamp"/>
        <field name="SecurityID"  id="48" type="SecurityID"/>
        <field name="ExecType" id="150" type="ExecType" semanticType="char"/>
        <field name="ExecID"   id="17" type="OrderIDString" description="Unique identifier for the trade." semanticType="String"/>
        <field name="LastSpotRate"   id="194" type="PriceNULL" description="Spot rate for execution"/>
        <field name="LastPx"      id="31" type="PriceNULL" description="All in price for execution: LastSpotRate + forward points"/>
        <field name="LastQty"   id="32" type="DecimalQtyNULL" description="Amount of spot execution."/>
        <field name="LastQtyDps"   id="20036" type="Int8NULL" description="Precision of LastQty in decimal points"/>
        <field name="ContraAmt"   id="20037" type="DecimalQtyNULL" description="Counterparty Amount of spot execution."/>
        <field name="ContraDps"   id="20038" type="Int8NULL" description="Precision of ContraAmt in decimal points"/>
        <field name="TradeDate" id="75" type="LocalMktDate" semanticType="LocalMktDate"/>
        <field name="SettlDate" id="64" type="LocalMktDate" semanticType="LocalMktDate"/>
        <field name="SpotDate" id="20035" type="LocalMktDate" semanticType="LocalMktDate"/>
        <field name="Side"      id="54" type="Side" description="The side of the order from the client/taker perspective"/>
        <field name="LastMarketSpotRate"   id="20040" type="PriceNULL" description="Market Spot rate"/>
        <field name="LastMarketPx"      id="20041" type="PriceNULL" description="All in market price : LastMarketSpotRate + market forward points"/>
        <field name="SpotDps"   id="20042" type="Int8NULL" description="precision for LastSpotRate and LastMarketSpotRate - e.g. EUR/USD=5 reflecting 5 digit precision of EUR/USD quotes"/>
        <field name="PxDps"     id="20043" type="Int8NULL" description="precision for LastPx and LastMarketPx"/>
        <field name="ScalePosition"  id="20044" type="Int8NULL" description="Defines what a pip is - e.g. for EUR/USD = 4, USD/JPY = 2, USD/HUF = 3 etc.."/>
        <field name="OrderIDString" id="37" type="OrderIDString" description="Order ID assigned by client." />
        <group name="NoPartyIDs" id="453" description="Number of parties provided" dimensionType="groupSizeEncoding">
            <field name="PartyRole" id="452" type="PartyRole" semanticType="char"/>
            <field name="PartyID" id="448" type="PartyID" semanticType="String"/>
        </group>
    </sbe:message>

    <sbe:message name="NewOrderSingle" id="9" description="Message for submitting a single order." semanticType="D">
        <field name="MsgSeqNum" id="34" type="SeqNum" description="Currently not used."/>
        <field name="Flags" id="20028" type="Flags"/>
        <field name="OrderIDString" id="37" type="OrderIDString" description="Order ID assigned by client." />
        <field name="SecurityID"  id="48" type="SecurityID"/>
        <field name="Side"   id="54" type="Side" description="The side of the order from the client/taker perspective"/>
        <field name="LastQty"   id="32" type="DecimalQtyNULL" description="Quantity of order executed in this execution, if any."/>
        <field name="LastPx"   id="31" type="PriceNULL" description="Price of this last fill, if any."/>
        <field name="SettlDate" id="64" type="LocalMktDate" semanticType="LocalMktDate" description="Settlement date."/>
        <field name="SendingTime" id="52" type="Timestamp" description="Time when the NewOrderSingle is generated." semanticType="UTCTimestamp"/>
        <group name="NoPartyIDs" id="453" description="Number of parties provided" dimensionType="groupSizeEncoding">
            <field name="PartyRole" id="452" type="PartyRole" semanticType="char"/>
            <field name="PartyID" id="448" type="PartyID" semanticType="String"/>
        </group> 
    </sbe:message>

    <sbe:message name="TradeCaptureReportSwap" id="10" description="Sent to the venue in order to report swap trades." semanticType="AE">
        <field name="MsgSeqNum" id="34" type="SeqNum"/>
        <field name="Flags" id="20028" type="Flags"/>
        <field name="SendingTime" id="52" type="Timestamp" description="Time when the trade capture report swap is generated." semanticType="UTCTimestamp"/>
        <field name="SecurityID"  id="48" type="SecurityID"/>
        <field name="ExecType" id="150" type="ExecType" semanticType="char"/>
        <field name="ExecID"   id="17" type="OrderIDString" description="Unique identifier for the trade." semanticType="String"/>
        <field name="LastSpotRate"   id="194" type="PriceNULL" description="Spot rate for the trade."/>
        <field name="LastPx"      id="31" type="PriceNULL" description="All in price for execution: LastSpotRate + leg 1 forward points"/>
        <field name="LastPx2"      id="20029" type="PriceNULL" description="All in price for execution: LastSpotRate + leg 2 forward points"/>
        <field name="LegLastQty"   id="1418" type="DecimalQtyNULL" description="Amount in fill for leg 1."/>
        <field name="LegLastQty2"   id="20026" type="DecimalQtyNULL" description="Amount in fill for leg 2."/>
        <field name="LastQtyDps"   id="20036" type="Int8NULL" description="Precision of LastQty in decimal points"/>
        <field name="LegContraAmt"   id="20048" type="DecimalQtyNULL" description="Counterparty Amount of spot execution."/>
        <field name="LegContraAmt2"   id="20049" type="DecimalQtyNULL" description="Counterparty Amount of spot execution."/>
        <field name="ContraDps"   id="20038" type="Int8NULL" description="Precision of ContraAmt in decimal points"/>
        <field name="TradeDate" id="75" type="LocalMktDate" semanticType="LocalMktDate"/>
        <field name="SpotDate" id="20035" type="LocalMktDate" semanticType="LocalMktDate" description="Settlement date of the spot portion" />
        <field name="SettlDate" id="64" type="LocalMktDate" semanticType="LocalMktDate" description="Settlement date of leg 1 component."/>
        <field name="SettlDate2" id="193" type="LocalMktDate" semanticType="LocalMktDate" description="Settlement date of the leg 2 component."/>
        <field name="Side"      id="54" type="Side" description="The side of the order from the client/taker perspective"/>
        <field name="LastMarketSpotRate"   id="20040" type="PriceNULL" description="Market Spot rate"/>
        <field name="LastMarketPx"      id="20041" type="PriceNULL" description="All in market price : LastMarketSpotRate + leg 1 market forward points"/>
        <field name="LastMarketPx2"      id="20045" type="PriceNULL" description="All in market price : LastMarketSpotRate + leg 2 market forward points"/>
        <field name="SpotDps"   id="20042" type="Int8NULL" description="precision for LastSpotRate and LastMarketSpotRate - e.g. EUR/USD=5 reflecting 5 digit precision of EUR/USD quotes"/>
        <field name="PxDps"     id="20043" type="Int8NULL" description="precision for LastPx and LastMarketPx"/>
        <field name="ScalePosition"  id="20044" type="Int8NULL" description="Defines what a pip is - e.g. for EUR/USD = 4, USD/JPY = 2, USD/HUF = 3 etc.."/>
        <field name="OrderIDString" id="37" type="OrderIDString" description="Order ID assigned by client." />
        <group name="NoPartyIDs" id="453" description="Number of parties provided" dimensionType="groupSizeEncoding">
            <field name="PartyRole" id="452" type="PartyRole" semanticType="char"/>
            <field name="PartyID" id="448" type="PartyID" semanticType="String"/>
        </group>
    </sbe:message>

    <sbe:message name="TradeCaptureReportAck" id="11" description="Sent from MF to client if a TradeCaptureReport is rejected." semanticType="AR">
        <field name="MsgSeqNum" id="34" type="SeqNum"/>
        <field name="Flags" id="20028" type="Flags"/>
        <field name="SendingTime" id="52" type="Timestamp" description="Time when the trade capture report ack is generated." semanticType="UTCTimestamp"/>
        <field name="ExecType" id="150" type="ExecType" semanticType="char"/>
        <field name="ExecID" id="17" type="OrderIDString" description="Unique identifier for the trade for which this ack corresponds." semanticType="String"/>
        <field name="TrdRptStatus" id="939" type="TrdRptStatus" description="The status of the trade report. Currently just reports rejections of trade capture reports." semanticType="int"/>
        <field name="TradeReportRejectReason" id="751" type="TradeReportRejectReason" description="The reason for the rejecting." semanticType="int"/>
    </sbe:message>

    <sbe:message name="Confirmation" id="12" description="Sent from MF to client for trade booking confirmation." semanticType="AK">
        <field name="MsgSeqNum" id="34" type="SeqNum"/>
        <field name="ConfirmID" id="664" type="ConfirmationIDString" description="Unique identifier for the booked trade." semanticType="String"/>
        <field name="ExecID" id="17" type="OrderIDString" description="Unique identifier for the trade for which this ack corresponds." semanticType="String"/>
    </sbe:message>

    <sbe:message name="OrderCancelRequest" id="13" description="Cancel an outstanding order." semanticType="F">
        <field name="MsgSeqNum" id="34" type="SeqNum" description="Currently not used."/>
        <field name="Flags" id="20028" type="Flags"/>
        <field name="OrderIDString" id="37" type="OrderIDString" description="Order ID assigned by client" />        
        <field name="SecurityID"  id="48" type="SecurityID"/>
        <field name="ClOrdID"     id="11" type="ClOrdIDString" description="Identifier of this cancel request." semanticType="String"/>
        <field name="SendingTime" id="52" type="Timestamp" description="Time when the order cancel request is generated." semanticType="UTCTimestamp"/>
    </sbe:message>

    <sbe:message name="ExecutionReport" id="14" description="A message for responses from the venue for order actions and events." semanticType="8">
        <field name="MsgSeqNum" id="34" type="SeqNum"/>
        <field name="OrderIDString" id="37" type="OrderIDString" description="Order ID assigned by client" />
        <field name="ExecType" id="150" type="ExecType" semanticType="char"/>
        <field name="SendingTime" id="52" type="Timestamp" description="Time when the execution report is generated." semanticType="UTCTimestamp"/>
        <field name="OrdRejReason" id="103" type="OrdRejReason" description="The reason for the order rejecting." semanticType="int"/>
    </sbe:message>

    <sbe:message name="OrderCancelReject" id="15" description="Order Cancel Reject for an outstanding order." semanticType="9">
        <field name="MsgSeqNum" id="34" type="SeqNum" description="Currently not used."/>
        <field name="Flags" id="20028" type="Flags"/>
        <field name="OrderIDString" id="37" type="OrderIDString" description="Order ID assigned by client." />        
        <field name="SecurityID"  id="48" type="SecurityID"/>
        <field name="ClOrdID"     id="11" type="ClOrdIDString" description="Identifier of this order cancel reject." semanticType="String"/>
        <field name="SendingTime" id="52" type="Timestamp" description="Time when the OrderCancelReject is generated." semanticType="UTCTimestamp"/>
    </sbe:message>

</sbe:messageSchema>
