Exemplo n.º 1
0
        public PositionList GetPositions(Sector sector)
        {
            PositionList positionList = new PositionList();

            try
            {
                // Lock the tables.
                Debug.Assert(!ClientMarketData.AreLocksHeld);
                ClientMarketData.AccountLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.AllocationLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectTreeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.OrderLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.PositionLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ProposedOrderLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.SectorLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.SecurityLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.TaxLotLock.AcquireReaderLock(CommonTimeout.LockWait);

                ClientMarketData.AccountRow accountRow = ClientMarketData.Account.FindByAccountId(this.AccountId);

                ClientMarketData.SectorRow sectorRow = ClientMarketData.Sector.FindBySectorId(sector.SectorId);

                // Aggregate the tax lot quantities.
                foreach (ClientMarketData.TaxLotRow taxLotRow in accountRow.GetTaxLotRows())
                {
                    if (IsSecurityInSector(sectorRow, taxLotRow.SecurityRow))
                    {
                        positionList.Add(Position.Make(this.AccountId, taxLotRow.SecurityId, taxLotRow.PositionTypeCode));
                    }
                }

                // Aggregate the proposed ordered quantities
                foreach (ClientMarketData.ProposedOrderRow proposedOrderRow in accountRow.GetProposedOrderRows())
                {
                    if (IsSecurityInSector(sectorRow, proposedOrderRow.SecurityRowByFKSecurityProposedOrderSecurityId))
                    {
                        positionList.Add(Position.Make(this.AccountId, proposedOrderRow.SecurityId, proposedOrderRow.PositionTypeCode));
                    }
                }

                // Aggregate the ordered quantities
                foreach (ClientMarketData.OrderRow orderRow in accountRow.GetOrderRows())
                {
                    if (IsSecurityInSector(sectorRow, orderRow.SecurityRowByFKSecurityOrderSecurityId))
                    {
                        positionList.Add(Position.Make(this.AccountId, orderRow.SecurityId, orderRow.PositionTypeCode));
                    }
                }

                // Aggregate the allocated quantities
                foreach (ClientMarketData.AllocationRow allocationRow in accountRow.GetAllocationRows())
                {
                    if (IsSecurityInSector(sectorRow, allocationRow.SecurityRowByFKSecurityAllocationSecurityId))
                    {
                        positionList.Add(Position.Make(this.AccountId, allocationRow.SecurityId, allocationRow.PositionTypeCode));
                    }
                }
            }
            finally
            {
                // Locks are no longer needed on the price table.
                if (ClientMarketData.AccountLock.IsReaderLockHeld)
                {
                    ClientMarketData.AccountLock.ReleaseReaderLock();
                }
                if (ClientMarketData.AllocationLock.IsReaderLockHeld)
                {
                    ClientMarketData.AllocationLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectTreeLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectTreeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderLock.ReleaseReaderLock();
                }
                if (ClientMarketData.PositionLock.IsReaderLockHeld)
                {
                    ClientMarketData.PositionLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ProposedOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.ProposedOrderLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SectorLock.IsReaderLockHeld)
                {
                    ClientMarketData.SectorLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.ReleaseReaderLock();
                }
                if (ClientMarketData.TaxLotLock.IsReaderLockHeld)
                {
                    ClientMarketData.TaxLotLock.ReleaseReaderLock();
                }
                Debug.Assert(!ClientMarketData.AreLocksHeld);
            }

            return(positionList);
        }
Exemplo n.º 2
0
        public bool Contains(Security security, int positionType)
        {
            try
            {
                // Lock the tables.
                Debug.Assert(!ClientMarketData.AreLocksHeld);
                ClientMarketData.AccountLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.AllocationLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.OrderLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ProposedOrderLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.TaxLotLock.AcquireReaderLock(CommonTimeout.LockWait);

                ClientMarketData.AccountRow accountRow = ClientMarketData.Account.FindByAccountId(this.AccountId);

                foreach (ClientMarketData.TaxLotRow taxLotRow in accountRow.GetTaxLotRows())
                {
                    if (taxLotRow.SecurityId == security.SecurityId && taxLotRow.PositionTypeCode == positionType)
                    {
                        return(true);
                    }
                }

                foreach (ClientMarketData.ProposedOrderRow proposedOrderRow in accountRow.GetProposedOrderRows())
                {
                    if (proposedOrderRow.SecurityId == security.SecurityId && proposedOrderRow.PositionTypeCode == positionType)
                    {
                        return(true);
                    }
                }

                foreach (ClientMarketData.OrderRow orderRow in accountRow.GetOrderRows())
                {
                    if (orderRow.SecurityId == security.SecurityId && orderRow.PositionTypeCode == positionType)
                    {
                        return(true);
                    }
                }

                foreach (ClientMarketData.AllocationRow allocationRow in accountRow.GetAllocationRows())
                {
                    if (allocationRow.SecurityId == security.SecurityId && allocationRow.PositionTypeCode == positionType)
                    {
                        return(true);
                    }
                }

                return(false);
            }
            finally
            {
                // Release the table locks.
                if (ClientMarketData.AccountLock.IsReaderLockHeld)
                {
                    ClientMarketData.AccountLock.ReleaseReaderLock();
                }
                if (ClientMarketData.AllocationLock.IsReaderLockHeld)
                {
                    ClientMarketData.AllocationLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ProposedOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.ProposedOrderLock.ReleaseReaderLock();
                }
                if (ClientMarketData.TaxLotLock.IsReaderLockHeld)
                {
                    ClientMarketData.TaxLotLock.ReleaseReaderLock();
                }
                Debug.Assert(!ClientMarketData.AreLocksHeld);
            }
        }