Esempio n. 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;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initialize the data used in this application.
        /// </summary>
        private void InitializeData(object parameter)
        {
            string           title            = string.Empty;
            string           symbol           = string.Empty;
            string           name             = string.Empty;
            Bitmap           logo             = null;
            decimal          leavesQuantity   = 0.0m;
            decimal          minimumQuantity  = 0.0m;
            NegotiationState negotiationState = NegotiationState.None;

            try
            {
                // Lock the tables.
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.MatchLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.NegotiationLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.ObjectLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.OrderTypeLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.SecurityLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.WorkingOrderLock.AcquireReaderLock(ClientTimeout.LockWait);

                // Find the Match record.
                ClientMarketData.MatchRow        matchRow        = ClientMarketData.Match.FindByMatchId(this.matchId);
                ClientMarketData.WorkingOrderRow workingOrderRow = matchRow.WorkingOrderRow;
                ClientMarketData.OrderTypeRow    orderTypeRow    = workingOrderRow.OrderTypeRow;
                ClientMarketData.SecurityRow     securityRow     = workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId;

                symbol          = securityRow.Symbol;
                name            = securityRow.ObjectRow.Name;
                minimumQuantity = securityRow.MinimumQuantity;
                if (!securityRow.IsLogoNull())
                {
                    MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(securityRow.Logo));
                    logo = new Bitmap(memoryStream);
                }
                title          = string.Format("{0} of {1}", orderTypeRow.Description, symbol);
                leavesQuantity = workingOrderRow.SubmittedQuantity;
                foreach (ClientMarketData.DestinationOrderRow destinationOrderRow in workingOrderRow.GetDestinationOrderRows())
                {
                    foreach (ClientMarketData.ExecutionRow executionRow in destinationOrderRow.GetExecutionRows())
                    {
                        leavesQuantity -= executionRow.ExecutionQuantity;
                    }
                }
            }
            finally
            {
                // Release the locks.
                if (ClientMarketData.MatchLock.IsReaderLockHeld)
                {
                    ClientMarketData.MatchLock.ReleaseReaderLock();
                }
                if (ClientMarketData.NegotiationLock.IsReaderLockHeld)
                {
                    ClientMarketData.NegotiationLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.ReleaseReaderLock();
                }
                if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.WorkingOrderLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }

            Invoke(new SetDialogAttributesDelegate(SetDialogAttributes), new object[] { title, symbol, name, logo, leavesQuantity, negotiationState });
        }
        /// <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 DestinationOrderDocument(Blotter blotter, WorkingOrder[] workingOrders)
        {
            try
            {
                // Lock the tables
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.BlotterLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.SourceOrderLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.DestinationLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.DestinationOrderLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ExecutionLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectTreeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.OrderTypeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.PriceTypeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.PriceLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.SecurityLock.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.DestinationOrderRow destinationOrderRow in workingOrderRow.GetDestinationOrderRows())
                            {
                                documentNode.AppendChild(new DestinationOrderElement(this, destinationOrderRow, 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.SourceOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.SourceOrderLock.ReleaseReaderLock();
                }
                if (ClientMarketData.DestinationLock.IsReaderLockHeld)
                {
                    ClientMarketData.DestinationLock.ReleaseReaderLock();
                }
                if (ClientMarketData.DestinationOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.DestinationOrderLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ExecutionLock.IsReaderLockHeld)
                {
                    ClientMarketData.ExecutionLock.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.PriceLock.IsReaderLockHeld)
                {
                    ClientMarketData.PriceLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.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);
            }
        }