예제 #1
0
        /// <summary>
        /// Copy the values from the data model.
        /// </summary>
        /// <param name="workingOrderRow">The data model row that is the source of the data.</param>
        public override void Copy(DataModel.WorkingOrderRow workingOrderRow)
        {
            // Validate the parameters.
            if (workingOrderRow == null)
            {
                throw new ArgumentNullException("workingOrderRow");
            }

            // Allow the base class to copy the core of the working order.
            base.Copy(workingOrderRow);

            // Copy the scalar that are specific to the Equity instruments directly from the data model.
            this.IsCrossing         = workingOrderRow.CrossingRow.CrossingCode == CrossingCode.AlwaysMatch;
            this.IsBrokerMatch      = workingOrderRow.IsBrokerMatch;
            this.IsHedgeMatch       = workingOrderRow.IsHedgeMatch;
            this.IsInstitutionMatch = workingOrderRow.IsInstitutionMatch;
            this.LimitPrice         = workingOrderRow.IsLimitPriceNull() ? 0.0M : workingOrderRow.LimitPrice;
            this.OrderTypeMnemonic  = workingOrderRow.OrderTypeRow.Mnemonic;
            this.OrderTypeCode      = workingOrderRow.OrderTypeRow.OrderTypeCode;
            this.StopPrice          = workingOrderRow.IsStopPriceNull() ? 0.0M : workingOrderRow.StopPrice;
            this.TimeInForceCode    = workingOrderRow.TimeInForceRow.TimeInForceCode;
        }
예제 #2
0
        /// <summary>
        /// Create an debt working order.
        /// </summary>
        void CreateDebt()
        {
            // All orders get a unique identifier.
            Guid workingOrderId = Guid.NewGuid();

            // These records provide the starting point for generating the orders.
            DataModel.BlotterRow blotterRow      = DataModel.Blotter.BlotterKey.Find(generatorInfo.BlotterId);
            DataModel.UserRow    userRow         = DataModel.User.UserKey.Find(generatorInfo.UserId);
            DataModel.CountryRow unitedStatesRow = DataModel.Country.CountryKeyExternalId0.Find("US");
            DataModel.StatusRow  statusRow       = DataModel.Status.StatusKey.Find(StatusCode.New);

            // Generate the settlement currency
            DataModel.EntityRow   usdEntityRow          = DataModel.Entity.EntityKeyExternalId0.Find("USD");
            DataModel.SecurityRow settlementCurrencyRow = DataModel.Security.SecurityKey.Find(usdEntityRow.EntityId);

            // The orders are an even mix of Buys and Sells.  Most positions are long.
            Boolean  isBuy    = random.Next(2) == 0;
            Boolean  isLong   = random.Next(4) != 0;
            SideCode sideCode = isBuy && isLong ? SideCode.Buy : !isBuy && isLong ? SideCode.Sell : isBuy && !isLong ? SideCode.BuyCover : SideCode.SellShort;

            DataModel.SideRow sideRow = DataModel.Side.SideKey.Find(sideCode);

            // Find a random debt position that is unique to this blotter.
            DataModel.SecurityRow securityRow = null;
            while (securityRow == null)
            {
                // Select a random debt instrument for the next order.
                DataModel.DebtRow debtRow = DataModel.Debt[random.Next(DataModel.Debt.Count - 1)];

                // Only generate orders for positions that are unique to this blotter.
                Position position = new Position(debtRow.DebtId, sideCode);
                if (!positionSet.Contains(position))
                {
                    securityRow = debtRow.SecurityRowByFK_Security_Debt_DebtId;
                    positionSet.Add(position);
                }
            }

            // These orders will not match by default.  We need to turn them on manually.
            DataModel.CrossingRow crossingRow = DataModel.Crossing.CrossingKey.Find(CrossingCode.NeverMatch);

            // Select a random Time In Force for this order.  Most orders are Day orders but occationally we'll generate a GTC just to keep it interesting.
            TimeInForceCode timeInForce = random.Next(4) == 0 ? TimeInForceCode.GoodTillCancel : TimeInForceCode.Day;

            DataModel.TimeInForceRow timeInForceRow = DataModel.TimeInForce.TimeInForceKey.Find(timeInForce);

            // Generate the trade and settlement dates based on the current time and make sure it doesn't fall on a weekend.
            DateTime tradeDate      = DateTime.Now;
            DateTime settlementDate = DateTime.Now;
            TimeSpan oneDay         = TimeSpan.FromDays(1.0);

            for (Int32 dayIndex = 0; dayIndex < 3; dayIndex++)
            {
                settlementDate += oneDay;
                if (settlementDate.DayOfWeek == DayOfWeek.Saturday)
                {
                    settlementDate += oneDay;
                }
                if (settlementDate.DayOfWeek == DayOfWeek.Sunday)
                {
                    settlementDate += oneDay;
                }
            }

            // This will generate random matching preferences for the orders for demonstrating the matching box capabilities.
            Boolean isBrokerMatch      = random.Next(20) == 0;
            Boolean isHedgeMatch       = random.Next(15) == 0;
            Boolean isInstitutionMatch = true;

            // This randomizes the random matching patterns.  Every now and then, don't match with anyone.
            if (random.Next(5) == 0)
            {
                isBrokerMatch      = false;
                isHedgeMatch       = false;
                isInstitutionMatch = false;
            }

            //  <transaction>
            XElement elementTransaction = new XElement("transaction");

            this.xDocument.Root.Add(elementTransaction);

            //    <method name="StoreWorkingOrder">
            XElement elementWorkingOrder = new XElement("method", new XAttribute("name", "StoreWorkingOrder"));

            elementTransaction.Add(elementWorkingOrder);

            //      <parameter name="blotterKey" value="EMERGING MARKETS BLOTTER" />
            elementWorkingOrder.Add(
                new XElement("parameter",
                             new XAttribute("name", "blotterKey"),
                             new XAttribute("value", blotterRow.EntityRow.ExternalId0)));

            //      <parameter name="configurationId" value="US TICKER" />
            elementWorkingOrder.Add(new XElement("parameter", new XAttribute("name", "configurationId"), new XAttribute("value", "CUSIP")));

            //      <parameter name="createdTime" value="5/6/2012 5:27:56 PM" />
            elementWorkingOrder.Add(new XElement("parameter", new XAttribute("name", "createdTime"), new XAttribute("value", DateTime.Now.ToString("G"))));

            //      <parameter name="crossingKey" value="NEVER MATCH" />
            elementWorkingOrder.Add(new XElement("parameter", new XAttribute("name", "crossingKey"), new XAttribute("value", crossingRow.ExternalId0)));

            //      <parameter name="externalId0" value="{bab88942-5c4e-440a-a352-c8e9b00fec12}" />
            elementWorkingOrder.Add(new XElement("parameter", new XAttribute("name", "externalId0"), new XAttribute("value", workingOrderId.ToString("B"))));

            //      <parameter name="isBrokerMatch" value="false" />
            elementWorkingOrder.Add(new XElement("parameter", new XAttribute("name", "isBrokerMatch"), new XAttribute("value", isBrokerMatch)));

            //      <parameter name="isHedgeMatch" value="false" />
            elementWorkingOrder.Add(new XElement("parameter", new XAttribute("name", "isHedgeMatch"), new XAttribute("value", isHedgeMatch)));

            //      <parameter name="isInstitutionMatch" value="true" />
            elementWorkingOrder.Add(new XElement("parameter", new XAttribute("name", "isInstitutionMatch"), new XAttribute("value", isInstitutionMatch)));

            //      <parameter name="modifiedTime" value="5/6/2012 5:27:56 PM" />
            elementWorkingOrder.Add(new XElement("parameter", new XAttribute("name", "modifiedTime"), new XAttribute("value", DateTime.Now.ToString("G"))));

            //      <parameter name="orderTypeKey" value="MKT" />
            elementWorkingOrder.Add(new XElement("parameter", new XAttribute("name", "orderTypeKey"), new XAttribute("value", "MKT")));

            //      <parameter name="securityKeyBySecurityId" value="ODP" />
            elementWorkingOrder.Add(
                new XElement("parameter",
                             new XAttribute("name", "securityKeyBySecurityId"),
                             new XAttribute("value", securityRow.EntityRow.ExternalId4)));

            //      <parameter name="securityKeyBySettlementId" value="USD" />
            elementWorkingOrder.Add(
                new XElement("parameter",
                             new XAttribute("name", "securityKeyBySettlementId"),
                             new XAttribute("value", settlementCurrencyRow.EntityRow.ExternalId0)));

            //      <parameter name="settlementDate" value="5/9/2012 5:27:56 PM" />
            elementWorkingOrder.Add(new XElement("parameter", new XAttribute("name", "settlementDate"), new XAttribute("value", settlementDate.ToString("G"))));

            //      <parameter name="sideKey" value="SELL" />
            elementWorkingOrder.Add(new XElement("parameter", new XAttribute("name", "sideKey"), new XAttribute("value", sideRow.ExternalId0)));

            //      <parameter name="statusKey" value="NEW" />
            elementWorkingOrder.Add(new XElement("parameter", new XAttribute("name", "statusKey"), new XAttribute("value", statusRow.ExternalId0)));

            //      <parameter name="timeInForceKey" value="DAY" />
            elementWorkingOrder.Add(new XElement("parameter", new XAttribute("name", "timeInForceKey"), new XAttribute("value", timeInForceRow.ExternalId0)));

            //      <parameter name="tradeDate" value="5/6/2012 5:27:56 PM" />
            elementWorkingOrder.Add(new XElement("parameter", new XAttribute("name", "tradeDate"), new XAttribute("value", tradeDate.ToString("G"))));

            //      <parameter name="userKeyByCreatedUserId" value="DEV KAPOOR" />
            elementWorkingOrder.Add(
                new XElement("parameter",
                             new XAttribute("name", "userKeyByCreatedUserId"),
                             new XAttribute("value", userRow.EntityRow.ExternalId0)));

            //      <parameter name="userKeyByModifiedUserId" value="DEV KAPOOR" />
            elementWorkingOrder.Add(
                new XElement("parameter",
                             new XAttribute("name", "userKeyByModifiedUserId"),
                             new XAttribute("value", userRow.EntityRow.ExternalId0)));

            // This will generate between one and three source orders for the working order.  Source orders are a blocking concept.  You can get several orders for
            // the same security on the same side for the same price.  When this happens, it is much more efficient to block them as a single order and execute them
            // as a single order and allocate them back to the original orders when the order is done.
            Int32 sourceOrderCount = random.Next(1, 3);

            for (Int32 sourceOrderIndex = 0; sourceOrderIndex < sourceOrderCount; sourceOrderIndex++)
            {
                // This creates a unique identifier for the source order.
                Guid sourceOrderId = Guid.NewGuid();

                // This generates a random quantity for the order between 100 and 10,000 shares.
                Decimal orderedQuantity = Convert.ToDecimal(random.Next(1, 100)) * 100.0M;

                //    <method name="StoreSourceOrder">
                XElement elementSourceOrder = new XElement("method", new XAttribute("name", "StoreSourceOrder"));
                elementTransaction.Add(elementSourceOrder);

                //      <parameter name="configurationId" value="US TICKER" />
                elementSourceOrder.Add(new XElement("parameter", new XAttribute("name", "configurationId"), new XAttribute("value", "CUSIP")));

                //      <parameter name="createdTime" value="2012-05-06T17:27:56.2658093-04:00" />
                elementSourceOrder.Add(new XElement("parameter", new XAttribute("name", "createdTime"), new XAttribute("value", DateTime.Now)));

                //      <parameter name="externalId0" value="{3c69e0a0-3316-4499-a7b1-6dda5a058837}" />
                elementSourceOrder.Add(new XElement("parameter", new XAttribute("name", "externalId0"), new XAttribute("value", sourceOrderId.ToString("B"))));

                //      <parameter name="modifiedTime" value="5/6/2012 5:27:56 PM" />
                elementSourceOrder.Add(new XElement("parameter", new XAttribute("name", "modifiedTime"), new XAttribute("value", DateTime.Now.ToString("G"))));

                //      <parameter name="orderedQuantity" value="4300.0" />
                elementSourceOrder.Add(new XElement("parameter", new XAttribute("name", "orderedQuantity"), new XAttribute("value", orderedQuantity)));

                //      <parameter name="orderTypeKey" value="MKT" />
                elementSourceOrder.Add(new XElement("parameter", new XAttribute("name", "orderTypeKey"), new XAttribute("value", "MKT")));

                //      <parameter name="securityKeyBySecurityId" value="ODP" />
                elementSourceOrder.Add(
                    new XElement("parameter",
                                 new XAttribute("name", "securityKeyBySecurityId"),
                                 new XAttribute("value", securityRow.EntityRow.ExternalId4)));

                //      <parameter name="securityKeyBySettlementId" value="USD" />
                elementSourceOrder.Add(
                    new XElement("parameter",
                                 new XAttribute("name", "securityKeyBySettlementId"),
                                 new XAttribute("value", settlementCurrencyRow.EntityRow.ExternalId0)));

                //      <parameter name="settlementDate" value="2012-05-09T17:27:56.2528086-04:00" />
                elementSourceOrder.Add(new XElement("parameter", new XAttribute("name", "settlementDate"), new XAttribute("value", settlementDate)));

                //      <parameter name="sideKey" value="SELL" />
                elementSourceOrder.Add(new XElement("parameter", new XAttribute("name", "sideKey"), new XAttribute("value", sideRow.ExternalId0)));

                //      <parameter name="statusKey" value="NEW" />
                elementSourceOrder.Add(new XElement("parameter", new XAttribute("name", "statusKey"), new XAttribute("value", statusRow.ExternalId0)));

                //      <parameter name="timeInForceKey" value="DAY" />
                elementSourceOrder.Add(
                    new XElement("parameter",
                                 new XAttribute("name", "timeInForceKey"),
                                 new XAttribute("value", timeInForceRow.ExternalId0)));

                //      <parameter name="tradeDate" value="5/6/2012 5:27:56 PM" />
                elementSourceOrder.Add(new XElement("parameter", new XAttribute("name", "tradeDate"), new XAttribute("value", tradeDate.ToString("G"))));

                //      <parameter name="userKeyByCreatedUserId" value="DEV KAPOOR" />
                elementSourceOrder.Add(
                    new XElement("parameter",
                                 new XAttribute("name", "userKeyByCreatedUserId"),
                                 new XAttribute("value", userRow.EntityRow.ExternalId0)));

                //      <parameter name="userKeyByModifiedUserId" value="DEV KAPOOR" />
                elementSourceOrder.Add(
                    new XElement("parameter",
                                 new XAttribute("name", "userKeyByModifiedUserId"),
                                 new XAttribute("value", userRow.EntityRow.ExternalId0)));

                //      <parameter name="workingOrderKey" value="{bab88942-5c4e-440a-a352-c8e9b00fec12}" />
                elementSourceOrder.Add(
                    new XElement("parameter",
                                 new XAttribute("name", "workingOrderKey"),
                                 new XAttribute("value", workingOrderId.ToString("B"))));
            }
        }
예제 #3
0
 /// <summary>
 /// Gets an internal database identifier based on the Enumerated value.
 /// </summary>
 /// <param name="key">The strongly typed enumerated value.</param>
 /// <returns>The equivalent record identifier from the database.</returns>
 public static Guid FromCode(TimeInForceCode key)
 {
     return(TimeInForceMap.enumDictionary[key]);
 }
예제 #4
0
 /// <summary>
 /// Converts a TimeInForce to a string.
 /// </summary>
 /// <returns>A TimeInForce value.</returns>
 /// <param name="value">The FIX string representation of a TimeInForce.</param>
 public static string ConvertTo(TimeInForceCode messageType)
 {
     return((string)TimeInForceConverter.toTable[messageType]);
 }