From 6504f1d2c27eb1669bef8e980aa37a2263a19788 Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 27 Mar 2025 18:55:13 -0400 Subject: [PATCH] Code enhancements --- .gitignore | 2 ++ MarketData/MarketData/Services/MainService.cs | 35 +++++++------------ 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 70d16ea..b7f631c 100644 --- a/.gitignore +++ b/.gitignore @@ -153,3 +153,5 @@ MarketData/MarketDataLib/obj/project.assets.json MarketData/MarketDataLib/obj/project.nuget.cache MarketData/MarketData/*.log MarketData/MarketData/marketdata.log +MarketData/MarketData/logs/marketdata_echo.log +MarketData/MarketData/logs/marketdata_loadheadlineswatchlist.log diff --git a/MarketData/MarketData/Services/MainService.cs b/MarketData/MarketData/Services/MainService.cs index b6625c4..0bdf709 100755 --- a/MarketData/MarketData/Services/MainService.cs +++ b/MarketData/MarketData/Services/MainService.cs @@ -44,7 +44,7 @@ namespace MarketData.Services } string arg = args[0].ToUpper(); - + CreateLogging(arg); // log files are now of the form market_data+task.log. Also log files will expire daily MDTrace.WriteLine(LogLevel.DEBUG,$"[RunService] Started @ {Utility.DateTimeToStringYYYYHMMHDDHHMMSSTT(currentDate)}"); @@ -189,25 +189,13 @@ namespace MarketData.Services // Sanity check. If the given date is not today then ask the user to confirm if (currentDate != startDate.Date) { - Console.WriteLine(String.Format("Run date is not today, please confirm Y/N:{0}?",startDate.ToShortDateString())); - String result=Console.ReadLine(); - if(null==result||!(result.ToUpper().Equals("Y")||result.ToUpper().Equals("YES")))return; + MDTrace.WriteLine(LogLevel.DEBUG,$"Run date is not today: Current Date:{currentDate.ToShortDateString()} Run Date: {startDate.ToShortDateString()}"); + return; } - if(!dateGenerator.IsMarketOpen(currentDate)) + if(!CheckRunCriteria()) { - String description=""; - if(HolidayDA.IsMarketHoliday(currentDate)) description=HolidayDA.GetHolidayDescription(currentDate); - else description=Utility.DayOfWeekToString(currentDate.DayOfWeek); - Console.WriteLine(String.Format("Market is closed today ({0}), please confirm Y/N:{1}?",description,startDate.ToShortDateString())); - String result=Console.ReadLine(); - if(null==result||!(result.ToUpper().Equals("Y")||result.ToUpper().Equals("YES"))) return; + return; } - if(!NetworkStatus.IsInternetConnected()) - { - Console.WriteLine(String.Format("The internet is not connected, continue anyway Y/N:?")); - String result=Console.ReadLine(); - if(null==result||!(result.ToUpper().Equals("Y")||result.ToUpper().Equals("YES")))return; - } MDTrace.WriteLine(LogLevel.DEBUG,$"UPDATEDAILY2 DATE:{startDate.ToShortDateString()}"); int STAGE_1=0,STAGE_2=1,STAGE_3=2,STAGE_4=3,STAGE_5=4,STAGE_6=5,STAGE_7=6,STAGE_8=7,STAGE_9=8,STAGE_10=9,STAGE_11=10,STAGE_12=11,STAGE_FINAL=12; DeletePriceWatchList("valuations",startDate.ToShortDateString()); @@ -460,6 +448,7 @@ namespace MarketData.Services { try { + if(!CheckRunCriteria())return; DateGenerator dateGenerator = new DateGenerator(); MDTrace.WriteLine(LogLevel.DEBUG, "[UPDATELATESTANALYSTRATINGS]"); AnalystRatings analystRatings = MarketDataHelper.GetLatestAnalystRatings(); @@ -626,6 +615,7 @@ namespace MarketData.Services { try { + if(!CheckRunCriteria())return; MDTrace.WriteLine(LogLevel.DEBUG, "[UPDATEANALYSTRATINGS]"); List symbols = new List(); if (paramSymbol == null) symbols = PricingDA.GetSymbols(); @@ -750,16 +740,15 @@ namespace MarketData.Services String description=""; if(HolidayDA.IsMarketHoliday(currentDate)) description=HolidayDA.GetHolidayDescription(currentDate); else description=Utility.DayOfWeekToString(currentDate.DayOfWeek); - MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Market is closed today {0} ({1}), please confirm Y/N:?",currentDate.ToShortDateString(),description)); + MDTrace.WriteLine(LogLevel.DEBUG,$"Market is closed today {currentDate.ToShortDateString()} for {description}."); return false; } - if(!NetworkStatus.IsInternetConnected()) - { - MDTrace.WriteLine(LogLevel.DEBUG,String.Format("The internet is not connected.")); + if(!NetworkStatus.IsInternetConnected()) + { + MDTrace.WriteLine(LogLevel.DEBUG,$"The internet is not connected."); return false; - } + } return true; } - } } \ No newline at end of file