diff --git a/.vs/MarketData/v16/.suo b/.vs/MarketData/v16/.suo index b7b2b42..3ca1b8a 100644 Binary files a/.vs/MarketData/v16/.suo and b/.vs/MarketData/v16/.suo differ diff --git a/MarketDataLib/Helper/MarketDataHelper.cs b/MarketDataLib/Helper/MarketDataHelper.cs index ecbf79b..f2861b9 100644 --- a/MarketDataLib/Helper/MarketDataHelper.cs +++ b/MarketDataLib/Helper/MarketDataHelper.cs @@ -5227,6 +5227,7 @@ namespace MarketData.Helper } return prices; } + public static Price GetPriceAsOf(String symbol, DateTime asOf) { HttpNetResponse httpNetResponse=null; @@ -5293,12 +5294,6 @@ namespace MarketData.Helper //******************************************************************************************************************************************************************************************************** // ******************************************************************************** H I S T O R I C A L P R I C I N G Y A H O O ********************************************************************* //******************************************************************************************************************************************************************************************************** -// ********************************************************************************************************************************************************* -// ********************************************************************************************************************************************************* - -// ******************************************************************************************************************************************************************************************************************** -// ******************************************************************************************************** N E W V E R S I O N ************************************************************************************* -// ******************************************************************************************************************************************************************************************************************** // Implemented 06/10/2022 public static Price GetDailyPrice(String symbol,DateTime pricingDate) @@ -5319,12 +5314,15 @@ namespace MarketData.Helper HttpNetResponse httpNetResponse=null; try { + startDate=startDate.Date; + endDate=endDate.Date; if(startDate>endDate) { DateTime tempDate=startDate; startDate=endDate; endDate=tempDate; } + MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[MarketDataHelper:GetDailyPrices]{0} start:{1} end:{2}",symbol,Utility.DateTimeToStringMMHDDHYYYY(startDate),Utility.DateTimeToStringMMHDDHYYYY(endDate))); StringBuilder sb = new StringBuilder(); String strRequest; diff --git a/MarketDataLib/Helper/PricingMarketDataHelper.cs b/MarketDataLib/Helper/PricingMarketDataHelper.cs index cf12caf..7f79189 100644 --- a/MarketDataLib/Helper/PricingMarketDataHelper.cs +++ b/MarketDataLib/Helper/PricingMarketDataHelper.cs @@ -6,6 +6,7 @@ using System.Threading; using MarketData.MarketDataModel; using MarketData.DataAccess; using MarketData.Utils; +using System.Net; namespace MarketData.Helper { @@ -49,7 +50,8 @@ namespace MarketData.Helper } public class PricingMarketDataHelper { - private static int MaxThreads = (int)ThreadHelperEnum.MaxThreads; + private static int MaxThreads = 20; // (int)ThreadHelperEnum.MaxThreads; + private static int WaitBetweenRequests=300; private List symbols; private int currentIndex = 0; @@ -97,7 +99,7 @@ namespace MarketData.Helper { PricingThreadHelper pricingThreadHelper = new PricingThreadHelper(queueSymbols[index],resetEvents[index]); ThreadPool.QueueUserWorkItem(ThreadPoolCallbackUpdateLatestPriceAll, pricingThreadHelper); - try{Thread.Sleep(250);}catch(Exception){;} + try{Thread.Sleep(WaitBetweenRequests);}catch(Exception){;} } MDTrace.WriteLine(LogLevel.DEBUG,"UpdateLatestPriceAll, waiting for queued items to complete."); WaitHandle.WaitAll(resetEvents); @@ -131,6 +133,7 @@ namespace MarketData.Helper { PricingThreadHelper pricingThreadHelper = new PricingThreadHelper(queueSymbols[index],startDate.Value,resetEvents[index]); ThreadPool.QueueUserWorkItem(ThreadPoolCallbackUpdatePricesBigCharts, pricingThreadHelper); + try{Thread.Sleep(WaitBetweenRequests);}catch(Exception){;} } MDTrace.WriteLine(LogLevel.DEBUG,"UpdatePricesBigCharts, waiting for queued items to complete."); WaitHandle.WaitAll(resetEvents); @@ -164,6 +167,7 @@ namespace MarketData.Helper { PricingThreadHelper pricingThreadHelper=new PricingThreadHelper(queueSymbols[index],startDate.Value,resetEvents[index]); ThreadPool.QueueUserWorkItem(ThreadPoolCallbackUpdatePricesYahoo,pricingThreadHelper); + try{Thread.Sleep(WaitBetweenRequests);}catch(Exception){;} } MDTrace.WriteLine(LogLevel.DEBUG,"UpdatePricesYahoo, waiting for queued items to complete."); WaitHandle.WaitAll(resetEvents); @@ -197,6 +201,7 @@ namespace MarketData.Helper { PricingThreadHelper pricingThreadHelper=new PricingThreadHelper(queueSymbols[index],startDate.Value,resetEvents[index]); ThreadPool.QueueUserWorkItem(ThreadPoolCallbackUpdatePricesYahooSweep,pricingThreadHelper); + try{Thread.Sleep(WaitBetweenRequests);}catch(Exception){;} } MDTrace.WriteLine(LogLevel.DEBUG,"UpdatePricesYahooSweep, waiting for queued items to complete."); WaitHandle.WaitAll(resetEvents); @@ -229,6 +234,7 @@ namespace MarketData.Helper { PricingThreadHelper pricingThreadHelper = new PricingThreadHelper(queueSymbols[index], resetEvents[index],asOf); ThreadPool.QueueUserWorkItem(ThreadPoolCallbackUpdatePricesAsOf, pricingThreadHelper); + try{Thread.Sleep(WaitBetweenRequests);}catch(Exception){;} } MDTrace.WriteLine(LogLevel.DEBUG,"UpdatePricesAsOfSymbol, waiting for queued items to complete."); WaitHandle.WaitAll(resetEvents); @@ -261,6 +267,7 @@ namespace MarketData.Helper { PricingThreadHelper pricingThreadHelper=new PricingThreadHelper(queueSymbols[index],asOf,resetEvents[index]); ThreadPool.QueueUserWorkItem(ThreadPoolCallbackUpdatePricesYahoo,pricingThreadHelper); + try{Thread.Sleep(WaitBetweenRequests);}catch(Exception){;} } MDTrace.WriteLine(LogLevel.DEBUG,"UpdatePricesAsOfSymbol, waiting for queued items to complete."); WaitHandle.WaitAll(resetEvents); @@ -292,6 +299,7 @@ namespace MarketData.Helper { PricingThreadHelper pricingThreadHelper = new PricingThreadHelper(queueSymbols[index], resetEvents[index],asOf); ThreadPool.QueueUserWorkItem(ThreadPoolCallbackUpdatePricesAsOf, pricingThreadHelper); + try{Thread.Sleep(WaitBetweenRequests);}catch(Exception){;} } MDTrace.WriteLine(LogLevel.DEBUG,"UpdatePricesAsOf, waiting for queued items to complete."); WaitHandle.WaitAll(resetEvents); @@ -325,6 +333,7 @@ namespace MarketData.Helper { PricingThreadHelper pricingThreadHelper = new PricingThreadHelper(queueSymbols[index], resetEvents[index],startDate); ThreadPool.QueueUserWorkItem(ThreadPoolCallbackGetMissingPrice, pricingThreadHelper); + try{Thread.Sleep(WaitBetweenRequests);}catch(Exception){;} } MDTrace.WriteLine(LogLevel.DEBUG,"Get missing prices, waiting for queued items to complete."); WaitHandle.WaitAll(resetEvents); @@ -356,6 +365,7 @@ namespace MarketData.Helper { PricingThreadHelper pricingThreadHelper = new PricingThreadHelper(queueSymbols[index], resetEvents[index],startDate); ThreadPool.QueueUserWorkItem(ThreadPoolCallbackGetMissingPrice, pricingThreadHelper); + try{Thread.Sleep(WaitBetweenRequests);}catch(Exception){;} } MDTrace.WriteLine(LogLevel.DEBUG,"Get missing prices, waiting for queued items to complete."); WaitHandle.WaitAll(resetEvents); @@ -394,7 +404,7 @@ namespace MarketData.Helper { PricingThreadHelper pricingThreadHelper = new PricingThreadHelper(queueSymbols[index], pricingDate,resetEvents[index]); ThreadPool.QueueUserWorkItem(ThreadPoolCallbackUpdateLatestPrice, pricingThreadHelper); - try{Thread.Sleep(250);}catch(Exception){;} + try{Thread.Sleep(WaitBetweenRequests);}catch(Exception){;} } MDTrace.WriteLine(LogLevel.DEBUG,"Load prices, waiting for queued items to complete."); WaitHandle.WaitAll(resetEvents); @@ -427,6 +437,7 @@ namespace MarketData.Helper { PricingThreadHelper pricingThreadHelper = new PricingThreadHelper(queueSymbols[index], pricingDate,resetEvents[index]); ThreadPool.QueueUserWorkItem(ThreadPoolCallbackLoadPrices, pricingThreadHelper); + try{Thread.Sleep(WaitBetweenRequests);}catch(Exception){;} } MDTrace.WriteLine(LogLevel.DEBUG,"Load prices, waiting for queued items to complete."); WaitHandle.WaitAll(resetEvents); diff --git a/MarketDataUnitTests/MarketDataFeedTests.cs b/MarketDataUnitTests/MarketDataFeedTests.cs index e9931a5..506222e 100644 --- a/MarketDataUnitTests/MarketDataFeedTests.cs +++ b/MarketDataUnitTests/MarketDataFeedTests.cs @@ -43,9 +43,17 @@ namespace MarketDataUnitTests } [TestMethod] - public void LatestPriceXXXRetrieval() + public void LatestPriceRetrieval() { - String symbol="ACWX"; + String symbol="AAPL"; + Price price=MarketDataHelper.GetLatestPrice(symbol); + Assert.IsTrue(null!=price && price.IsValid); + } + + [TestMethod] + public void LatestPriceGoogleRetrieval() + { + String symbol="AAPL"; Price price=MarketDataHelper.GetLatestPriceGoogle(symbol); Assert.IsTrue(null!=price && price.IsValid); } @@ -55,7 +63,7 @@ namespace MarketDataUnitTests { String symbol="AAPL"; Price price=MarketDataHelper.GetLatestPriceYahoo(symbol); - Assert.IsTrue(null!=price,"No Price"); + Assert.IsTrue(null!=price,"No Price from Yahoo"); Assert.IsTrue(price.IsValid,"Invalid Price"); } @@ -68,6 +76,27 @@ namespace MarketDataUnitTests Assert.IsTrue(price.IsValid,"Invalid Price"); } + [TestMethod] + public void DailyPricesYahoo() + { + String symbol="AAPL"; + DateTime startDate=DateTime.Parse("04-08-2024"); + DateTime endDate=DateTime.Parse("04-01-2024"); + + Prices prices = MarketDataHelper.GetDailyPrices(symbol, startDate, endDate); + Assert.IsTrue(null!=prices,"No Price from BigCharts"); + } + //public static Prices GetDailyPrices(String symbol, DateTime startDate, DateTime endDate) + + [TestMethod] + public void HistoricalPriceBigChartsRetrieval() + { + String symbol="AAPL"; + DateTime asOf=DateTime.Now; + Price price = MarketDataHelper.GetPriceAsOf(symbol, asOf); + Assert.IsTrue(null!=price,"No Price from BigCharts"); + } + [TestMethod] public void ConsumerPriceIndexBureauOfLaborStatisticsRetrieval() { diff --git a/Program.cs b/Program.cs index f8f7106..19f8a81 100644 --- a/Program.cs +++ b/Program.cs @@ -1664,8 +1664,8 @@ namespace MarketData Utility.RemoveLogFiles(); int STAGE_1=0,STAGE_FINAL=2; - DeletePriceWatchList("valuations",startDate.ToShortDateString()); - DeletePriceWatchList("Momentum",startDate.ToShortDateString()); + DeletePriceWatchList("valuations", startDate.ToShortDateString()); + DeletePriceWatchList("Momentum", startDate.ToShortDateString()); ManualResetEvent[] resetEvents = new ManualResetEvent[STAGE_FINAL+1]; for(int index=0;index