示例#1
0
        public void AggregateFields(ClientMarketData.WorkingOrderRow workingOrderRow)
        {
            this.totalSourceOrderedQuantity      = 0.0M;
            this.totalDestinationOrderedQuantity = 0.0M;
            this.totalWorkingQuantity            = 0.0M;
            this.totalExecutedQuantity           = 0.0M;
            this.totalAllocatedQuantity          = 0.0M;
            this.totalLeavesQuantity             = 0.0M;
            this.averagePriceExecuted            = 0.0M;
            this.totalCommission  = 0.0M;
            this.totalMarketValue = 0.0M;
//			this.averageCommissionRate = 0.0M;

            foreach (ClientMarketData.SourceOrderRow customerOrderRow in workingOrderRow.GetSourceOrderRows())
            {
                this.totalSourceOrderedQuantity += customerOrderRow.OrderedQuantity;
            }

            foreach (ClientMarketData.DestinationOrderRow destinationOrderRow in workingOrderRow.GetDestinationOrderRows())
            {
                this.totalDestinationOrderedQuantity += destinationOrderRow.OrderedQuantity - destinationOrderRow.CanceledQuantity;

                foreach (ClientMarketData.ExecutionRow executionRow in destinationOrderRow.GetExecutionRows())
                {
                    this.totalExecutedQuantity += executionRow.ExecutionQuantity;
                    this.totalMarketValue      += executionRow.ExecutionQuantity * executionRow.ExecutionPrice;
                }
            }

            this.totalWorkingQuantity = this.totalSourceOrderedQuantity - this.totalExecutedQuantity;
            this.totalLeavesQuantity  = this.totalSourceOrderedQuantity - this.totalDestinationOrderedQuantity;

            this.averagePriceExecuted = this.totalExecutedQuantity == 0.0M ? 0.0M :
                                        this.totalMarketValue / this.totalExecutedQuantity;

            foreach (ClientMarketData.AllocationRow allocationRow in workingOrderRow.GetAllocationRows())
            {
                this.totalAllocatedQuantity += allocationRow.Quantity;
                this.totalCommission        += allocationRow.Commission;
            }
        }
示例#2
0
        /// <summary>
        /// Creates a well formed working order document object model.
        /// </summary>
        /// <param name="blotterId">The blotter identifies what blocks are to be included in this document.</param>
        public SourceOrderDocument(Blotter blotter, WorkingOrder[] workingOrders)
        {
            try
            {
                // Lock the tables
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.BlotterLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.DestinationLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectTreeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.OrderTypeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.PriceTypeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.SecurityLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.SourceOrderLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.StatusLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.StylesheetLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.TimeInForceLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.UserLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.WorkingOrderLock.AcquireReaderLock(CommonTimeout.LockWait);

                // Create the root element for the document.
                XmlNode documentNode = this.AppendChild(this.CreateElement("Document"));

                if (workingOrders == null)
                {
                    // Find the top level blotter record and recursively construct the report by merging all the children.
                    ClientMarketData.ObjectRow objectRow = ClientMarketData.Object.FindByObjectId(blotter.BlotterId);
                    if (objectRow != null)
                    {
                        RecurseBlotter(documentNode, objectRow);
                    }
                }
                else
                {
                    foreach (WorkingOrder workingOrder in workingOrders)
                    {
                        ClientMarketData.WorkingOrderRow workingOrderRow = ClientMarketData.WorkingOrder.FindByWorkingOrderId(workingOrder.WorkingOrderId);
                        if (workingOrderRow != null)
                        {
                            foreach (ClientMarketData.SourceOrderRow sourceOrderRow in workingOrderRow.GetSourceOrderRows())
                            {
                                documentNode.AppendChild(new SourceOrderElement(this, sourceOrderRow, FieldArray.Set));
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                // Write the error and stack trace out to the debug listener
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);
            }
            finally
            {
                // Release the table locks.
                if (ClientMarketData.BlotterLock.IsReaderLockHeld)
                {
                    ClientMarketData.BlotterLock.ReleaseReaderLock();
                }
                if (ClientMarketData.DestinationLock.IsReaderLockHeld)
                {
                    ClientMarketData.DestinationLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectTreeLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectTreeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.PriceTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.PriceTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SourceOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.SourceOrderLock.ReleaseReaderLock();
                }
                if (ClientMarketData.StatusLock.IsReaderLockHeld)
                {
                    ClientMarketData.StatusLock.ReleaseReaderLock();
                }
                if (ClientMarketData.StylesheetLock.IsReaderLockHeld)
                {
                    ClientMarketData.StylesheetLock.ReleaseReaderLock();
                }
                if (ClientMarketData.TimeInForceLock.IsReaderLockHeld)
                {
                    ClientMarketData.TimeInForceLock.ReleaseReaderLock();
                }
                if (ClientMarketData.UserLock.IsReaderLockHeld)
                {
                    ClientMarketData.UserLock.ReleaseReaderLock();
                }
                if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.WorkingOrderLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }
        }