<?xml version="1.0" encoding="utf-8"?>

<Strategy xmlns="http://www.fixprotocol.org/FIXatdl-1-1/Core"
    xmlns:val="http://www.fixprotocol.org/FIXatdl-1-1/Validation"
    xmlns:lay="http://www.fixprotocol.org/FIXatdl-1-1/Layout"
    xmlns:flow="http://www.fixprotocol.org/FIXatdl-1-1/Flow"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.fixprotocol.org/FIXatdl-1-1/Core tt-fixatdl-core-1-1.xsd"
    name="TT_TWAP" uiRep="TT TWAP" version="15.178.6" providerID="TT" entryFile="algo.so">

    <HideFromUIComponents>
        <UIComponent>Dashboard</UIComponent>
    </HideFromUIComponents>

    <Parameter name="__instr_id"
               xsi:type="String_t"
               refValue="OrderInstrumentID"
               required="true" dir="In" updateable="false"/>

    <Parameter name="__order_quantity"
               xsi:type="Qty_t"
               refValue="OrderQty"
               required="true" dir="In" updateable="true"/>

    <Parameter name="__price"
               xsi:type="Price_t"
               refValue="OrderPrice"
               required="true" dir="In" updateable="true"/>

    <Parameter name="__side"
               xsi:type="Int_t"
               refValue="OrderSide"
               required="true" dir="In" updateable="false"/>

    <Parameter name="__account"
               xsi:type="String_t"
               refValue="OrderAccount"
               required="true" dir="In" updateable="false"/>

    <Parameter name="ChildTIF"
               xsi:type="Int_t"
               refValue="OrderTif"
               required="true" dir="In" updateable="false" orderEntryFixtag="16903"/>

    <!-- For now, hardcode parent to GTC -->
    <Parameter name="__tif" xsi:type="Int_t" constValue="2" required="true" dir="In" updateable="false"/>

    <!-- Market or Limit -->
    <Parameter name="__type"
               xsi:type="Int_t"
               initValue="eLimit"
               required="true" dir="In" updateable="false">
        <EnumPair enumID="eMkt" wireValue="1"/>
        <EnumPair enumID="eLimit" wireValue="2"/>
    </Parameter>

    <!-- Time Slicing Details -->

    <!-- interval (on the wire always in ms) -->
    <Parameter name="Interval"
               xsi:type="Int_t"
               initValue="5" minValue="1"
               required="false" dir="In" updateable="false" orderEntryFixtag="16907"/>

    <!-- display qty -->
    <Parameter name="DiscVal"
               xsi:type="Qty_t"
               initValue="1" minValue="0.00000001"
               required="false" dir="In" updateable="true" orderEntryFixtag="16904"/>

    <Parameter name="DiscValType"
               xsi:type="Int_t"
               initValue="eQty"
               required="false" dir="In" updateable="false" orderEntryFixtag="16905">
        <EnumPair enumID="eQty" wireValue="1"/>
        <EnumPair enumID="ePercent" wireValue="2"/>
    </Parameter>

    <!-- duration -->
    <Parameter name="Duration"
               xsi:type="Int_t"
               initValue="1" minValue="1"
               required="false" dir="In"
               updateable="true"
               orderEntryFixtag="16944"/>

    <Parameter name="DurationBaseUnit"
               xsi:type="Int_t"
               initValue="eHour"
               required="false" dir="In"
               updateable="true"
               orderEntryFixtag="16945">
        <EnumPair enumID="eHour" wireValue="1"/>
        <EnumPair enumID="eMinute" wireValue="2"/>
        <EnumPair enumID="eSecond" wireValue="3"/>
    </Parameter>

    <Parameter name="DurationSTime"
               xsi:type="UTCTimestamp_t"
               required="false" dir="In"
               updateable="true"
               orderEntryFixtag="16946"/>

    <Parameter name="DurationETime"
               xsi:type="UTCTimestamp_t"
               required="false" dir="In"
               updateable="true"
               orderEntryFixtag="16947"/>

    <!-- Variance -->
    <Parameter name="Variance"
               xsi:type="Int_t"
               initValue="0" minValue="0" maxValue="100"
               required="false" dir="In" updateable="false" orderEntryFixtag="16958"/>

    <!-- Custom Slice Schedule -->
    <Parameter name="CustomSliceSched"
               xsi:type="String_t"
               initValue=""
               required="false" dir="In" updateable="true"/>

    <!-- Max Participation Rate -->
    <Parameter name="MaxPart"
               xsi:type="Int_t"
               initValue="10" minValue="1" maxValue="100"
               required="required" dir="In" updateable="true"  orderEntryFixtag="17006"/>

    <!-- Max Display -->
    <Parameter name="MaxDisp"
               xsi:type="Int_t"
               initValue="10" minValue="1" maxValue="100"
               required="required" dir="In" updateable="true"  orderEntryFixtag="17007"/>

    <!--Would If Prc-->
    <Parameter name="WouldIfPrc"
               xsi:type="Price_t"
               required="false" dir="In" updateable="true" orderEntryFixtag="17009"/>

    <!--Limit Prc-->
    <Parameter name="LimitPrc"
               xsi:type="Price_t"
               required="false" dir="In" updateable="true" orderEntryFixtag="17010"/>

    <!-- Date and Time -->
    <Parameter name="STime"
               xsi:type="UTCTimestamp_t"
               required="false" dir="In" updateable="true" orderEntryFixtag="168"/>

    <Parameter name="ETime"
               xsi:type="UTCTimestamp_t"
               required="false" dir="In" updateable="true" orderEntryFixtag="126"/>

    <Parameter name="TwapStyle" xsi:type="Int_t" initValue="eDefault" required="true" dir="In" updateable="true" orderEntryFixtag="17008">
        <EnumPair enumID="eAggressive"        wireValue="0"/>
        <EnumPair enumID="eDefault"           wireValue="1"/>
        <EnumPair enumID="ePassive"           wireValue="2"/>
    </Parameter>

    <lay:StrategyLayout>
        <!-- TWAP details -->
        <lay:StrategyPanel class="main-panel">
            <lay:Control ID="TWAP_lbl" xsi:type="lay:Label_t" label="Details" class="atdl-panel-title"/>

            <!-- Duration Type (Duration/StartEnd) -->
            <lay:StrategyPanel>
                <lay:StrategyPanel orientation="HORIZONTAL">
                    <lay:Control ID="DurationType_lbl"
                                 xsi:type="lay:Label_t"
                                 label="Duration Type"/>

                    <lay:Control ID="DurationType_ctrl"
                                 xsi:type="lay:DropDownList_t"
                                 initValue="eDuration">
                        <lay:ListItem enumID="eDuration" uiRep="Duration"/>
                        <lay:ListItem enumID="eStartEnd" uiRep="StartEnd"/>
                    </lay:Control>
                </lay:StrategyPanel>

                <!-- Duration -->
                <lay:StrategyPanel name="DurationPanel">
                    <flow:StateRule visible="true">
                        <val:Edit field="DurationType_ctrl" operator="EQ" value="eDuration"/>
                    </flow:StateRule>

                    <lay:StrategyPanel orientation="HORIZONTAL">
                        <lay:Control ID="Duration_ctrl" parameterRef="Duration"
                                     xsi:type="lay:SingleSpinner_t"
                                     initValue="1"
                                     label="Duration"/>

                        <lay:Control ID="DurationBaseUnit_ctrl" parameterRef="DurationBaseUnit"
                                     xsi:type="lay:DropDownList_t"
                                     initValue="eHour">
                            <lay:ListItem enumID="eHour" uiRep="hr"/>
                            <lay:ListItem enumID="eMinute" uiRep="min"/>
                            <lay:ListItem enumID="eSecond" uiRep="sec"/>
                        </lay:Control>
                    </lay:StrategyPanel>
                </lay:StrategyPanel>

                <!-- StartEnd Duration -->
                <lay:StrategyPanel name="DurationStartEndPanel">
                    <flow:StateRule visible="true">
                        <val:Edit field="DurationType_ctrl" operator="EQ" value="eStartEnd"/>
                    </flow:StateRule>

                    <lay:StrategyPanel orientation="HORIZONTAL">
                        <lay:Control ID="DurationStartTime_lbl"
                                     xsi:type="lay:Label_t"
                                     label="Start"/>

                        <lay:StrategyPanel name="HiddenDurationStartTimePanel">
                            <flow:StateRule visible="false">
                                <val:Edit logicOperator="AND"/>
                            </flow:StateRule>
                            <lay:Control ID="HiddenDurationStartTime_ctrl"
                                         xsi:type="lay:HiddenField_t"/>
                        </lay:StrategyPanel>

                        <lay:Control ID="DurationStartType_ctrl"
                                     xsi:type="lay:DropDownList_t"
                                     initValue="eNow">
                            <lay:ListItem enumID="eNow" uiRep="Now"/>
                            <lay:ListItem enumID="eTime" uiRep="Time"/>
                        </lay:Control>

                        <lay:Control ID="DurationStartTime_ctrl" parameterRef="DurationSTime"
                                     xsi:type="lay:Clock_t"
                                     initValueMode="1">
                            <flow:StateRule visible="true">
                                <val:Edit field="DurationStartType_ctrl" operator="EQ" value="eTime"/>
                            </flow:StateRule>
                        </lay:Control>
                    </lay:StrategyPanel>

                    <lay:StrategyPanel orientation="HORIZONTAL">
                        <lay:Control ID="DurationEndTime_lbl"
                                     xsi:type="lay:Label_t"
                                     label="End"/>

                        <lay:Control ID="DurationEndTime_ctrl" parameterRef="DurationETime"
                                     xsi:type="lay:Clock_t"
                                     initValueMode="1"/>
                    </lay:StrategyPanel>
                </lay:StrategyPanel>
            </lay:StrategyPanel>
            <!-- Max Display -->
            <lay:StrategyPanel name="MaxDisplayPanel" orientation="HORIZONTAL">
                <lay:Control ID="MaxDisplay_lbl"
                             xsi:type="lay:Label_t"
                             label="Max Display"/>

                <lay:Control ID="MaxDisplay_ctrl" parameterRef="MaxDisp"
                             xsi:type="lay:SingleSpinner_t">
                </lay:Control>
                <lay:Control ID="MaxDisplay_pct_lbl"
                             xsi:type="lay:Label_t"
                             label="%"/>
            </lay:StrategyPanel>
            <!-- TWAP Style -->
            <lay:StrategyPanel name="TwapStylePanel" orientation="HORIZONTAL">
                <lay:Control ID="TwapStyle_ctrl" parameterRef="TwapStyle"
                             xsi:type="lay:DropDownList_t"
                             initValue="eDefault" label="Style">
                    <lay:ListItem enumID="eAggressive" uiRep="Aggressive"/>
                    <lay:ListItem enumID="eDefault" uiRep="Default"/>
                    <lay:ListItem enumID="ePassive" uiRep="Passive"/>
                </lay:Control>
            </lay:StrategyPanel>
            <!-- Would If Price -->
            <lay:StrategyPanel name="WouldIfPanel" orientation="HORIZONTAL">
                <lay:Control ID="WouldIf_check"
                             xsi:type="lay:CheckBox_t"
                             initValue="false"
                             label="Would If Prc"/>

                <lay:Control ID="WouldIf_ctrl" parameterRef="WouldIfPrc"
                    xsi:type="lay:SingleSpinner_t">
                    <flow:StateRule enabled="true">
                        <val:Edit field="WouldIf_check" operator="EQ" value="true"/>
                    </flow:StateRule>
                </lay:Control>
            </lay:StrategyPanel>
            <!-- Limit Price -->
            <lay:StrategyPanel name="LimitPricePanel" orientation="HORIZONTAL">
                <flow:StateRule visible="true">
                    <val:Edit logicOperator="OR">
                        <val:Edit field="TwapStyle_ctrl" operator="EQ" value="eAggressive"/>
                        <val:Edit field="TwapStyle_ctrl" operator="EQ" value="eDefault"/>
                        <val:Edit field="TwapStyle_ctrl" operator="EQ" value="ePassive"/>
                    </val:Edit>
                </flow:StateRule>
                <lay:Control ID="LimitPrice_check"
                             xsi:type="lay:CheckBox_t"
                             initValue="false"
                             label="Limit Price"/>

                <lay:Control ID="LimitPrice_ctrl" parameterRef="LimitPrc"
                    xsi:type="lay:SingleSpinner_t">
                    <flow:StateRule enabled="true">
                        <val:Edit field="LimitPrice_check" operator="EQ" value="true"/>
                    </flow:StateRule>
                </lay:Control>
            </lay:StrategyPanel>
        </lay:StrategyPanel>
    </lay:StrategyLayout>

    <val:StrategyEdit errorMessage="Display quantity must be greater than 0">
        <val:Edit logicOperator="OR">
            <val:Edit logicOperator="AND">
                <val:Edit field="DiscValType" operator="EQ" value="1"/>
                <val:Edit field="DiscVal" operator="NE" value=""/>
                <val:Edit field="DiscVal" operator="GE" value="1"/>
            </val:Edit>
            <val:Edit field="DiscValType" operator="EQ" value=""/>
            <val:Edit field="DiscValType" operator="EQ" value="2"/>
        </val:Edit>
    </val:StrategyEdit>

    <val:StrategyEdit errorMessage="Display percentage must be between 1 and 99">
        <val:Edit logicOperator="OR">
            <val:Edit logicOperator="AND">
                <val:Edit field="DiscValType" operator="EQ" value="2"/>
                <val:Edit field="DiscVal" operator="GE" value="1"/>
                <val:Edit field="DiscVal" operator="LE" value="99"/>
            </val:Edit>
            <val:Edit field="DiscValType" operator="EQ" value=""/>
            <val:Edit field="DiscValType" operator="EQ" value="1"/>
        </val:Edit>
    </val:StrategyEdit>

    <val:StrategyEdit errorMessage="Duration (hour) must be between 1 and 99">
        <val:Edit logicOperator="OR">
            <val:Edit logicOperator="AND">
                <val:Edit field="DurationBaseUnit" operator="EQ" value="1"/>
                <val:Edit field="Duration" operator="GE" value="1"/>
                <val:Edit field="Duration" operator="LE" value="99"/>
            </val:Edit>
            <val:Edit field="DurationBaseUnit" operator="NE" value="1"/>
        </val:Edit>
    </val:StrategyEdit>

    <val:StrategyEdit errorMessage="Duration (minute) must be between 1 and 9999">
        <val:Edit logicOperator="OR">
            <val:Edit logicOperator="AND">
                <val:Edit field="DurationBaseUnit" operator="EQ" value="2"/>
                <val:Edit field="Duration" operator="GE" value="1"/>
                <val:Edit field="Duration" operator="LE" value="9999"/>
            </val:Edit>
            <val:Edit field="DurationBaseUnit" operator="NE" value="2"/>
        </val:Edit>
    </val:StrategyEdit>

    <val:StrategyEdit errorMessage="Duration (second) must be between 1 and 9999">
        <val:Edit logicOperator="OR">
            <val:Edit logicOperator="AND">
                <val:Edit field="DurationBaseUnit" operator="EQ" value="3"/>
                <val:Edit field="Duration" operator="GE" value="1"/>
                <val:Edit field="Duration" operator="LE" value="9999"/>
            </val:Edit>
            <val:Edit field="DurationBaseUnit" operator="NE" value="3"/>
        </val:Edit>
    </val:StrategyEdit>

    <val:StrategyEdit errorMessage="Duration Start Time must precede Duration End Time.">
        <val:Edit logicOperator="OR">
            <val:Edit field="DurationSTime" operator="EQ" value=""/>
            <val:Edit field="DurationETime" operator="EQ" value=""/>
            <val:Edit field="DurationSTime" operator="LT" field2="DurationETime"/>
        </val:Edit>
    </val:StrategyEdit>

    <val:StrategyEdit errorMessage="Precondition Start Time must equal or precede Duration Start Time.">
        <val:Edit logicOperator="OR">
            <val:Edit field="DurationSTime" operator="EQ" value=""/>
            <val:Edit field="STime" operator="EQ" value=""/>
            <val:Edit field="STime" operator="LE" field2="DurationSTime"/>
        </val:Edit>
    </val:StrategyEdit>

    <val:StrategyEdit errorMessage="Variance percentage must be between 0 and 99">
        <val:Edit logicOperator="AND">
            <val:Edit field="Variance" operator="GE" value="0"/>
            <val:Edit field="Variance" operator="LE" value="99"/>
        </val:Edit>
    </val:StrategyEdit>

    <val:StrategyEdit errorMessage="Start Time must precede End Time.">
        <val:Edit logicOperator="OR">
            <val:Edit field="STime" operator="EQ" value=""/>
            <val:Edit field="ETime" operator="EQ" value=""/>
            <val:Edit field="STime" operator="LT" field2="ETime"/>
        </val:Edit>
    </val:StrategyEdit>

</Strategy>
