Eliminate TimeZoneInfo

This commit is contained in:
2025-04-16 22:24:31 -04:00
parent 97675da2b3
commit 449b3743a9
3 changed files with 102 additions and 111 deletions

View File

@@ -135,6 +135,7 @@ namespace MarketData.Services
public async Task TaskCalcSticker(CommandArgs commandArgs)
{
CalcSticker();
await Task.FromResult(true);
}
public async Task TaskUpdateHistorical(CommandArgs commandArgs)

View File

@@ -1,7 +1,6 @@
using MarketData.MarketDataModel;
using MarketData.DataAccess;
using MarketData.Utils;
using System.Net;
namespace MarketData.Helper
{
@@ -9,7 +8,6 @@ namespace MarketData.Helper
{
private DateTime pricingDate=DateTime.Parse("12-31-9999");
private DateTime? startDate;
private TimeZoneHelper timeZoneInfo;
public PricingThreadHelper(String symbol,ManualResetEvent resetEvent)
{
@@ -21,7 +19,6 @@ namespace MarketData.Helper
Symbol = symbol;
this.pricingDate=pricingDate;
ResetEvent = resetEvent;
timeZoneInfo=new TimeZoneHelper(pricingDate);
}
public PricingThreadHelper(String symbol, ManualResetEvent resetEvent,DateTime? startDate=null)
{
@@ -30,10 +27,6 @@ namespace MarketData.Helper
this.startDate=startDate;
ResetEvent = resetEvent;
}
public TimeZoneHelper TimeZoneInfo
{
get{return timeZoneInfo;}
}
public DateTime PricingDate
{
get{return pricingDate;}
@@ -114,7 +107,6 @@ namespace MarketData.Helper
symbols = PricingDA.GetSymbols();
currentIndex=0;
if(null==startDate)startDate=DateTime.Now;
TimeZoneHelper timeZoneHelper=new TimeZoneHelper(startDate.Value);
while (true)
{
List<String> queueSymbols = GetQueueSymbols();
@@ -148,7 +140,6 @@ namespace MarketData.Helper
symbols=PricingDA.GetSymbols();
currentIndex=0;
if(null==startDate) startDate=DateTime.Now;
TimeZoneHelper timeZoneHelper=new TimeZoneHelper(startDate.Value);
while(true)
{
List<String> queueSymbols=GetQueueSymbols();
@@ -182,7 +173,6 @@ namespace MarketData.Helper
symbols=PricingDA.GetSymbols();
currentIndex=0;
if(null==startDate) startDate=DateTime.Now;
TimeZoneHelper timeZoneHelper=new TimeZoneHelper(startDate.Value);
while(true)
{
List<String> queueSymbols=GetQueueSymbols();
@@ -467,7 +457,7 @@ namespace MarketData.Helper
try
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Load price (BigCharts), Thread {0} started for {1}...", Thread.CurrentThread.ManagedThreadId, pricingThreadHelper.Symbol));
UpdatePriceBigChartsEx(pricingThreadHelper.Symbol,pricingThreadHelper.TimeZoneInfo);
UpdatePriceBigChartsEx(pricingThreadHelper.Symbol,pricingThreadHelper.PricingDate);
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Load price (BigCharts), Thread {0} ended for {1}", Thread.CurrentThread.ManagedThreadId, pricingThreadHelper.Symbol));
}
finally
@@ -481,7 +471,7 @@ namespace MarketData.Helper
try
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Load price (Yahoo), Thread {0} started for {1}...",Thread.CurrentThread.ManagedThreadId,pricingThreadHelper.Symbol));
UpdatePriceYahoo(pricingThreadHelper.Symbol,pricingThreadHelper.TimeZoneInfo);
UpdatePriceYahoo(pricingThreadHelper.Symbol,pricingThreadHelper.PricingDate);
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Load price (Yahoo), Thread {0} ended for {1}",Thread.CurrentThread.ManagedThreadId,pricingThreadHelper.Symbol));
}
finally
@@ -495,7 +485,7 @@ namespace MarketData.Helper
try
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Load price (Yahoo), Thread {0} started for {1}...",Thread.CurrentThread.ManagedThreadId,pricingThreadHelper.Symbol));
UpdatePriceYahooSweep(pricingThreadHelper.Symbol,pricingThreadHelper.TimeZoneInfo);
UpdatePriceYahooSweep(pricingThreadHelper.Symbol,pricingThreadHelper.PricingDate);
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Load price (Yahoo), Thread {0} ended for {1}",Thread.CurrentThread.ManagedThreadId,pricingThreadHelper.Symbol));
}
finally
@@ -664,18 +654,18 @@ namespace MarketData.Helper
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
}
}
public static void UpdatePriceBigChartsEx(String symbol,TimeZoneHelper timeZoneInfo)
public static void UpdatePriceBigChartsEx(String symbol,DateTime pricingDate)
{
try
{
Price price=PricingDA.GetPrice(symbol,timeZoneInfo.StartDate);
Price price=PricingDA.GetPrice(symbol,pricingDate);
if(null!=price)
{
MDTrace.WriteLine(LogLevel.DEBUG,"Already have latest price for '" + symbol + "'");
return;
}
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Requesting price for {0} for start date:{1} end date:{2}",symbol,timeZoneInfo.StartDate,timeZoneInfo.StartDate));
Prices prices = MarketDataHelper.GetPricesAsOf(symbol, timeZoneInfo.StartDate,timeZoneInfo.StartDate);
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Requesting price for {0} for start date:{1} end date:{2}",symbol,pricingDate,pricingDate));
Prices prices = MarketDataHelper.GetPricesAsOf(symbol, pricingDate,pricingDate);
if (null == prices||0==prices.Count)
{
MDTrace.WriteLine(LogLevel.DEBUG,"No prices (GetPricesAsOf) for '" + symbol+ "'");
@@ -697,18 +687,18 @@ namespace MarketData.Helper
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception {0}",exception.ToString()));
}
}
public static void UpdatePriceYahoo(String symbol,TimeZoneHelper timeZoneInfo)
public static void UpdatePriceYahoo(String symbol,DateTime pricingDate)
{
try
{
Price price=PricingDA.GetPrice(symbol,timeZoneInfo.StartDate);
Price price=PricingDA.GetPrice(symbol,pricingDate);
if(null!=price)
{
MDTrace.WriteLine(LogLevel.DEBUG,"Already have latest price for '"+symbol+"'");
return;
}
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Requesting price for {0} for start date:{1} end date:{2}",symbol,timeZoneInfo.StartDate,timeZoneInfo.StartDate));
price=MarketDataHelper.GetDailyPrice(symbol,timeZoneInfo.StartDate);
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Requesting price for {0} for start date:{1} end date:{2}",symbol,pricingDate,pricingDate));
price=MarketDataHelper.GetDailyPrice(symbol,pricingDate);
if(null==price)
{
MDTrace.WriteLine(LogLevel.DEBUG,"No price (UpdatePriceYahoo) for '"+symbol+"'");
@@ -725,12 +715,12 @@ namespace MarketData.Helper
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception {0}",exception.ToString()));
}
}
public static void UpdatePriceYahooSweep(String symbol,TimeZoneHelper timeZoneInfo)
public static void UpdatePriceYahooSweep(String symbol,DateTime pricingDate)
{
try
{
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(symbol);
Price price=PricingDA.GetPrice(symbol,timeZoneInfo.StartDate);
Price price=PricingDA.GetPrice(symbol,pricingDate);
if(null!=price)
{
if(companyProfile==null || !companyProfile.PricingSourceEnum.Equals(CompanyProfile.EnumPricingSource.YAHOO))
@@ -739,8 +729,8 @@ namespace MarketData.Helper
return;
}
}
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("UpdatePriceYahooSweep: Requesting price for {0} for start date:{1} end date:{2}",symbol,timeZoneInfo.StartDate,timeZoneInfo.StartDate));
price=MarketDataHelper.GetDailyPrice(symbol,timeZoneInfo.StartDate);
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("UpdatePriceYahooSweep: Requesting price for {0} for start date:{1} end date:{2}",symbol,pricingDate,pricingDate));
price=MarketDataHelper.GetDailyPrice(symbol,pricingDate);
if(null==price)
{
MDTrace.WriteLine(LogLevel.DEBUG,"No price (UpdatePriceYahoo) for '"+symbol+"'");

View File

@@ -1,89 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MarketData.Utils;
using System.Collections.ObjectModel;
// using System;
// using System.Collections.Generic;
// using System.Linq;
// using System.Text;
// using System.Threading.Tasks;
// using MarketData.Utils;
// using System.Collections.ObjectModel;
namespace MarketData.Helper
{
public class TimeZoneHelper
{
private DateGenerator dateGenerator=new DateGenerator();
private DateTime startDate;
private DateTime endDate;
private DateTime prevBusinessDate;
private DateTime easternTime;
private TimeZoneInfo localZone = TimeZoneInfo.Local;
private TimeZone currentTimeZone=TimeZone.CurrentTimeZone;
private static TimeZoneInfo easternTimeZone = GetEasternTimeZone();
// namespace MarketData.Helper
// {
// public class TimeZoneHelper
// {
// private DateGenerator dateGenerator=new DateGenerator();
// private DateTime startDate;
// private DateTime endDate;
// private DateTime prevBusinessDate;
// private DateTime easternTime;
// private TimeZoneInfo localZone = TimeZoneInfo.Local;
// private TimeZone currentTimeZone=TimeZone.CurrentTimeZone;
// private static TimeZoneInfo easternTimeZone = GetEasternTimeZone();
public TimeZoneHelper()
{
startDate=DateTime.Now;
endDate = startDate; // the most recent date
prevBusinessDate=startDate;
prevBusinessDate = dateGenerator.GetPrevBusinessDay(endDate);
easternTime=new DateTime(prevBusinessDate.Year,prevBusinessDate.Month,prevBusinessDate.Day,20,30,0);
// public TimeZoneHelper()
// {
// startDate=DateTime.Now;
// endDate = startDate; // the most recent date
// prevBusinessDate=startDate;
// prevBusinessDate = dateGenerator.GetPrevBusinessDay(endDate);
// easternTime=new DateTime(prevBusinessDate.Year,prevBusinessDate.Month,prevBusinessDate.Day,20,30,0);
if(!currentTimeZone.DaylightName.Equals("Eastern Daylight Time")&&!currentTimeZone.DaylightName.Equals("Eastern Time (US & Canada)"))
{
easternTime=TimeZoneInfo.ConvertTimeToUtc(new DateTime(easternTime.Year,easternTime.Month,easternTime.Day,20,30,0),easternTimeZone);
}
if(prevBusinessDate.Equals(endDate)&&DateTime.Now.TimeOfDay<new TimeSpan(easternTime.Hour,easternTime.Minute,easternTime.Second))
{
prevBusinessDate=dateGenerator.FindPrevBusinessDay(prevBusinessDate);
}
}
public TimeZoneHelper(DateTime startDate)
{
this.startDate=startDate;
endDate = startDate; // the most recent date
prevBusinessDate=startDate;
prevBusinessDate = dateGenerator.GetPrevBusinessDay(endDate);
easternTime=new DateTime(prevBusinessDate.Year,prevBusinessDate.Month,prevBusinessDate.Day,20,30,0);
if(!currentTimeZone.DaylightName.Equals("Eastern Daylight Time")&&!currentTimeZone.DaylightName.Equals("Eastern Time (US & Canada)"))
{
easternTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(easternTime.Year, easternTime.Month, easternTime.Day, 20, 30, 0), easternTimeZone);
}
if(prevBusinessDate.Equals(endDate)&&DateTime.Now.TimeOfDay<new TimeSpan(easternTime.Hour,easternTime.Minute,easternTime.Second))
{
prevBusinessDate=dateGenerator.FindPrevBusinessDay(prevBusinessDate);
}
}
private static TimeZoneInfo GetEasternTimeZone()
{
TimeZoneInfo timeZoneInfo = null;
ReadOnlyCollection<TimeZoneInfo> timeZones;
timeZones= TimeZoneInfo.GetSystemTimeZones();
for (int index = 0; index < timeZones.Count; index++)
{
timeZoneInfo = timeZones[index];
if (timeZoneInfo.DisplayName.Equals("Eastern Daylight Time")||timeZoneInfo.DisplayName.Equals("Eastern Time (US & Canada)")||
timeZoneInfo.DaylightName.Equals("Eastern Daylight Time")||timeZoneInfo.StandardName.Equals("Eastern Standard Time")) break;
}
return timeZoneInfo;
}
public DateTime StartDate
{
get{return startDate;}
}
public DateTime EndDate
{
get{return endDate;}
}
public DateTime PrevBusinessDate
{
get{return prevBusinessDate;}
}
public DateTime EasternTime
{
get{return easternTime;}
}
public DateGenerator DateGenerator
{
get{return dateGenerator;}
}
}
}
// if(!currentTimeZone.DaylightName.Equals("Eastern Daylight Time")&&!currentTimeZone.DaylightName.Equals("Eastern Time (US & Canada)"))
// {
// easternTime=TimeZoneInfo.ConvertTimeToUtc(new DateTime(easternTime.Year,easternTime.Month,easternTime.Day,20,30,0),easternTimeZone);
// }
// if(prevBusinessDate.Equals(endDate)&&DateTime.Now.TimeOfDay<new TimeSpan(easternTime.Hour,easternTime.Minute,easternTime.Second))
// {
// prevBusinessDate=dateGenerator.FindPrevBusinessDay(prevBusinessDate);
// }
// }
// public TimeZoneHelper(DateTime startDate)
// {
// this.startDate=startDate;
// endDate = startDate; // the most recent date
// prevBusinessDate=startDate;
// prevBusinessDate = dateGenerator.GetPrevBusinessDay(endDate);
// easternTime=new DateTime(prevBusinessDate.Year,prevBusinessDate.Month,prevBusinessDate.Day,20,30,0);
// if(!currentTimeZone.DaylightName.Equals("Eastern Daylight Time")&&!currentTimeZone.DaylightName.Equals("Eastern Time (US & Canada)"))
// {
// easternTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(easternTime.Year, easternTime.Month, easternTime.Day, 20, 30, 0), easternTimeZone);
// }
// if(prevBusinessDate.Equals(endDate)&&DateTime.Now.TimeOfDay<new TimeSpan(easternTime.Hour,easternTime.Minute,easternTime.Second))
// {
// prevBusinessDate=dateGenerator.FindPrevBusinessDay(prevBusinessDate);
// }
// }
// private static TimeZoneInfo GetEasternTimeZone()
// {
// TimeZoneInfo timeZoneInfo = null;
// ReadOnlyCollection<TimeZoneInfo> timeZones;
// timeZones= TimeZoneInfo.GetSystemTimeZones();
// for (int index = 0; index < timeZones.Count; index++)
// {
// timeZoneInfo = timeZones[index];
// if (timeZoneInfo.DisplayName.Equals("Eastern Daylight Time")||timeZoneInfo.DisplayName.Equals("Eastern Time (US & Canada)")||
// timeZoneInfo.DaylightName.Equals("Eastern Daylight Time")||timeZoneInfo.StandardName.Equals("Eastern Standard Time")) break;
// }
// return timeZoneInfo;
// }
// public DateTime StartDate
// {
// get{return startDate;}
// }
// public DateTime EndDate
// {
// get{return endDate;}
// }
// public DateTime PrevBusinessDate
// {
// get{return prevBusinessDate;}
// }
// public DateTime EasternTime
// {
// get{return easternTime;}
// }
// public DateGenerator DateGenerator
// {
// get{return dateGenerator;}
// }
// }
// }