/// <summary> /// Copies the values from the data model into the SideItem instance. /// </summary> /// <param name="sideRow">The source of the data.</param> internal void Copy(DataModel.SideRow sideRow) { // Copy the members from the data model. this.Description = sideRow.Description; this.Mnemonic = sideRow.Mnemonic; this.SideCode = sideRow.SideCode; this.SortOrder = sideRow.SortOrder; // This will disassemble the icon and give us the basic image sizes supported by the application framework. Dictionary <ImageSize, ImageSource> images = ImageHelper.DecodeIcon(Convert.FromBase64String(sideRow.Image)); this.SmallImageSource = images[ImageSize.Small]; this.MediumImageSource = images[ImageSize.Medium]; this.LargeImageSource = images[ImageSize.Large]; this.ExtraLargeImageSource = images[ImageSize.ExtraLarge]; }
/// <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")))); } }
internal SideItem(DataModel.SideRow sideRow) { // This will populate the new item with information from the data model. this.Copy(sideRow); }