<?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="mfmarketdata"
                   id="1"
                   version="2"
                   semanticVersion="MF-FIX5.0SP2"
                   description="Schema for marketdata messages.  Based on the FIX50SP2.
                                The protocol is designed to run over various transports (TCP, UDP unicast, shared memory, and UDP multicast)."
                   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="Int32NULL"        description="Nullable, signed 32-bit integer." presence="optional" nullValue="-2147483648" primitiveType="int32" semanticType="int"/>
        <type name="Int8NULL"         description="Nullable, signed 8-bit integer." presence="optional" nullValue="-128" primitiveType="int8"/>
        <type name="uInt32NULL"       description="Nullable, unsigned 32-bit integer." presence="optional" nullValue="4294967295"  primitiveType="uint32"/>
        <type name="uInt8NULL"        description="Nullable, unsigned 8-bit integer." 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="Sequence number for detecting missed messages." 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="VenueID"          description="Numeric ID of a given venue." primitiveType="uint32"/>
        <type name="Timestamp"        description="Number of nanoseconds since epoch" 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>
    <!-- Enumerations and sets -->
    <types>
        <enum name="OrdType" encodingType="char" semanticType="char">
            <validValue name="Market" description="Standard Market order. Buys or sells the order quantity regardless of price.">1</validValue>
            <validValue name="Limit" description="Standard Limit order. Buys or sells the order quantity without exceeding the order's price.">2</validValue>
            <validValue name="StopLoss" description="Standard Stop Loss order. Executes an exposure reducing market order when market exceeds order's price.">3</validValue>
            <validValue name="StopLimit" description="Standard Stop Limit order. Executes an exposure reducing limit order when market exceeds order's price.">4</validValue>
            <validValue name="PreviouslyQuoted" description="An order to hit an individual quote.  To hit multiple quotes, aka sweeping, the user must submit individual orders from best to worst price.">D</validValue>
            <validValue name="OrderCancelRequest" description="An order to modify a previously submitted order.">x</validValue>
            <validValue name="VwapSweep" description="An order that can hit/lift one or multiple quotes by submitting an order with the desired amount and the Volume Weighted Average Price (VWAP) of the total amount.">y</validValue>
            <validValue name="PreviouslyQuotedAmountTier" description="An order to hit an individual quote within a Amount Tier Quote Book.Only one tier may be executed once per collection.">z</validValue>
        </enum>
        <enum name="TimeInForce" encodingType="char">
            <validValue name="Day">0</validValue>
            <validValue name="GTC">1</validValue>
            <validValue name="IOC">3</validValue>
            <validValue name="FOK">4</validValue>
        </enum>

        <set name="VenueAttributes" description="Special features of a venue." encodingType="uint8">
            <choice name="hasBatching" description="Set if the venue supports batching of Market Data. Currently only on EBS feeds.">0</choice>
            <choice name="hasMinQty" description="Set if the venue has a minQty field for orders.">1</choice>
        </set>
        <set name="Flags" description="General use flags." encodingType="uint8">
            <choice name="lastMDEntryInGroup" description="Set if this is the last MDEntry in group.">0</choice>
        </set>
        <enum name="MDUpdateAction" description="A market data update action." encodingType="char" semanticType="char">
            <validValue name="New">0</validValue>
            <validValue name="Change">1</validValue>
            <validValue name="Delete">2</validValue>
        </enum>
        <enum name="MDEntryType" description="A market data entry type." encodingType="char">
            <validValue name="Bid" description="Entry contains bid details.">0</validValue>
            <validValue name="Offer" description="Entry contains offer details.">1</validValue>
            <validValue name="Trade" description="Entry contains venue trade details.">2</validValue>
            <validValue name="EmptyBook" description="Sent to indicate the book should be cleared.">J</validValue>
            <validValue name="WorstTradeGiven" description="The worst price that was sold on EBS during a timeslice.">w</validValue>
            <validValue name="WorstTradePaid" description="The worst price that was bought on EBS during a timeslice.">x</validValue>
            <validValue name="TradeGiven" description="Indicates trade where the offer was aggressed.">y</validValue>
            <validValue name="TradePaid" description="Indicates trade where the bid was aggressed.">z</validValue>
        </enum>
        <enum name="MDBookType" description="Defines the type of a market data update group." encodingType="uint8">
            <validValue name="TopOfBook" description="Book containing just the top-of-book information.">1</validValue>
            <validValue name="PriceDepth" description="Book containing the standard per level price and depth information.">2</validValue>
            <validValue name="OrderDepth" description="Book containing the count of orders at each price level.">3</validValue>
            <validValue name="AmountView" description="
                The worst PRICE for which you would have
                to trade in order to get at least the regular amount (it's a minimum, not
                a precise value). The size field should be set to the same fixed
                constraint amount every time (fixed by the exchange for each market).
                This corresponds to an EBS Regular Price and to a Reuters Aggregate
                Price. This entry is credit screened (once again, we treat EBS Live's
                amount constraint as if it were credit-screened).">100</validValue>
            <validValue name="SpreadView" description="
                A price constraint, that is, the sum total amount that is available from
                the top of the book through a fixed number of price levels away from that
                price. Essentially, this provides an amount variable for a fixed price.
                Because the price changes constantly, the fixed price range is usually
                specified as a price difference from the top-of-book. We compute provide
                that price in this entry. This corresponds to EBS's Outside Amount.
                Sometimes this entry is capped. This entry is credit-screened.">101</validValue>
            <validValue name="ExchangeBest" description="Used for Reuters.  The best price on the venue, regardless of whether it is credit screened.">102</validValue>
            <validValue name="PriceDepthQuote" description="Book containing quotes that have been aggregated by price.">103</validValue>
            <validValue name="Quote" description="Book containing quotes that must be aggressed individually. ">104</validValue>
            <validValue name="QuoteAmountTier" description="A stream of a collection of quotes where there are tiers of amount bands.  Only one tier may be executed per collection.">105</validValue>
            <validValue name="PriceDepthQuoteAmountTier" description="An Amount Tier Book that is aggregated by price.">106</validValue>
        </enum>
        <enum name="SubscriptionRequestType" description="Market data subscription request type." encodingType="char">
            <validValue name="SnapshotAndUpdates" description="Subscription for all market data updates.">1</validValue>
            <validValue name="Disable" description="Unsubscribe for all market data updates.">2</validValue>
            <validValue name="Resubscribe" description="Request for resubscription.  Applicable when the transport is UDP unicast.">z</validValue>
        </enum>
        <enum name="SecurityRequestType" description="Market data security request type." encodingType="uint8">
            <validValue name="AllSecurities" description="Request for all securities.">8</validValue>
        </enum>
        <enum name="SecurityTradingStatus" description="Trading status for a specific security." encodingType="uInt8NULL">
            <validValue name="Close">4</validValue>
            <validValue name="ReadyToTrade">17</validValue>
            <validValue name="NotAvailableForTrading">18</validValue>
            <validValue name="UnknownOrInvalid">20</validValue>
            <validValue name="PreOpen">21</validValue>
            <validValue name="PostClose">26</validValue>
            <validValue name="Error">254</validValue>
        </enum>
        <enum name="MDComponentType" description="Type of an Market data component which can be attached to a market data message." encodingType="uint8">
            <validValue name="Int">1</validValue>
            <validValue name="Length">2</validValue>
            <validValue name="NumInGroup">3</validValue>
            <validValue name="SeqNum">4</validValue>
            <validValue name="TagNum">5</validValue>
            <validValue name="Float">6</validValue>
            <validValue name="Qty">7</validValue>
            <validValue name="Price">8</validValue>
            <validValue name="PriceOffset">9</validValue>
            <validValue name="Amt">10</validValue>
            <validValue name="Percentage">11</validValue>
            <validValue name="Char">12</validValue>
            <validValue name="Boolean">13</validValue>
            <validValue name="String">14</validValue>
            <validValue name="MultipleCharValue">15</validValue>
            <validValue name="Currency">17</validValue>
            <validValue name="MonthYear">18</validValue>
            <validValue name="UTCTimestamp">19</validValue>
            <validValue name="UTCTimeOnly">20</validValue>
            <validValue name="LocalMktDate">21</validValue>
            <validValue name="data">23</validValue>
            <validValue name="MultipleStringValue">24</validValue>
            <validValue name="Country">25</validValue>
            <validValue name="Language">26</validValue>
            <validValue name="TZTimeOnly">27</validValue>
            <validValue name="TZTimestamp">28</validValue>
            <validValue name="Tenor">29</validValue>
        </enum>
        <enum name="MDReqRejReason" description="Reason for rejection of a Market data subscription request."  encodingType="char">
            <validValue name="UnknownSymbol" description="Rejected due to unknown security symbol.">0</validValue>
            <validValue name="Other" description="Rejected for other reason. Catch-all.">Z</validValue>
        </enum>
    </types>
    <!-- Session messages -->
    <sbe:message name="Logon" id="2" description="Used to logon to a market data session." semanticType="A">
        <field name="Username" id="533" type="Username" semanticType="String"/>
        <field name="Password" id="554" type="Password" semanticType="String"/>
    </sbe:message>
    <sbe:message name="LogonResponse" id="3" description="An acknowledgement from the server that the logon was successful as well as the expected heartbeat interval." semanticType="A">
    </sbe:message>
    <sbe:message name="Logout" id="4" 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="5" description="An acknowledgement that the session has been terminated." semanticType="5"/>
    <sbe:message name="Heartbeat" id="6" description="This is sent from each side of the connection after x seconds of inactivity." semanticType="0"/>
    <sbe:message name="SecurityDefinitionRequest" id="7" description="A request for a list of a venue's securities and their attributes." semanticType="a">
        <field name="VenueID" id="20022" type="VenueID" semanticType="int"/>
        <field name="SecurityRequestType" id="321" type="SecurityRequestType" />
    </sbe:message>
    <sbe:message name="SecurityDefinition" id="8" 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="VenueID" id="20022" type="VenueID" 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>

    <!-- Marketdata subscriptions -->
    <sbe:message name="MarketDataRequest" id="9" description="A request to create, cancel, or otherwise manipulate a subscription for a single security from a specific venue." semanticType="V">
        <field name="VenueID" id="20022" type="VenueID" semanticType="int"/>
        <field name="SubscriptionRequestType"  id="263" type="SubscriptionRequestType"/>
        <field name="SecurityID"  id="48" type="SecurityID"/>
    </sbe:message>
    <sbe:message name="MarketDataRequestReject" id="10" description="A rejection of a request for market data." semanticType="Y">
        <field name="VenueID" id="20022" type="VenueID" semanticType="int"/>
        <field name="SecurityID"  id="48" type="SecurityID"/>
        <field name="MDReqRejReason"  id="281" type="MDReqRejReason"/>
        <field name="Text"  id="58" type="Text" description="Additional information, if any, about the rejection."/>
    </sbe:message>

    <!-- Security status -->
    <sbe:message name="SecurityStatus" id="11"
                 description="Contains details of a venue status, trade/settle dates, and more. Comes as a response to a MarketDataRequest and should be processed before the first market data message. Can also arrive asynchronously if the state of a security changes." semanticType="f">
        <field name="VenueID" id="20022" type="VenueID" semanticType="int"/>
        <field name="SecurityID" id="48" type="SecurityID" semanticType="int"/>
        <field name="TradeDate" id="75" type="LocalMktDate" description="Trade Session Date of security." semanticType="LocalMktDate"/>
        <field name="SettlDate" id="64" type="LocalMktDate" description="Settlement date of security." semanticType="LocalMktDate"/>
        <field name="SecurityTradingStatus" id="326" type="SecurityTradingStatus" description="Identifies the trading status applicable to the instrument or Security Group" semanticType="int"/>
        <field name="Text" id="58" type="Text" description="Explanation of status state."/>
    </sbe:message>

    <!-- MarketData messages -->
    <sbe:message name="MarketDataIncrementalRefresh" id="0"
                 description="First message, and possibly only, in a Market data update group. Contains common information about
                 the updates to follow. Also contains, for the sake of compression, a single MDEntry update."
                 semanticType="X">
        <field name="NumMDEntries"  id="20005" type="uint16" description="Number of update entries in this group. This total includes this MarketDataIncrementalRefresh message itself since it 'contains' an MDEntry. "/>
        <field name="VenueSeqNum" id="20006" type="SeqNum" description="Used to correlate this entry with the venue message.  Will be NULL if message is generated by MF (snapshot, enhanced data, etc.).  This can also be used to group messages from the same venue message since they will share the same sequence number."/>
        <field name="VenueTimestamp" id="20007" type="Timestamp" description="Time the market data was stamped by the source venue."/>
        <field name="TimeArrival"    id="20008" type="Timestamp" description="Time the market data was received by MF."/>
        <field name="VenueID" id="20022"   type="VenueID"/>
        <field name="SecurityID"     id="48"   type="SecurityID"/>
        <field name="RptSeq"         id="83"   type="SeqNum" description="SeqNum used to detect packet loss."/>
        <field name="MDEntryType"    id="269"  type="MDEntryType" presence="optional"/>
        <field name="MDEntryPx"      id="270"  type="PriceNULL" description="Price (in mantissa format)."/>
        <field name="MDEntrySize"    id="271"  type="DecimalQtyNULL" description="Size (in mantissa format)."/>
        <field name="MinQty"         id="110"  type="DecimalQtyNULL" description="Minimum quantity available to execute (in mantissa format)."/>
        <field name="MDUpdateAction" id="279"  type="MDUpdateAction" presence="optional" description="Presence is optional if the MDEntryType is 'Empty' for example."/>
        <field name="MDBookType"     id="1021" type="MDBookType" presence="optional" description="Presence is optional if the MDEntryType is 'Empty' for example."/>
        <field name="NumberOfOrders" id="346"  type="int16" description="Number of orders at this level, if available."/>
        <field name="Flags" id="20021" type="Flags" sinceVersion="1" description="Contains lastMDEntryInGroup which indicates if this message is the last in the update group."/>
        <group name="MDComponentGroup" id="20009" description="Additional optional information about this MDEntry.  If not present, will be an empty group." dimensionType="groupSizeEncoding">
            <field name="MDComponentID" id="20010" type="uint16" semanticType="TagNum" description="ID for this component. For example, a value of 67 might identify this MDComponent as holding a QuoteID."/>
            <field name="MDComponentType" id="20011" type="MDComponentType" semanticType="int"/>
            <field name="MDComponentValue" id="20012" type="MDComponentValue"/>
        </group>
    </sbe:message>
    <sbe:message name="MDEntry" id="1"
                 description="Part of a Market data update group and, if necessary, will always come after a MarketDataIncrementalRefresh message.
                 Contains the details for an atomic change to the quote book."
                 semanticType="X">
        <field name="VenueID" id="20022" type="VenueID"/>
        <field name="SecurityID"     id="48"   type="SecurityID"/>
        <field name="RptSeq"         id="83"   type="SeqNum" description="SeqNum used to detect packet loss for a particular SecurityID in a UDP (unicast or multicast) stream."/>
        <field name="MDEntryType"    id="269"  type="MDEntryType" presence="optional"/>
        <field name="MDEntryPx"      id="270"  type="PriceNULL" description="Price (in mantissa format)."/>
        <field name="MDEntrySize"    id="271"  type="DecimalQtyNULL" description="Size (in mantissa format)."/>
        <field name="MinQty"         id="110"  type="DecimalQtyNULL" description="Minimum quantity available to execute (in mantissa format)."/>
        <field name="MDUpdateAction" id="279"  type="MDUpdateAction" presence="optional" description="Presence is optional if the MDEntryType is 'Empty' for example."/>
        <field name="MDBookType"     id="1021" type="MDBookType" presence="optional" description="Presence is optional if the MDEntryType is 'Empty' for example."/>
        <field name="NumberOfOrders" id="346"  type="int16"/>
        <field name="Flags" id="20021" type="Flags" sinceVersion="1" description="Contains lastMDEntryInGroup which indicates if this message is the last in the update group."/>
        <group name="MDComponentGroup" id="20009" description="Additional optional information about this MDEntry.  If not present, will be an empty group." dimensionType="groupSizeEncoding">
            <field name="MDComponentID" id="20010" type="uint16" semanticType="TagNum" description="ID for this component. For example, a value of 67 might identify this MDComponent as holding a QuoteID."/>
            <field name="MDComponentType" id="20011" type="MDComponentType" semanticType="int"/>
            <field name="MDComponentValue" id="20012" type="MDComponentValue"/>
        </group>
    </sbe:message>
    <!-- Batching messages -->
    <sbe:message name="RegisterForBatch" id="12" description="Register for an EBS-Ai batch.">
        <field name="VenueID" id="20022" type="VenueID" semanticType="int"/>
        <field name="BatchDefinitionID" id="20013" type="uint64" description="Batch creator's identifier for this batch. Necessary to later cancel or identify batch updates."/>
        <group name="NoSecurityIDs" id="20014" description="List of security IDs to batch.">
            <field name="SecurityID"  id="48" type="SecurityID"/>
        </group>
    </sbe:message>
    <sbe:message name="UnregisterForBatch" id="13" description="Unregister for an EBS-Ai batch.">
        <field name="VenueID" id="20022" type="VenueID" semanticType="int"/>
        <field name="BatchDefinitionID" id="20015" type="uint64" description="ID provided during the batch creation using the RegisterForBatch message."/>
    </sbe:message>
    <sbe:message name="BatchesCompleted" id="14" description="Message sent when an EBS-Ai batch of market data updates is done.">
        <field name="VenueID" id="20022" type="VenueID" semanticType="int"/>
        <group name="BatchGroup" id="20016" description="A list of batches that are done processing." dimensionType="groupSizeEncoding">
            <field name="BatchDefinitionID" id="20017" type="uint64" description="ID provided during the batch creation using the RegisterForBatch message."/>
        </group>
    </sbe:message>

    <!-- Historic Tick Streamer Related messages-->
    <sbe:message name="MarketDataRequestHistoric" id="15" description="A request to stream historic market data" semanticType="V" sinceVersion="2">
    <field name="SubscriptionRequestType"  id="263" type="SubscriptionRequestType"/>
    <field name="StartTimestamp" id="20045" type="Timestamp" description="Required when subscribing, Nanoseconds"/>
    <field name="EndTimestamp" id="20046" type="Timestamp" description="Required when subscribing, Nanoseconds"/>
    <group name="NoRelatedSym" id="20047" description="Venue and security pair to subscribe to. At least 1 pair is required." dimensionType="groupSizeEncoding">
        <field name="VenueID" id="20022" type="VenueID" semanticType="int"/>
        <field name="SecurityID"  id="48" description="Use 0 to subscribe or unsubscribe to all securities from the venue" type="SecurityID"/>
    </group>
    </sbe:message>

</sbe:messageSchema>
