Ejemplo n.º 1
0
        /// <summary>
        /// Updates the aggregates associated with a SourceOrder.
        /// </summary>
        /// <param name="workingOrderRow">The working order to which the SourceOrder belongs.</param>
        void UpdateSourceOrderQuantity(WorkingOrder workingOrder, DataModel.WorkingOrderRow workingOrderRow)
        {
            // These factors are used display the quantities and prices in industry standard notations.
            Decimal quantityFactor = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId.QuantityFactor;
            Decimal priceFactor    = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId.PriceFactor;

            // Aggregate the execution and source order quantities.
            Decimal sourceOrderQuantity = 0.0m;

            foreach (DataModel.SourceOrderRow sourceOrderRow in workingOrderRow.GetSourceOrderRows())
            {
                sourceOrderQuantity += sourceOrderRow.OrderedQuantity;
            }

            // Update and commit the changes to the WorkingOrder record.
            this.workingOrderCollectionView.EditItem(workingOrder);
            workingOrder.SourceOrderQuantity = sourceOrderQuantity;
            workingOrder.MarketValue         = sourceOrderQuantity * quantityFactor * workingOrder.LastPrice.Price * priceFactor;
            this.workingOrderCollectionView.CommitEdit();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The sum total of the quantities of all the source orders in a given working order.
        /// </summary>
        /// <param name="dataModelTransaction"></param>
        /// <param name="workingOrderRow">A working order row.</param>
        /// <returns>The total quantity of all the source orders associated with the working order.</returns>
        internal static Decimal GetSourceOrderQuantity(DataModelTransaction dataModelTransaction, DataModel.WorkingOrderRow workingOrderRow)
        {
            // This will aggregate all the source order quantities.  Note that the rows are kept locked for the duration of the transaction.  This guarantees
            // the integrity of the aggregate values.
            Decimal sourceOrderQuantity = 0.0m;

            foreach (DataModel.SourceOrderRow sourceOrderRow in workingOrderRow.GetSourceOrderRows())
            {
                try
                {
                    sourceOrderRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
                    sourceOrderQuantity += sourceOrderRow.OrderedQuantity;
                }
                finally
                {
                    sourceOrderRow.ReleaseLock(dataModelTransaction.TransactionId);
                }
            }

            // This is the sum total of all the source orders in the given working order.
            return(sourceOrderQuantity);
        }
Ejemplo n.º 3
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 virtual void Copy(DataModel.WorkingOrderRow workingOrderRow)
        {
            // Validate the parameters.
            if (workingOrderRow == null)
            {
                throw new ArgumentNullException("workingOrderRow");
            }

            // Find the price associated with the security in this order and copy.
            DataModel.PriceRow priceRow = DataModel.Price.PriceKey.Find(
                workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId.SecurityId,
                workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SettlementId.SecurityId);
            if (priceRow != null)
            {
                this.AskPrice.Price  = priceRow.AskPrice;
                this.BidPrice.Price  = priceRow.BidPrice;
                this.LastPrice.Price = priceRow.LastPrice;
            }

            // Any order that is not filled is considered active.
            this.IsActive = workingOrderRow.StatusRow.StatusCode != StatusCode.Filled;

            // Copy the scalar values directly from the data model.
            this.BlotterName    = workingOrderRow.BlotterRow.EntityRow.Name;
            this.CreatedBy      = workingOrderRow.UserRowByFK_User_WorkingOrder_CreatedUserId.EntityRow.Name;
            this.CreatedTime    = workingOrderRow.CreatedTime;
            this.ModifiedBy     = workingOrderRow.UserRowByFK_User_WorkingOrder_ModifiedUserId.EntityRow.Name;
            this.ModifiedTime   = workingOrderRow.ModifiedTime;
            this.RowVersion     = workingOrderRow.RowVersion;
            this.SecurityName   = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId.EntityRow.Name;
            this.SideCode       = workingOrderRow.SideRow.SideCode;
            this.SideMnemonic   = workingOrderRow.SideRow.Mnemonic;
            this.SettlementDate = workingOrderRow.SettlementDate;
            this.StatusCode     = workingOrderRow.StatusRow.StatusCode;
            this.Symbol         = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId.Symbol;
            this.TradeDate      = workingOrderRow.TradeDate;
            this.WorkingOrderId = workingOrderRow.WorkingOrderId;

            // These factors are needed to compute the proper quantities and prices.
            Decimal quantityFactor = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId.QuantityFactor;
            Decimal priceFactor    = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId.PriceFactor;

            // Aggregate the Destiantion Order and Execution Quantities.
            Decimal destinationOrderQuantity = 0.0m;
            Decimal executionQuantity        = 0.0m;

            foreach (DataModel.DestinationOrderRow destinationOrderRow in workingOrderRow.GetDestinationOrderRows())
            {
                destinationOrderQuantity += destinationOrderRow.OrderedQuantity;
                foreach (DataModel.ExecutionRow executionRow in destinationOrderRow.GetExecutionRows())
                {
                    executionQuantity += executionRow.ExecutionQuantity;
                }
            }
            this.DestinationOrderQuantity = destinationOrderQuantity;
            this.ExecutionQuantity        = executionQuantity;

            // Aggregate the Source Order Quantity.
            Decimal sourceOrderQuantity = 0.0m;

            foreach (DataModel.SourceOrderRow sourceOrderRow in workingOrderRow.GetSourceOrderRows())
            {
                sourceOrderQuantity += sourceOrderRow.OrderedQuantity;
            }
            this.SourceOrderQuantity = sourceOrderQuantity;

            // These derived values must be calcualted after the value columns.
            this.AvailableQuantity = this.SourceOrderQuantity - this.DestinationOrderQuantity;
            this.MarketValue       = sourceOrderQuantity * quantityFactor * this.LastPrice.Price * priceFactor;
            this.LeavesQuantity    = this.DestinationOrderQuantity - this.ExecutionQuantity;
        }