Пример #1
0
        /// <summary>
        /// Creates an XML Element representing a placment in the order document.
        /// </summary>
        /// <param name="xmlDocument">The destination XML document.</param>
        /// <param name="orderRow">A order record.</param>
        public LocalOrderElement(XmlDocument xmlDocument, LocalOrderSet.OrderRow orderRow) :
            base("LocalOrder", xmlDocument)
        {
            // Add the attributes of a order to this record.
            AddAttribute("OrderId", orderRow.OrderId.ToString());

            // Account field
            if (!orderRow.IsAccountIdNull())
            {
                AddAttribute("AccountId", orderRow.AccountId.ToString());

                ClientMarketData.AccountRow accountRow = ClientMarketData.Account.FindByAccountId(orderRow.AccountId);
                if (accountRow != null)
                {
                    AddAttribute("AccountId", accountRow.AccountId.ToString());
                    AddAttribute("AccountName", accountRow.ObjectRow.Name);
                    AddAttribute("AccountMnemonic", accountRow.Mnemonic);
                }
            }

            // Security field
            if (!orderRow.IsSecurityIdNull())
            {
                AddAttribute("SecurityId", orderRow.SecurityId.ToString());

                ClientMarketData.SecurityRow securityRow = ClientMarketData.Security.FindBySecurityId(orderRow.SecurityId);
                if (securityRow != null)
                {
                    AddAttribute("SecurityId", securityRow.SecurityId.ToString());
                    AddAttribute("SecurityName", securityRow.ObjectRow.Name);
                    AddAttribute("SecuritySymbol", securityRow.Symbol);
                }
            }

            // Broker field
            if (!orderRow.IsBrokerIdNull())
            {
                AddAttribute("BrokerId", orderRow.BrokerId.ToString());

                ClientMarketData.BrokerRow brokerRow = ClientMarketData.Broker.FindByBrokerId(orderRow.BrokerId);
                if (brokerRow != null)
                {
                    AddAttribute("BrokerId", brokerRow.BrokerId.ToString());
                    AddAttribute("BrokerName", brokerRow.ObjectRow.Name);
                    AddAttribute("BrokerSymbol", brokerRow.Symbol);
                    if (!brokerRow.IsPhoneNull())
                    {
                        AddAttribute("BrokerPhone", brokerRow.Phone);
                    }
                }
            }

            // TransactionType field
            if (!orderRow.IsTransactionTypeCodeNull())
            {
                AddAttribute("TransactionTypeCode", orderRow.TransactionTypeCode.ToString());

                ClientMarketData.TransactionTypeRow transactionTypeRow = ClientMarketData.TransactionType.FindByTransactionTypeCode(orderRow.TransactionTypeCode);
                if (transactionTypeRow != null)
                {
                    AddAttribute("TransactionTypeMnemonic", transactionTypeRow.Mnemonic);
                }
            }

            // TimeInForce field
            if (!orderRow.IsTimeInForceCodeNull())
            {
                AddAttribute("TimeInForceCode", orderRow.TimeInForceCode.ToString());

                ClientMarketData.TimeInForceRow timeInForceRow = ClientMarketData.TimeInForce.FindByTimeInForceCode(orderRow.TimeInForceCode);
                if (timeInForceRow != null)
                {
                    AddAttribute("TimeInForceMnemonic", timeInForceRow.Mnemonic);
                }
            }

            // OrderType field
            if (!orderRow.IsOrderTypeCodeNull())
            {
                AddAttribute("OrderTypeCode", orderRow.OrderTypeCode.ToString());

                ClientMarketData.OrderTypeRow orderTypeRow = ClientMarketData.OrderType.FindByOrderTypeCode(orderRow.OrderTypeCode);
                if (orderTypeRow != null)
                {
                    AddAttribute("OrderTypeMnemonic", orderTypeRow.Mnemonic);
                }
            }

            if (!orderRow.IsQuantityNull())
            {
                AddAttribute("Quantity", orderRow.Quantity.ToString());
            }
            if (!orderRow.IsPrice1Null())
            {
                AddAttribute("Price1", orderRow.Price1.ToString());
            }
            if (!orderRow.IsPrice2Null())
            {
                AddAttribute("Price2", orderRow.Price2.ToString());
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a denormalized order record from a local record.
        /// </summary>
        /// <param name="localOrder">A local order record.</param>
        /// <returns>A order record that is independant of the global data set for all the anscillary data.</returns>
        public static OrderSet.OrderRow Create(LocalOrderSet.OrderRow localOrder)
        {
            // Create a new, empty order record.
            OrderSet.OrderRow orderRow = orderSet.Order.NewOrderRow();

            // This new record is a copy of a local record and uses the local system of identifiers.
            orderRow.IsLocal = true;

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

            // AccountId cross-referenced data is filled in here.
            if (!localOrder.IsAccountIdNull())
            {
                ClientMarketData.AccountRow accountRow = ClientMarketData.Account.FindByAccountId(orderRow.AccountId);
                if (accountRow != null)
                {
                    orderRow.AccountMnemonic = accountRow.Mnemonic;
                    orderRow.AccountName     = accountRow.ObjectRow.Name;
                }
            }

            // SecurityId cross-referenced data is filled in here.
            if (!localOrder.IsSecurityIdNull())
            {
                ClientMarketData.SecurityRow securityRow = ClientMarketData.Security.FindBySecurityId(orderRow.SecurityId);
                if (securityRow != null)
                {
                    orderRow.SecuritySymbol = securityRow.Symbol;
                    orderRow.SecurityName   = securityRow.ObjectRow.Name;
                }
            }

            // CurrencyId cross-referenced data is filled in here.
            if (!localOrder.IsSettlementIdNull())
            {
                ClientMarketData.CurrencyRow currencyRow = ClientMarketData.Currency.FindByCurrencyId(orderRow.SettlementId);
                if (currencyRow != null)
                {
                    orderRow.SettlementSymbol = currencyRow.SecurityRow.Symbol;
                    orderRow.SettlementName   = currencyRow.SecurityRow.ObjectRow.Name;
                }
            }

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

            // TransactionType cross-referenced data is filled in here.
            if (!localOrder.IsTransactionTypeCodeNull())
            {
                ClientMarketData.TransactionTypeRow transactionTypeRow = ClientMarketData.TransactionType.FindByTransactionTypeCode(orderRow.TransactionTypeCode);
                if (transactionTypeRow != null)
                {
                    orderRow.TransactionTypeMnemonic = transactionTypeRow.Mnemonic;
                }
            }

            // TimeInForce cross-referenced data is filled in here.
            if (!localOrder.IsTimeInForceCodeNull())
            {
                ClientMarketData.TimeInForceRow timeInForceRow = ClientMarketData.TimeInForce.FindByTimeInForceCode(orderRow.TimeInForceCode);
                if (timeInForceRow != null)
                {
                    orderRow.TimeInForceMnemonic = timeInForceRow.Mnemonic;
                }
            }

            // TimeInForce cross-referenced data is filled in here.
            if (!localOrder.IsOrderTypeCodeNull())
            {
                ClientMarketData.OrderTypeRow orderTypeRow = ClientMarketData.OrderType.FindByOrderTypeCode(orderRow.OrderTypeCode);
                if (orderTypeRow != null)
                {
                    orderRow.OrderTypeMnemonic = orderTypeRow.Mnemonic;
                }
            }

            // This is a complete record of the order, including the referenced data.
            return(orderRow);
        }