예제 #1
0
        public MatchElement(MatchDocument matchDocument, ClientMarketData.MatchRow matchRow, FieldArray fields) :
            base("Match", matchDocument)
        {
            // WorkingOrderId
            AddAttribute("MatchId", matchRow.MatchId);
            AddAttribute("WorkingOrderId", matchRow.WorkingOrderId);
            AddAttribute("ContraOrderId", matchRow.ContraOrderId);

            // Status
            if (fields[Field.Status])
            {
                AddAttribute("StatusCode", matchRow.StatusCode);
                AddAttribute("StatusName", matchRow.StatusRow.Mnemonic);
                TimeSpan timeLeft = matchRow.TimerRow.StopTime.Subtract(matchRow.TimerRow.CurrentTime);
                AddAttribute("TimeLeft", string.Format("{0:0}:{1:00}", timeLeft.Minutes, timeLeft.Seconds));
                AddAttribute("SecondsLeft", Convert.ToInt32(timeLeft.TotalSeconds));
            }

            // Blotter
            if (fields[Field.Blotter])
            {
                AddAttribute("Blotter", matchRow.WorkingOrderRow.BlotterRow.BlotterId);
                AddAttribute("BlotterName", matchRow.WorkingOrderRow.BlotterRow.ObjectRow.Name);
            }

            // Security
            if (fields[Field.Security])
            {
                AddAttribute("SecurityId", matchRow.WorkingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.SecurityId);
                AddAttribute("SecuritySymbol", matchRow.WorkingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.Symbol);
                AddAttribute("SecurityName", matchRow.WorkingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.ObjectRow.Name);
                if (!matchRow.WorkingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.IsAverageDailyVolumeNull())
                {
                    AddAttribute("AverageDailyVolume", matchRow.WorkingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.AverageDailyVolume / 1000);
                }
                if (!matchRow.WorkingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.IsMarketCapitalizationNull())
                {
                    AddAttribute("MarketCapitalization", matchRow.WorkingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.MarketCapitalization / 1000000);
                }
                AddAttribute("VolumeCategoryMnemonic", matchRow.WorkingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.VolumeCategoryRow.Mnemonic);
                MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(matchRow.WorkingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.Logo));
                Bitmap       bitmap       = new Bitmap(memoryStream);
                Bitmap       halfBitmap   = new Bitmap(bitmap, new Size(bitmap.Width / 2, bitmap.Height / 2));
                MemoryStream halfStream   = new MemoryStream();
                halfBitmap.Save(halfStream, System.Drawing.Imaging.ImageFormat.Png);
                AddAttribute("SecurityImage", Convert.ToBase64String(halfStream.GetBuffer()));
            }

            // Submitted Quantity
            if (fields[Field.SubmittedQuantity])
            {
                AddAttribute("SubmittedQuantity", matchRow.WorkingOrderRow.SubmittedQuantity);
            }

            // Direction (OrderType)
            if (fields[Field.OrderTypeCode])
            {
                AddAttribute("OrderTypeCode", matchRow.WorkingOrderRow.OrderTypeCode);
                AddAttribute("OrderTypeMnemonic", matchRow.WorkingOrderRow.OrderTypeRow.Mnemonic);
            }


            // Find the pricing record.
            if (!matchRow.WorkingOrderRow.IsSettlementIdNull())
            {
                ClientMarketData.PriceRow priceRow = ClientMarketData.Price.FindBySecurityId(matchRow.WorkingOrderRow.SecurityId);
                if (priceRow != null)
                {
                    if (fields[Field.LastPrice])
                    {
                        AddAttribute("LastPrice", priceRow.LastPrice);
                    }
                    if (fields[Field.BidPrice])
                    {
                        AddAttribute("BidPrice", priceRow.BidPrice);
                    }
                    if (fields[Field.AskPrice])
                    {
                        AddAttribute("AskPrice", priceRow.AskPrice);
                    }
                    if (fields[Field.LastSize])
                    {
                        AddAttribute("LastSize", priceRow.LastSize);
                    }
                    if (fields[Field.BidSize])
                    {
                        AddAttribute("BidSize", priceRow.BidSize);
                    }
                    if (fields[Field.AskPrice])
                    {
                        AddAttribute("AskSize", priceRow.AskSize);
                    }
                    if (fields[Field.Volume])
                    {
                        AddAttribute("Volume", priceRow.Volume);
                    }
                    if (fields[Field.InterpolatedVolume])
                    {
                        AddAttribute("InterpolatedVolume", VolumeHelper.CurrentVolumePercentage(DateTime.Now,
                                                                                                matchRow.WorkingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.AverageDailyVolume,
                                                                                                priceRow.Volume));
                    }
                    if (fields[Field.VolumeWeightedAveragePrice])
                    {
                        AddAttribute("VolumeWeightedAveragePrice", priceRow.VolumeWeightedAveragePrice);
                    }
                }
            }
        }
예제 #2
0
        public WorkingOrderElement(WorkingOrderDocument workingOrderDocument, ClientMarketData.WorkingOrderRow workingOrderRow, FieldArray fields) :
            base("WorkingOrder", workingOrderDocument)
        {
            // Aggregate all the data related to this staged order.  This will work out the aggregates and distinct column
            // operations.
            if (fields[Field.SourceOrder] || fields[Field.DestinationOrder] || fields[Field.Execution] || fields[Field.Allocation])
            {
                AggregateFields(workingOrderRow);
            }

            // WorkingOrderId - Primary Key for this report.
            AddAttribute("WorkingOrderId", workingOrderRow.WorkingOrderId);

            // Status - Note that the status code is always provided to the DOM for color coding of the fields.
            AddAttribute("StatusCode", workingOrderRow.StatusCode);
            if (fields[Field.Status])
            {
                AddAttribute("StatusName", workingOrderRow.StatusRow.Mnemonic);
            }

            // Select a green flag for submitted records, a red flag for unsubmitted.
            int imageIndex = -1;

            switch (workingOrderRow.StatusCode)
            {
            case Status.Error:
                imageIndex = ClientMarketData.Image.KeyImageExternalId0.Find("Error Small");
                break;

            case Status.Submitted:
                imageIndex = ClientMarketData.Image.KeyImageExternalId0.Find("Flag Green Small");
                break;

            default:
                imageIndex = ClientMarketData.Image.KeyImageExternalId0.Find("Flag Red Small");
                break;
            }
            if (imageIndex != -1)
            {
                ClientMarketData.ImageRow imageRow =
                    (ClientMarketData.ImageRow)ClientMarketData.Image.KeyImageExternalId0[imageIndex].Row;
                AddAttribute("StatusImage", imageRow.Image);
            }

            // Blotter
            if (fields[Field.Blotter])
            {
                AddAttribute("Blotter", workingOrderRow.BlotterId);
                AddAttribute("BlotterName", workingOrderRow.BlotterRow.ObjectRow.Name);
            }

            // SubmissionTypeCode
            if (fields[Field.SubmissionTypeCode])
            {
                AddAttribute("SubmissionTypeCode", workingOrderRow.SubmissionTypeCode);
            }

            // IsBrokerMatch
            if (fields[Field.IsBrokerMatch])
            {
                AddAttribute("IsBrokerMatch", workingOrderRow.IsBrokerMatch);
            }

            // IsInstitutionMatch
            if (fields[Field.IsInstitutionMatch])
            {
                AddAttribute("IsInstitutionMatch", workingOrderRow.IsInstitutionMatch);
            }

            // IsHedgeMatch
            if (fields[Field.IsHedgeMatch])
            {
                AddAttribute("IsHedgeMatch", workingOrderRow.IsHedgeMatch);
            }


            // Auto-Execute - we always send the isAutomatic flag and the quantity
            if (fields[Field.AutoExecute])
            {
                AddAttribute("IsAutomatic", workingOrderRow.IsAutomatic);

                if (!workingOrderRow.IsAutomaticQuantityNull())
                {
                    AddAttribute("AutomaticQuantity", workingOrderRow.AutomaticQuantity);
                }
                else
                {
                    AddAttribute("AutomaticQuantity", 0);
                }
            }

            // LimitPrice
            if (fields[Field.LimitPrice])
            {
                if (!workingOrderRow.IsLimitPriceNull())
                {
                    AddAttribute("LimitPrice", workingOrderRow.LimitPrice);
                }
                else
                {
                    AddAttribute("LimitPrice", 0);
                }
            }

            // OrderType
            if (fields[Field.OrderType])
            {
                AddAttribute("OrderTypeCode", workingOrderRow.OrderTypeCode);
                AddAttribute("OrderTypeDescription", workingOrderRow.OrderTypeRow.Description);
                AddAttribute("OrderTypeMnemonic", workingOrderRow.OrderTypeRow.Mnemonic);
                AddAttribute("CashSign", workingOrderRow.OrderTypeRow.CashSign);
                AddAttribute("QuantitySign", workingOrderRow.OrderTypeRow.QuantitySign);

                // Select a green flag for submitted records, a red flag for unsubmitted.
                int orderTypeImageIndex = -1;
                switch (workingOrderRow.OrderTypeCode)
                {
                case OrderType.Buy:
                    orderTypeImageIndex = ClientMarketData.Image.KeyImageExternalId0.Find("Navigate Plain Green Small");
                    break;

                case OrderType.Sell:
                    orderTypeImageIndex = ClientMarketData.Image.KeyImageExternalId0.Find("Navigate Plain Red Small");
                    break;
                }
                if (orderTypeImageIndex != -1)
                {
                    ClientMarketData.ImageRow imageRow =
                        (ClientMarketData.ImageRow)ClientMarketData.Image.KeyImageExternalId0[orderTypeImageIndex].Row;
                    AddAttribute("OrderTypeImage", imageRow.Image);
                }
            }

            // TimeInForce
            if (fields[Field.TimeInForce])
            {
                AddAttribute("TimeInForceCode", workingOrderRow.TimeInForceRow.TimeInForceCode);
                AddAttribute("TimeInForceName", workingOrderRow.TimeInForceRow.Mnemonic);
            }

            // Security
            if (fields[Field.Security])
            {
                AddAttribute("SecurityId", workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.SecurityId);
                AddAttribute("SecuritySymbol", workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.Symbol);
                AddAttribute("SecurityName", workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.ObjectRow.Name);
                if (!workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.IsMarketCapitalizationNull())
                {
                    AddAttribute("MarketCapitalization", workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.MarketCapitalization / 1000000.0m);
                }
                if (!workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.IsAverageDailyVolumeNull())
                {
                    AddAttribute("AverageDailyVolume", workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.AverageDailyVolume / 1000.0m);
                }
                AddAttribute("VolumeCategoryMnemonic", workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.VolumeCategoryRow.Mnemonic);
            }

            // Source Order Total Quantity
            if (fields[Field.SourceOrder])
            {
                AddAttribute("SourceOrderQuantity", this.totalSourceOrderedQuantity);
            }

            //  Destination Order Total Quantity
            if (fields[Field.DestinationOrder])
            {
                AddAttribute("DestinationOrderQuantity", this.totalDestinationOrderedQuantity);
            }

            // Total Executed Quantity and Average Price
            if (fields[Field.SubmittedQuantity])
            {
                AddAttribute("SubmittedQuantity", workingOrderRow.SubmittedQuantity);
            }

            // Total Executed Quantity and Average Price
            if (fields[Field.Execution])
            {
                AddAttribute("ExecutedQuantity", this.totalExecutedQuantity);
                AddAttribute("AveragePrice", this.averagePriceExecuted);
            }

            // Total Quantity Allocated
            if (fields[Field.Allocation])
            {
                AddAttribute("AllocatedQuantity", this.totalAllocatedQuantity);
            }

            //  Working Order Leaves (Total Source Quantity - Total Destination Quantity)
            if (fields[Field.SourceOrder] || fields[Field.DestinationOrder])
            {
                AddAttribute("LeavesQuantity", this.totalLeavesQuantity);
            }

            //  Working Order Working Quantity (Total Source Quantity - Total Executed Quantity)
            if (fields[Field.SourceOrder] || fields[Field.Execution])
            {
                AddAttribute("WorkingQuantity", this.totalWorkingQuantity);
            }

            // Start Time
            if (fields[Field.StartTime] && !workingOrderRow.IsStartTimeNull())
            {
                AddAttribute("StartTime", workingOrderRow.StartTime.ToString("s"));
            }

            // Stop Time
            if (fields[Field.StopTime] && !workingOrderRow.IsStopTimeNull())
            {
                AddAttribute("StopTime", workingOrderRow.StopTime.ToString("s"));
            }

            // Maxmimum Volatility
            if (fields[Field.MaximumVolatility] && !workingOrderRow.IsMaximumVolatilityNull())
            {
                AddAttribute("MaximumVolatility", workingOrderRow.MaximumVolatility);
            }

            // News Free Time
            if (fields[Field.NewsFreeTime] && !workingOrderRow.IsNewsFreeTimeNull())
            {
                AddAttribute("NewsFreeTime", workingOrderRow.NewsFreeTime);
            }

            // Timer Field
            if (fields[Field.Timer])
            {
                TimeSpan timeLeft = workingOrderRow.TimerRow.StopTime.Subtract(workingOrderRow.TimerRow.CurrentTime);
                AddAttribute("TimeLeft", string.Format("{0:0}:{1:00}", timeLeft.Minutes, timeLeft.Seconds));
            }

            // The Working Order Fields
            if (fields[Field.WorkingOrder])
            {
                // Created
                AddAttribute("CreatedName", workingOrderRow.UserRowByUserWorkingOrderCreatedUserId.ObjectRow.Name);
                AddAttribute("CreatedTime", workingOrderRow.CreatedTime.ToString("s"));

                // Destination
                if (!workingOrderRow.IsDestinationIdNull())
                {
                    AddAttribute("DestinationId", workingOrderRow.DestinationRow.DestinationId);
                    AddAttribute("DestinationName", workingOrderRow.DestinationRow.Name);
                    AddAttribute("DestinationShortName", workingOrderRow.DestinationRow.ShortName);
                }

                // The Direction of this order (buy, sell, buy cover, etc.)
                AddAttribute("PriceTypeCode", workingOrderRow.PriceTypeRow.PriceTypeCode);
                AddAttribute("PriceTypeMnemonic", workingOrderRow.PriceTypeRow.Mnemonic);

                // Commission
                AddAttribute("Commission", this.totalCommission);

                // FilledNet
                AddAttribute("NetMarketValue", this.totalMarketValue - workingOrderRow.OrderTypeRow.CashSign * this.totalCommission);

                // Market
                //			AddAttribute("MarketId", workingOrderRow.SecurityRowByFKSecurityWorkingOrderSecurityId.MarketRow.MarketId);
                //			AddAttribute("MarketName", workingOrderRow.SecurityRowByFKSecurityWorkingOrderSecurityId.MarketRow.Name);
                //			AddAttribute("MarketShortName", workingOrderRow.SecurityRowByFKSecurityWorkingOrderSecurityId.MarketRow.ShortName);

                // LimitPrice
                // NOTE: LimitPrice is not sent when the WorkingOrder flag is set.
                // LimitPrice has a separate bit set in the field arary

                // Stop Price
                if (!workingOrderRow.IsStopPriceNull())
                {
                    AddAttribute("StopPrice", (decimal)workingOrderRow.StopPrice);
                }

                // TradeDate
                AddAttribute("TradeDate", workingOrderRow.CreatedTime.ToString("s"));

                // UploadTime
                if (!workingOrderRow.IsUploadedTimeNull())
                {
                    AddAttribute("UploadTime", workingOrderRow.CreatedTime.ToString("s"));
                }

                // CommissionType
                //				if (workingOrderRow != null)
                //				{
                //				ClientMarketData.CommissionRateTypeRow commissionRateTypeRow =
                //					ClientMarketData.CommissionRateType.FindByCommissionRateTypeCode((int)this.commissionRateTypeCode);
                //				AddAttribute("CommissionRateTypeCode", commissionRateTypeRow.CommissionRateTypeCode);
                //				AddAttribute("CommissionRateTypeName", commissionRateTypeRow.Name);
                //					AddAttribute("CommissionRate", this.averageCommissionRate);
                //				}

                // Filled Gross
                AddAttribute("MarketValue", this.totalMarketValue);

                // Unfilled
                AddAttribute("Unfilled", this.totalSourceOrderedQuantity - this.totalExecutedQuantity);
            }

            // Find the pricing record.
            if (!workingOrderRow.IsSettlementIdNull())
            {
                ClientMarketData.PriceRow priceRow = ClientMarketData.Price.FindBySecurityId(workingOrderRow.SecurityId);
                if (priceRow != null)
                {
                    if (fields[Field.LastPrice])
                    {
                        AddAttribute("LastPrice", priceRow.LastPrice);
                    }
                    if (fields[Field.BidPrice])
                    {
                        AddAttribute("BidPrice", priceRow.BidPrice);
                    }
                    if (fields[Field.AskPrice])
                    {
                        AddAttribute("AskPrice", priceRow.AskPrice);
                    }
                    if (fields[Field.LastSize])
                    {
                        AddAttribute("LastSize", priceRow.LastSize);
                    }
                    if (fields[Field.BidSize])
                    {
                        AddAttribute("BidSize", priceRow.BidSize);
                    }
                    if (fields[Field.AskPrice])
                    {
                        AddAttribute("AskSize", priceRow.AskSize);
                    }
                    if (fields[Field.Volume])
                    {
                        AddAttribute("Volume", priceRow.Volume);
                    }
                    if (fields[Field.InterpolatedVolume])
                    {
                        AddAttribute("InterpolatedVolume", VolumeHelper.CurrentVolumePercentage(DateTime.Now,
                                                                                                workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId.AverageDailyVolume,
                                                                                                priceRow.Volume));
                    }
                    if (fields[Field.VolumeWeightedAveragePrice])
                    {
                        AddAttribute("VolumeWeightedAveragePrice", priceRow.VolumeWeightedAveragePrice);
                    }
                }
            }
        }