/// <summary>Archives a Price record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="RowVersion">The version number of this row.</param> /// <param name="securityId">The value for the SecurityId column.</param> /// <param name="archive">true to archive the object, false to unarchive it.</param> public static void Archive(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int securityId) { // Accessor for the Price Table. ServerMarketData.PriceDataTable priceTable = ServerMarketData.Price; // Rule #1: Make sure the record exists before updating it. ServerMarketData.PriceRow priceRow = priceTable.FindBySecurityId(securityId); if ((priceRow == null)) { throw new Exception(string.Format("The Price table does not have an element identified by {0}", securityId)); } // Rule #2: Optimistic Concurrency Check if ((priceRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Archive the child records. for (int index = 0; (index < priceRow.GetWorkingOrderRows().Length); index = (index + 1)) { ServerMarketData.WorkingOrderRow childWorkingOrderRow = priceRow.GetWorkingOrderRows()[index]; WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId); } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Delete the record in the ADO database. priceRow[priceTable.RowVersionColumn] = rowVersion; adoTransaction.DataRows.Add(priceRow); priceRow.Delete(); // Archive the record in the SQL database. SqlCommand sqlCommand = new SqlCommand("update \"Price\" set \"IsArchived\" = 1 where \"SecurityId\"=@securityId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Loads a Price record using Metadata Parameters.</summary> /// <param name="transaction">Contains the parameters and exceptions for this command.</param> public static void Load(ParameterList parameters) { // Accessor for the Price Table. ServerMarketData.PriceDataTable priceTable = ServerMarketData.Price; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; object askPrice = parameters["askPrice"].Value; object askSize = parameters["askSize"].Value; object bidPrice = parameters["bidPrice"].Value; object bidSize = parameters["bidSize"].Value; object closePrice = parameters["closePrice"].Value; string externalCurrencyId = parameters["currencyId"]; object highPrice = parameters["highPrice"].Value; object lastPrice = parameters["lastPrice"].Value; object lastSize = parameters["lastSize"].Value; object lowPrice = parameters["lowPrice"].Value; object openPrice = parameters["openPrice"].Value; object priceChange = parameters["priceChange"].Value; string externalSecurityId = parameters["securityId"]; object volume = parameters["volume"].Value; object volumeWeightedAveragePrice = parameters["volumeWeightedAveragePrice"].Value; // The row versioning is largely disabled for external operations. long rowVersion = long.MinValue; // Resolve External Identifiers int currencyId = Currency.FindRequiredKey(configurationId, "currencyId", externalCurrencyId); int securityId = Security.FindRequiredKey(configurationId, "securityId", externalSecurityId); // Find the record using the unique identifier. If it doesn't exist, it will be inserted, if it does exist, // it will be updated. ServerMarketData.PriceRow priceRow = priceTable.FindBySecurityId(securityId); if ((priceRow == null)) { // Call the internal 'Insert' method to complete the operation. MarkThree.Guardian.Core.Price.Insert(adoTransaction, sqlTransaction, ref rowVersion, askPrice, askSize, bidPrice, bidSize, closePrice, currencyId, highPrice, lastPrice, lastSize, lowPrice, openPrice, priceChange, securityId, volume, volumeWeightedAveragePrice); } else { // This will bypass the optimistic concurrency checking required by the internal method. rowVersion = ((long)(priceRow[priceTable.RowVersionColumn])); // Call the internal 'Update' method to complete the operation. MarkThree.Guardian.Core.Price.Update(adoTransaction, sqlTransaction, ref rowVersion, askPrice, askSize, bidPrice, bidSize, closePrice, currencyId, highPrice, lastPrice, lastSize, lowPrice, openPrice, priceChange, securityId, volume, volumeWeightedAveragePrice); } // Return values parameters["rowVersion"] = rowVersion; }
/// <summary>Archives a Price record using Metadata Parameters.</summary> /// <param name="transaction">Contains the parameters and exceptions for this command.</param> public static void Archive(ParameterList parameters) { // Accessor for the Price Table. ServerMarketData.PriceDataTable priceTable = ServerMarketData.Price; // Extract the parameters from the command batch. AdoTransaction adoTransaction = parameters["adoTransaction"]; SqlTransaction sqlTransaction = parameters["sqlTransaction"]; object configurationId = parameters["configurationId"].Value; string externalSecurityId = parameters["securityId"]; // Resolve External Identifiers int securityId = Security.FindRequiredKey(configurationId, "securityId", externalSecurityId); // The row versioning is largely disabled for external operations. long rowVersion = long.MinValue; // While the optimistic concurrency checking is disabled for the external methods, the internal methods // still need to perform the check. This ncurrency checking logic by finding the current row version to be // will bypass the coused when the internal method is called. ServerMarketData.PriceRow priceRow = priceTable.FindBySecurityId(securityId); rowVersion = ((long)(priceRow[priceTable.RowVersionColumn])); // Call the internal method to complete the operation. MarkThree.Guardian.Core.Price.Archive(adoTransaction, sqlTransaction, rowVersion, securityId); }
/// <summary>Inserts a Price record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="askPrice">The value for the AskPrice column.</param> /// <param name="askSize">The value for the AskSize column.</param> /// <param name="bidPrice">The value for the BidPrice column.</param> /// <param name="bidSize">The value for the BidSize column.</param> /// <param name="closePrice">The value for the ClosePrice column.</param> /// <param name="currencyId">The value for the CurrencyId column.</param> /// <param name="highPrice">The value for the HighPrice column.</param> /// <param name="lastPrice">The value for the LastPrice column.</param> /// <param name="lastSize">The value for the LastSize column.</param> /// <param name="lowPrice">The value for the LowPrice column.</param> /// <param name="openPrice">The value for the OpenPrice column.</param> /// <param name="priceChange">The value for the PriceChange column.</param> /// <param name="securityId">The value for the SecurityId column.</param> /// <param name="volume">The value for the Volume column.</param> /// <param name="volumeWeightedAveragePrice">The value for the VolumeWeightedAveragePrice column.</param> public static void Insert( AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, object askPrice, object askSize, object bidPrice, object bidSize, object closePrice, int currencyId, object highPrice, object lastPrice, object lastSize, object lowPrice, object openPrice, object priceChange, int securityId, object volume, object volumeWeightedAveragePrice) { // Accessor for the Price Table. ServerMarketData.PriceDataTable priceTable = ServerMarketData.Price; // Apply Defaults if ((askPrice == null)) { askPrice = 0.0m; } if ((askSize == null)) { askSize = 0.0m; } if ((bidPrice == null)) { bidPrice = 0.0m; } if ((bidSize == null)) { bidSize = 0.0m; } if ((closePrice == null)) { closePrice = 0.0m; } if ((highPrice == null)) { highPrice = 0.0m; } if ((lastPrice == null)) { lastPrice = 0.0m; } if ((lastSize == null)) { lastSize = 0.0m; } if ((lowPrice == null)) { lowPrice = 0.0m; } if ((openPrice == null)) { openPrice = 0.0m; } if ((priceChange == null)) { priceChange = 0.0m; } if ((volume == null)) { volume = 0.0m; } if ((volumeWeightedAveragePrice == null)) { volumeWeightedAveragePrice = 0.0m; } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Insert the record into the ADO database. ServerMarketData.PriceRow priceRow = priceTable.NewPriceRow(); priceRow[priceTable.RowVersionColumn] = rowVersion; priceRow[priceTable.AskPriceColumn] = askPrice; priceRow[priceTable.AskSizeColumn] = askSize; priceRow[priceTable.BidPriceColumn] = bidPrice; priceRow[priceTable.BidSizeColumn] = bidSize; priceRow[priceTable.ClosePriceColumn] = closePrice; priceRow[priceTable.CurrencyIdColumn] = currencyId; priceRow[priceTable.HighPriceColumn] = highPrice; priceRow[priceTable.LastPriceColumn] = lastPrice; priceRow[priceTable.LastSizeColumn] = lastSize; priceRow[priceTable.LowPriceColumn] = lowPrice; priceRow[priceTable.OpenPriceColumn] = openPrice; priceRow[priceTable.PriceChangeColumn] = priceChange; priceRow[priceTable.SecurityIdColumn] = securityId; priceRow[priceTable.VolumeColumn] = volume; priceRow[priceTable.VolumeWeightedAveragePriceColumn] = volumeWeightedAveragePrice; priceTable.AddPriceRow(priceRow); adoTransaction.DataRows.Add(priceRow); // Insert the record into the SQL database. SqlCommand sqlCommand = new SqlCommand(@"insert ""Price"" (""rowVersion"",""AskPrice"",""AskSize"",""BidPrice"",""BidSize"",""ClosePrice"",""CurrencyId"",""HighPrice"",""LastPrice"",""LastSize"",""LowPrice"",""OpenPrice"",""SecurityId"",""Volume"",""VolumeWeightedAveragePrice"") values (@rowVersion,@askPrice,@askSize,@bidPrice,@bidSize,@closePrice,@currencyId,@highPrice,@lastPrice,@lastSize,@lowPrice,@openPrice,@securityId,@volume,@volumeWeightedAveragePrice)"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion)); sqlCommand.Parameters.Add(new SqlParameter("@askPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, askPrice)); sqlCommand.Parameters.Add(new SqlParameter("@askSize", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, askSize)); sqlCommand.Parameters.Add(new SqlParameter("@bidPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, bidPrice)); sqlCommand.Parameters.Add(new SqlParameter("@bidSize", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, bidSize)); sqlCommand.Parameters.Add(new SqlParameter("@closePrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, closePrice)); sqlCommand.Parameters.Add(new SqlParameter("@currencyId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, currencyId)); sqlCommand.Parameters.Add(new SqlParameter("@highPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, highPrice)); sqlCommand.Parameters.Add(new SqlParameter("@lastPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, lastPrice)); sqlCommand.Parameters.Add(new SqlParameter("@lastSize", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, lastSize)); sqlCommand.Parameters.Add(new SqlParameter("@lowPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, lowPrice)); sqlCommand.Parameters.Add(new SqlParameter("@openPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, openPrice)); sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId)); sqlCommand.Parameters.Add(new SqlParameter("@volume", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, volume)); sqlCommand.Parameters.Add(new SqlParameter("@volumeWeightedAveragePrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, volumeWeightedAveragePrice)); sqlCommand.ExecuteNonQuery(); }
/// <summary>Updates a Price record.</summary> /// <param name="transaction">Commits or rejects a set of commands as a unit</param> /// <param name="rowVersion">The version number of the row</param> /// <param name="askPrice">The value for the AskPrice column.</param> /// <param name="askSize">The value for the AskSize column.</param> /// <param name="bidPrice">The value for the BidPrice column.</param> /// <param name="bidSize">The value for the BidSize column.</param> /// <param name="closePrice">The value for the ClosePrice column.</param> /// <param name="currencyId">The value for the CurrencyId column.</param> /// <param name="highPrice">The value for the HighPrice column.</param> /// <param name="lastPrice">The value for the LastPrice column.</param> /// <param name="lastSize">The value for the LastSize column.</param> /// <param name="lowPrice">The value for the LowPrice column.</param> /// <param name="openPrice">The value for the OpenPrice column.</param> /// <param name="priceChange">The value for the PriceChange column.</param> /// <param name="securityId">The value for the SecurityId column.</param> /// <param name="volume">The value for the Volume column.</param> /// <param name="volumeWeightedAveragePrice">The value for the VolumeWeightedAveragePrice column.</param> public static void Update( AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, object askPrice, object askSize, object bidPrice, object bidSize, object closePrice, object currencyId, object highPrice, object lastPrice, object lastSize, object lowPrice, object openPrice, object priceChange, int securityId, object volume, object volumeWeightedAveragePrice) { // Accessor for the Price Table. ServerMarketData.PriceDataTable priceTable = ServerMarketData.Price; // Rule #1: Make sure the record exists before updating it. ServerMarketData.PriceRow priceRow = priceTable.FindBySecurityId(securityId); if ((priceRow == null)) { throw new Exception(string.Format("The Price table does not have an element identified by {0}", securityId)); } // Rule #2: Optimistic Concurrency Check if ((priceRow.RowVersion != rowVersion)) { throw new System.Exception("This record is busy. Please try again later."); } // Apply Defaults if ((askPrice == null)) { askPrice = priceRow[priceTable.AskPriceColumn]; } if ((askSize == null)) { askSize = priceRow[priceTable.AskSizeColumn]; } if ((bidPrice == null)) { bidPrice = priceRow[priceTable.BidPriceColumn]; } if ((bidSize == null)) { bidSize = priceRow[priceTable.BidSizeColumn]; } if ((closePrice == null)) { closePrice = priceRow[priceTable.ClosePriceColumn]; } if ((currencyId == null)) { currencyId = priceRow[priceTable.CurrencyIdColumn]; } if ((highPrice == null)) { highPrice = priceRow[priceTable.HighPriceColumn]; } if ((lastPrice == null)) { lastPrice = priceRow[priceTable.LastPriceColumn]; } if ((lastSize == null)) { lastSize = priceRow[priceTable.LastSizeColumn]; } if ((lowPrice == null)) { lowPrice = priceRow[priceTable.LowPriceColumn]; } if ((openPrice == null)) { openPrice = priceRow[priceTable.OpenPriceColumn]; } if ((priceChange == null)) { priceChange = priceRow[priceTable.PriceChangeColumn]; } if ((volume == null)) { volume = priceRow[priceTable.VolumeColumn]; } if ((volumeWeightedAveragePrice == null)) { volumeWeightedAveragePrice = priceRow[priceTable.VolumeWeightedAveragePriceColumn]; } // Increment the row version rowVersion = ServerMarketData.RowVersion.Increment(); // Update the record in the ADO database. priceRow[priceTable.RowVersionColumn] = rowVersion; priceRow[priceTable.AskPriceColumn] = askPrice; priceRow[priceTable.AskSizeColumn] = askSize; priceRow[priceTable.BidPriceColumn] = bidPrice; priceRow[priceTable.BidSizeColumn] = bidSize; priceRow[priceTable.ClosePriceColumn] = closePrice; priceRow[priceTable.CurrencyIdColumn] = currencyId; priceRow[priceTable.HighPriceColumn] = highPrice; priceRow[priceTable.LastPriceColumn] = lastPrice; priceRow[priceTable.LastSizeColumn] = lastSize; priceRow[priceTable.LowPriceColumn] = lowPrice; priceRow[priceTable.OpenPriceColumn] = openPrice; priceRow[priceTable.PriceChangeColumn] = priceChange; priceRow[priceTable.VolumeColumn] = volume; priceRow[priceTable.VolumeWeightedAveragePriceColumn] = volumeWeightedAveragePrice; adoTransaction.DataRows.Add(priceRow); // Update the record in the SQL database. SqlCommand sqlCommand = new SqlCommand(@"update ""Price"" set ""RowVersion""=@rowVersion,""AskPrice""=@askPrice,""AskSize""=@askSize,""BidPrice""=@bidPrice,""BidSize""=@bidSize,""ClosePrice""=@closePrice,""CurrencyId""=@currencyId,""HighPrice""=@highPrice,""LastPrice""=@lastPrice,""LastSize""=@lastSize,""LowPrice""=@lowPrice,""OpenPrice""=@openPrice,""Volume""=@volume,""VolumeWeightedAveragePrice""=@volumeWeightedAveragePrice where ""SecurityId""=@securityId"); sqlCommand.Connection = sqlTransaction.Connection; sqlCommand.Transaction = sqlTransaction; sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion)); sqlCommand.Parameters.Add(new SqlParameter("@askPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, askPrice)); sqlCommand.Parameters.Add(new SqlParameter("@askSize", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, askSize)); sqlCommand.Parameters.Add(new SqlParameter("@bidPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, bidPrice)); sqlCommand.Parameters.Add(new SqlParameter("@bidSize", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, bidSize)); sqlCommand.Parameters.Add(new SqlParameter("@closePrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, closePrice)); sqlCommand.Parameters.Add(new SqlParameter("@currencyId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, currencyId)); sqlCommand.Parameters.Add(new SqlParameter("@highPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, highPrice)); sqlCommand.Parameters.Add(new SqlParameter("@lastPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, lastPrice)); sqlCommand.Parameters.Add(new SqlParameter("@lastSize", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, lastSize)); sqlCommand.Parameters.Add(new SqlParameter("@lowPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, lowPrice)); sqlCommand.Parameters.Add(new SqlParameter("@openPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, openPrice)); sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId)); sqlCommand.Parameters.Add(new SqlParameter("@volume", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, volume)); sqlCommand.Parameters.Add(new SqlParameter("@volumeWeightedAveragePrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, volumeWeightedAveragePrice)); // Update the record in the SQL database. sqlCommand.ExecuteNonQuery(); }