Exemplo n.º 1
0
 public DeleteArgs(long rowVersion, int orderId, ClientMarketData.OrderRow SetPrice)
 {
     // Initialize Members
     this.rowVersion = rowVersion;
     this.orderId    = orderId;
     this.SetPrice   = SetPrice;
 }
Exemplo n.º 2
0
 public void Initialize(ClientMarketData.OrderRow orderRow)
 {
     this.orderId         = orderRow.OrderId;
     this.transactionType = (TransactionType)orderRow.TransactionTypeCode;
     this.tif             = (TIF)orderRow.TimeInForceCode;
     this.pricedAt        = (PricedAt)orderRow.OrderTypeCode;
     this.quantity        = orderRow.Quantity;
     this.price1          = orderRow.IsPrice1Null() ? (object)null : orderRow.Price1;
     this.price2          = orderRow.IsPrice2Null() ? (object)null : orderRow.Price2;
 }
Exemplo n.º 3
0
        public OrdersElement(BlockOrderDocument blockOrderDocument, ClientMarketData.OrderRow orderRow) :
            base("Order", blockOrderDocument)
        {
            this.orderRow = orderRow;

            AddAttribute("OrderId", this.orderRow.OrderId);
            AddAttribute("AccountId", this.orderRow.AccountId);
            AddAttribute("SecurityId", this.orderRow.SecurityId);

            AddAttribute("SecurityName", this.orderRow.SecurityRowByFKSecurityOrderSecurityId.ObjectRow.Name);
            AddAttribute("SecuritySymbol", this.orderRow.SecurityRowByFKSecurityOrderSecurityId.Symbol);

            AddAttribute("SettlementName", this.orderRow.SecurityRowByFKSecurityOrderSettlementId.ObjectRow.Name);
            AddAttribute("SettlementSymbol", this.orderRow.SecurityRowByFKSecurityOrderSettlementId.Symbol);

            AddAttribute("PositionTypeCode", this.orderRow.PositionTypeCode);
            AddAttribute("TransactionTypeCode", this.orderRow.TransactionTypeCode);
            AddAttribute("TransactionTypeName", this.orderRow.TransactionTypeRow.Mnemonic);
            AddAttribute("Quantity", this.orderRow.Quantity);
            AddAttribute("TimeInForceCode", this.orderRow.TimeInForceCode);
            AddAttribute("TimeInForceName", this.orderRow.TimeInForceRow.Mnemonic);
            AddAttribute("OrderTypeCode", this.orderRow.OrderTypeCode);
            AddAttribute("OrderTypeName", this.orderRow.OrderTypeRow.Mnemonic);

            ClientMarketData.PriceRow priceRow = ClientMarketData.Price.FindBySecurityIdCurrencyId(
                this.orderRow.SecurityId, this.orderRow.SettlementId);
            if (priceRow != null)
            {
                AddAttribute("LastPrice", priceRow.LastPrice);
                AddAttribute("BidPrice", priceRow.BidPrice);
                AddAttribute("BidSize", priceRow.BidSize);
                AddAttribute("AskPrice", priceRow.AskPrice);
                AddAttribute("AskSize", priceRow.AskSize);
            }

            if (!this.orderRow.IsPrice1Null())
            {
                AddAttribute("Price1", this.orderRow.Price1);
            }
            if (!this.orderRow.IsPrice2Null())
            {
                AddAttribute("Price2", this.orderRow.Price2);
            }
            if (!this.orderRow.IsConditionCodeNull())
            {
                AddAttribute("ConditionCode", this.orderRow.ConditionCode);
            }
            if (!this.orderRow.IsNoteNull())
            {
                AddAttribute("Note", this.orderRow.Note);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a denormalized order record from a global record.
        /// </summary>
        /// <param name="globalOrder"></param>
        /// <returns></returns>
        public static OrderSet.OrderRow Create(ClientMarketData.OrderRow globalOrder)
        {
            // Create a new order record from the record factory.
            OrderSet.OrderRow orderRow = orderSet.Order.NewOrderRow();

            // These records are global and use the global system of identifiers.
            orderRow.IsLocal = false;

            // Copy each field that has an analog in the local record set into the new record.
            foreach (DataColumn dataColumn in globalOrder.Table.Columns)
            {
                orderRow[dataColumn.ColumnName] = globalOrder[dataColumn];
            }

            // AccountId cross-referenced data is filled in here.
            orderRow.AccountMnemonic = globalOrder.AccountRow.Mnemonic;
            orderRow.AccountName     = globalOrder.AccountRow.ObjectRow.Name;

            // SecurityId cross-referenced data is filled in here.
            orderRow.SecuritySymbol = globalOrder.SecurityRowByFKSecurityOrderSecurityId.Symbol;
            orderRow.SecurityName   = globalOrder.SecurityRowByFKSecurityOrderSecurityId.ObjectRow.Name;

            // CurrencyId cross-referenced data is filled in here.
            orderRow.SettlementSymbol = globalOrder.SecurityRowByFKSecurityOrderSettlementId.Symbol;
            orderRow.SettlementName   = globalOrder.SecurityRowByFKSecurityOrderSettlementId.ObjectRow.Name;

            // BrokerId cross-referenced data is filled in here.
            if (!globalOrder.IsBrokerIdNull())
            {
                ClientMarketData.BrokerRow brokerRow = ClientMarketData.Broker.FindByBrokerId(globalOrder.BrokerId);
                if (brokerRow != null)
                {
                    orderRow.BrokerSymbol = brokerRow.Symbol;
                    orderRow.BrokerName   = brokerRow.ObjectRow.Name;
                }
            }

            // TimeInForce cross-referenced data is filled in here.
            orderRow.TimeInForceMnemonic = globalOrder.TimeInForceRow.Mnemonic;

            // TimeInForce cross-referenced data is filled in here.
            orderRow.OrderTypeMnemonic = globalOrder.OrderTypeRow.Mnemonic;

            // This is a complete record of the order, including the referenced data.
            return(orderRow);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a proposed order record.
        /// </summary>
        /// <param name="orderRow">A proposed order record from the primary ADO database.</param>
        /// <returns>A Order record based on the ADO record.</returns>
        internal static Order Make(ClientMarketData.OrderRow orderRow)
        {
            // Initialize the object
            DataRowVersion dataRowVersion = orderRow.RowState == DataRowState.Deleted ? DataRowVersion.Original : DataRowVersion.Current;

            // Extract the data from the ADO record.
            int             orderId          = (int)orderRow[ClientMarketData.Order.OrderIdColumn, dataRowVersion];
            TransactionType transactionType  = (TransactionType)orderRow[ClientMarketData.Order.TransactionTypeCodeColumn, dataRowVersion];
            int             accountId        = (int)orderRow[ClientMarketData.Order.AccountIdColumn, dataRowVersion];
            int             securityId       = (int)orderRow[ClientMarketData.Order.SecurityIdColumn, dataRowVersion];
            int             positionTypeCode = Common.TransactionType.GetPosition((int)transactionType);
            Position        position         = Position.Make(accountId, securityId, positionTypeCode);
            TIF             tif      = (TIF)orderRow[ClientMarketData.Order.TimeInForceCodeColumn, dataRowVersion];
            PricedAt        pricedAt = (PricedAt)orderRow[ClientMarketData.Order.OrderTypeCodeColumn, dataRowVersion];
            decimal         quantity = (decimal)orderRow[ClientMarketData.Order.QuantityColumn, dataRowVersion];
            object          price1   = orderRow[ClientMarketData.Order.Price1Column, dataRowVersion];
            object          price2   = orderRow[ClientMarketData.Order.Price2Column, dataRowVersion];

            // Create a new record based on the data extracted from the ADO database.
            return(new Order(orderId, position, tif, pricedAt, quantity, price1, price2));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handles the primary Market Data events and passes the events along to the Langauge Primitives.
        /// </summary>
        /// <param name="sender">The object that originated the event.</param>
        /// <param name="orderRowChangeEvent">The record change event argument.</param>
        public static void OrderHandler(object sender, ClientMarketData.OrderRowChangeEvent orderRowChangeEvent)
        {
            // Extract the record from the event argument.
            ClientMarketData.OrderRow orderRow = orderRowChangeEvent.Row;

            // Translate the ADO.NET row states into a record state used by the Rules Engine.
            Action action = Action.Nothing;

            switch (orderRowChangeEvent.Action)
            {
            case DataRowAction.Add: action = Action.Add; break;

            case DataRowAction.Delete: action = Action.Delete; break;

            case DataRowAction.Change: action = Action.Change; break;

            case DataRowAction.Commit: return;
            }

            // Place the event into a list that will be processed when the tables are no longer locked.
            Order.orderEventArgList.Add(new OrderEventArgs(action, Order.Make(orderRow)));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates an element in the Appraisal Document that represents a fund's or account's position.
        /// </summary>
        /// <param name="appraisalDocument">The parent document.</param>
        /// <param name="driverAccount">Identifies the individual position at the account/security/position level.</param>
        public AccountElement(AppraisalDocument appraisalDocument, AppraisalSet.AccountRow driverAccount) :
            base("Account", appraisalDocument)
        {
            // Get the account record from the account id.  This record drives most of the data that appears in this element.
            ClientMarketData.AccountRow accountRow =
                ClientMarketData.Account.FindByAccountId(driverAccount.AccountId);

            // Count up the compliance violations
            int violationCount = 0;

            foreach (DataRowView dataRowView in
                     ClientMarketData.Violation.UKViolationAccountIdSecurityIdPositionTypeCode.FindRows(
                         new object[] { driverAccount.AccountId, driverAccount.SecurityId, driverAccount.PositionTypeCode }))
            {
                ClientMarketData.ViolationRow violationRow = (ClientMarketData.ViolationRow)dataRowView.Row;
                if (violationRow.RestrictionRow.Severity > 0)
                {
                    violationCount++;
                }
            }
            AddAttribute("Violation", violationCount);

            // Add the essential attributes to the element.
            AddAttribute("AccountId", accountRow.AccountId.ToString());

            // Aggregate the tax lot positions and cost.
            decimal taxLotQuantity = 0.0M;
            decimal taxLotCost     = 0.0M;

            foreach (ClientMarketData.TaxLotRow taxLotRow in accountRow.GetTaxLotRows())
            {
                if (taxLotRow.SecurityId == driverAccount.SecurityId &&
                    taxLotRow.PositionTypeCode == driverAccount.PositionTypeCode)
                {
                    taxLotQuantity += taxLotRow.Quantity;
                    taxLotCost     += taxLotRow.Cost * taxLotRow.Quantity;
                }
            }
            AddAttribute("TaxLotQuantity", taxLotQuantity.ToString());
            AddAttribute("TaxLotCost", taxLotCost.ToString());

            // Aggregate the proposed orders positions.
            decimal proposedOrderQuantity = 0.0M;

            foreach (DataRowView dataRowView in
                     appraisalDocument.proposedOrderView.FindRows(new object[] { driverAccount.AccountId, driverAccount.SecurityId,
                                                                                 driverAccount.PositionTypeCode }))
            {
                ClientMarketData.ProposedOrderRow proposedOrderRow = (ClientMarketData.ProposedOrderRow)dataRowView.Row;
                proposedOrderQuantity += proposedOrderRow.Quantity *
                                         proposedOrderRow.TransactionTypeRow.QuantitySign;
            }
            AddAttribute("ProposedOrderQuantity", proposedOrderQuantity.ToString());

            // Aggregate the orders.
            decimal orderQuantity = 0.0M;

            foreach (DataRowView dataRowView in
                     appraisalDocument.orderView.FindRows(new object[] { driverAccount.AccountId, driverAccount.SecurityId,
                                                                         driverAccount.PositionTypeCode }))
            {
                ClientMarketData.OrderRow orderRow = (ClientMarketData.OrderRow)dataRowView.Row;
                orderQuantity += orderRow.Quantity *
                                 orderRow.TransactionTypeRow.QuantitySign;
            }
            AddAttribute("OrderQuantity", orderQuantity.ToString());

            // Aggregate the allocations.
            decimal allocationQuantity = 0.0M;

            foreach (DataRowView dataRowView in
                     appraisalDocument.allocationView.FindRows(new object[] { driverAccount.AccountId, driverAccount.SecurityId,
                                                                              driverAccount.PositionTypeCode }))
            {
                ClientMarketData.AllocationRow allocationRow = (ClientMarketData.AllocationRow)dataRowView.Row;
                allocationQuantity += allocationRow.Quantity *
                                      allocationRow.TransactionTypeRow.QuantitySign;
            }
            AddAttribute("AllocationQuantity", allocationQuantity.ToString());
        }
Exemplo n.º 8
0
 public OrdersElement CreateOrdersElement(ClientMarketData.OrderRow orderRow)
 {
     return(new OrdersElement(this, orderRow));
 }
Exemplo n.º 9
0
        public void Initialize(Account account, Security security, TransactionType transactionType, TIF tif,
                               PricedAt pricedAt, decimal quantity, object price1, object price2)
        {
            // Create a block order on the server.
            RemoteBatch    remoteBatch    = new RemoteBatch();
            RemoteAssembly remoteAssembly = remoteBatch.Assemblies.Add("Service.Trading");
            RemoteType     remoteType     = remoteAssembly.Types.Add("Shadows.WebService.Trading.Order");
            RemoteMethod   remoteMethod   = remoteType.Methods.Add("Insert");

            remoteMethod.Parameters.Add("orderId", DataType.Int, Direction.ReturnValue);
            remoteMethod.Parameters.Add("accountId", account.AccountId);
            remoteMethod.Parameters.Add("securityId", security.SecurityId);
            remoteMethod.Parameters.Add("settlementId", security.SettlementId);
            remoteMethod.Parameters.Add("transactionTypeCode", (int)transactionType);
            remoteMethod.Parameters.Add("timeInForceCode", (int)tif);
            remoteMethod.Parameters.Add("orderTypeCode", (int)pricedAt);
            remoteMethod.Parameters.Add("quantity", quantity);
            remoteMethod.Parameters.Add("price1", price1 == null ? (object)DBNull.Value : price1);
            remoteMethod.Parameters.Add("price2", price2 == null ? (object)DBNull.Value : price2);
            ClientMarketData.Execute(remoteBatch);

            // Now that the block order is created, construct the in-memory version of the record.
            int orderId = (int)remoteMethod.Parameters["orderId"].Value;

            try
            {
                // Lock the tables.
                Debug.Assert(!ClientMarketData.AreLocksHeld);
                ClientMarketData.AccountLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.OrderLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.SecurityLock.AcquireReaderLock(CommonTimeout.LockWait);

                ClientMarketData.OrderRow orderRow = ClientMarketData.Order.FindByOrderId(orderId);
                if (orderRow == null)
                {
                    throw new Exception(String.Format("Order {0} doesn't exist", orderId));
                }

                Initialize(orderRow);
            }
            finally
            {
                // Release the table locks.
                if (ClientMarketData.AccountLock.IsReaderLockHeld)
                {
                    ClientMarketData.AccountLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.ReleaseReaderLock();
                }
                Debug.Assert(!ClientMarketData.AreLocksHeld);
            }
        }