Ejemplo n.º 1
0
 /// <summary>
 /// Updates prices using a United States ticker.
 /// </summary>
 /// <param name="quotes">A collection of price quotes.</param>
 internal static void UpdateUnitedStatesTickerPrice(Quote[] quotes)
 {
     // Update the price table with United States ticker symbols.
     DataModel.IEntityIndex symbolIndex   = DataModel.Entity.EntityKeyExternalId3;
     DataModel.IEntityIndex currencyIndex = DataModel.Entity.EntityKeyExternalId0;
     foreach (Quote quote in quotes)
     {
         PriceService.UpdatePriceBySymbolCurrency(symbolIndex, new Object[] { quote.Symbol }, currencyIndex, new Object[] { "USD" }, quote);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates prices using a United States ticker.
        /// </summary>
        /// <param name="symbolIndex">The index to use to find the symbol.</param>
        /// <param name="symbolKey">The symbol key.</param>
        /// <param name="currencyIndex">The index to use to find the currency.</param>
        /// <param name="currencyKey">The currency key.</param>
        /// <param name="quote">The quote used to update the price.</param>
        static void UpdatePriceBySymbolCurrency(
            DataModel.IEntityIndex symbolIndex,
            Object[] symbolKey,
            DataModel.IEntityIndex currencyIndex,
            Object[] currencyKey,
            Quote quote)
        {
            // The current transaction and the target data model is extracted from the thread.
            DataModelTransaction dataModelTransaction = DataModel.CurrentTransaction;
            TenantDataModel      tenantDataSet        = dataModelTransaction.TenantDataModel;

            // This will find the currency of the quote.
            DataModel.EntityRow currencyEntityRow = currencyIndex.Find(currencyKey);
            if (currencyEntityRow == null)
            {
                throw new FaultException <RecordNotFoundFault>(new RecordNotFoundFault("Entity", currencyKey));
            }
            currencyEntityRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
            dataModelTransaction.AddLock(currencyEntityRow);
            if (currencyEntityRow.RowState == System.Data.DataRowState.Detached)
            {
                throw new FaultException <RecordNotFoundFault>(new RecordNotFoundFault("Entity", currencyKey));
            }
            Guid currencyId = currencyEntityRow.EntityId;

            // This will find the security using the external identifier.
            DataModel.EntityRow securityEntityRow = symbolIndex.Find(symbolKey);
            if (securityEntityRow == null)
            {
                throw new FaultException <RecordNotFoundFault>(new RecordNotFoundFault("Entity", symbolKey));
            }
            securityEntityRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
            dataModelTransaction.AddLock(securityEntityRow);
            if (securityEntityRow.RowState == System.Data.DataRowState.Detached)
            {
                throw new FaultException <RecordNotFoundFault>(new RecordNotFoundFault("Entity", symbolKey));
            }
            Guid securityId = securityEntityRow.EntityId;

            // If the price record exists, then update it.  If it doesn't exist then create it.
            Object[]           priceKey = new Object[] { securityId, currencyId };
            DataModel.PriceRow priceRow = DataModel.Price.PriceKey.Find(priceKey);
            if (priceRow == null)
            {
                tenantDataSet.CreatePrice(
                    quote.AskPrice,
                    quote.AskSize,
                    quote.BidPrice,
                    quote.BidSize,
                    null,
                    currencyId,
                    null,
                    quote.LastPrice,
                    quote.LastSize,
                    null,
                    null,
                    null,
                    securityId,
                    null,
                    null);
            }
            else
            {
                priceRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
                dataModelTransaction.AddLock(priceRow);
                if (priceRow.RowState == System.Data.DataRowState.Detached)
                {
                    throw new FaultException <RecordNotFoundFault>(new RecordNotFoundFault("Price", priceKey));
                }
                tenantDataSet.UpdatePrice(
                    quote.AskPrice,
                    quote.AskSize,
                    quote.BidPrice,
                    quote.BidSize,
                    null,
                    currencyId,
                    null,
                    quote.LastPrice,
                    quote.LastSize,
                    null,
                    null,
                    null,
                    priceKey,
                    priceRow.RowVersion,
                    securityId,
                    null,
                    null);
            }
        }