Merge MKDT_0002

This commit is contained in:
2025-10-01 20:51:03 -04:00
parent 5e27c13e5f
commit 5343f070c6
2 changed files with 194 additions and 45 deletions

View File

@@ -5240,23 +5240,29 @@ namespace MarketData.Helper
return prices;
}
/// <summary>
/// The main BigChart Feed which is no longer working
/// </summary>
/// <param name="symbol"></param>
/// <param name="asOf"></param>
/// <returns></returns>
public static Price GetPriceAsOf(String symbol, DateTime asOf)
{
HttpNetResponse httpNetResponse=null;
HttpNetResponse httpNetResponse = null;
try
{
String strRequest;
StringBuilder sb = null;
if (null == symbol) return null;
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(symbol);
if(null!=companyProfile && companyProfile.FreezePricing)
CompanyProfile companyProfile = CompanyProfileDA.GetCompanyProfile(symbol);
if (null != companyProfile && companyProfile.FreezePricing)
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Pricing for {0} is frozen.",symbol));
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Pricing for {0} is frozen.", symbol));
return null;
}
String requestSymbol=symbol;
if(requestSymbol.StartsWith("^"))requestSymbol=requestSymbol.Substring(1);
String requestSymbol = symbol;
if (requestSymbol.StartsWith("^")) requestSymbol = requestSymbol.Substring(1);
sb = new StringBuilder();
sb.Append("http://bigcharts.marketwatch.com/historical/default.asp?symb=");
sb.Append(requestSymbol);
@@ -5265,14 +5271,13 @@ namespace MarketData.Helper
sb.Append("%2F");
sb.Append(asOf.Day.ToString());
sb.Append("%2F");
sb.Append((asOf.Year-2000).ToString());
sb.Append((asOf.Year - 2000).ToString());
sb.Append("&x=38&y=25");
strRequest = sb.ToString();
httpNetResponse=HttpNetRequest.GetRequestNoEncoding(strRequest);
if(!httpNetResponse.Success)
httpNetResponse = HttpNetRequest.GetRequestNoEncoding(strRequest);
if (!httpNetResponse.Success)
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Request:{0} failed with status {1}",httpNetResponse.Request,httpNetResponse.StatusCode));
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Request:{0} failed with status {1}", httpNetResponse.Request, httpNetResponse.StatusCode));
return null;
}
byte[] streamBytes = Encoding.ASCII.GetBytes(httpNetResponse.ResponseString);
@@ -5283,51 +5288,137 @@ namespace MarketData.Helper
if (null == tables || 0 == tables.Count) return null;
HtmlNodeCollection rows = tables[0].SelectNodes(".//tr");
if (rows.Count < 7) return null;
Price price=new Price();
price.Source=Price.PriceSource.BigCharts;
Price price = new Price();
price.Source = Price.PriceSource.BigCharts;
price.Symbol = symbol.ToUpper();
price.Date=FeedParser.ParseValueDateTimeMonthFormatFromMarketWatch(rows[1].InnerText);
price.Close=FeedParser.ParseValueFromMarketWatch("Closing Price:",rows[2].InnerText);
price.Date = FeedParser.ParseValueDateTimeMonthFormatFromMarketWatch(rows[1].InnerText);
price.Close = FeedParser.ParseValueFromMarketWatch("Closing Price:", rows[2].InnerText);
price.AdjClose = price.Close;
price.Open = FeedParser.ParseValueFromMarketWatch("Open:", rows[3].InnerText);
price.High = FeedParser.ParseValueFromMarketWatch("High:", rows[4].InnerText);
price.Low = FeedParser.ParseValueFromMarketWatch("Low:", rows[5].InnerText);
price.Volume = FeedParser.ParseLongValueFromMarketWatch("Volume:", rows[6].InnerText);
if(!(price.Date.Date.Equals(asOf.Date.Date)))
if (!(price.Date.Date.Equals(asOf.Date.Date)))
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("The price retrieved for {0} does not contain the requested date. Requested date {1} Retrieved date {2}",symbol,price.Date.ToShortDateString(),asOf.ToShortDateString()));
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("The price retrieved for {0} does not contain the requested date. Requested date {1} Retrieved date {2}", symbol, price.Date.ToShortDateString(), asOf.ToShortDateString()));
return null;
}
return price;
}
catch(Exception)
catch (Exception)
{
return null;
}
finally
{
if(null!=httpNetResponse)httpNetResponse.Dispose();
if (null != httpNetResponse) httpNetResponse.Dispose();
}
}
//********************************************************************************************************************************************************************************************************
// ******************************************************************************** H I S T O R I C A L P R I C I N G Y A H O O *********************************************************************
//********************************************************************************************************************************************************************************************************
public static Price GetDailyPrice(String symbol,DateTime pricingDate)
public static Price GetPriceAsOfV2(String symbol, DateTime asOf)
{
if(null==symbol)return null;
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(symbol);
if(null!=companyProfile && companyProfile.FreezePricing)
HttpNetResponse httpNetResponse = null;
try
{
String strRequest;
StringBuilder sb = null;
if (null == symbol) return null;
CompanyProfile companyProfile = CompanyProfileDA.GetCompanyProfile(symbol);
if (null != companyProfile && companyProfile.FreezePricing)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Pricing for {0} is frozen.", symbol));
return null;
}
String requestSymbol = symbol;
if (requestSymbol.StartsWith("^")) requestSymbol = requestSymbol.Substring(1);
sb = new StringBuilder();
// sb.Append("http://bigcharts.marketwatch.com/historical/default.asp?symb=");
// sb.Append(requestSymbol);
// sb.Append("&closeDate=");
// sb.Append(asOf.Month.ToString());
// sb.Append("%2F");
// sb.Append(asOf.Day.ToString());
// sb.Append("%2F");
// sb.Append((asOf.Year - 2000).ToString());
// sb.Append("&x=38&y=25");0000000000000000000000000000000000000000
// strRequest = sb.ToString();
//https://www.marketwatch.com/investing/stock/TSCDY/download-data
sb.Append("https://www.marketwatch.com/investing/stock/").Append(symbol);
sb.Append("/downloaddatapartial?startdate=");
sb.Append(asOf.Month.ToString()).Append("/").Append(asOf.Day.ToString()).Append("/").Append(asOf.Year.ToString());
sb.Append("%2000:00:00&enddate=");
sb.Append(asOf.Month.ToString()).Append("/").Append(asOf.Day.ToString()).Append("/").Append(asOf.Year.ToString());
sb.Append("%2023:59:59&daterange=d30&frequency=p1d&csvdownload=true&downloadpartial=false&newdates=false");
strRequest = sb.ToString();
httpNetResponse = HttpNetRequest.GetRequestNoEncodingV2(strRequest);
if (!httpNetResponse.Success)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Request:{0} failed with status {1}", httpNetResponse.Request, httpNetResponse.StatusCode));
return null;
}
byte[] streamBytes = Encoding.ASCII.GetBytes(httpNetResponse.ResponseString);
MemoryStream memoryStream = new MemoryStream(streamBytes);
HtmlDocument htmlDocument = new HtmlDocument();
htmlDocument.Load(memoryStream);
HtmlNodeCollection tables = htmlDocument.DocumentNode.SelectNodes("//*[@class=\"historicalquote fatbottomed\"]");
if (null == tables || 0 == tables.Count) return null;
HtmlNodeCollection rows = tables[0].SelectNodes(".//tr");
if (rows.Count < 7) return null;
Price price = new Price();
price.Source = Price.PriceSource.BigCharts;
price.Symbol = symbol.ToUpper();
price.Date = FeedParser.ParseValueDateTimeMonthFormatFromMarketWatch(rows[1].InnerText);
price.Close = FeedParser.ParseValueFromMarketWatch("Closing Price:", rows[2].InnerText);
price.AdjClose = price.Close;
price.Open = FeedParser.ParseValueFromMarketWatch("Open:", rows[3].InnerText);
price.High = FeedParser.ParseValueFromMarketWatch("High:", rows[4].InnerText);
price.Low = FeedParser.ParseValueFromMarketWatch("Low:", rows[5].InnerText);
price.Volume = FeedParser.ParseLongValueFromMarketWatch("Volume:", rows[6].InnerText);
if (!(price.Date.Date.Equals(asOf.Date.Date)))
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("The price retrieved for {0} does not contain the requested date. Requested date {1} Retrieved date {2}", symbol, price.Date.ToShortDateString(), asOf.ToShortDateString()));
return null;
}
return price;
}
catch (Exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Pricing for {0} is frozen.",symbol));
return null;
}
Prices prices=GetDailyPrices(symbol,pricingDate,pricingDate);
if(null==prices||0==prices.Count)return null;
Price price=prices.FirstOrDefault();
if(!price.Date.Date.Equals(pricingDate.Date))
finally
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("GetDailyPrice: The pricing date returned for '{0}' was different than the date requested. Date requested '{1}', date returned '{2}'",symbol,pricingDate.ToShortDateString(),price.Date.Date.ToShortDateString()));
if (null != httpNetResponse) httpNetResponse.Dispose();
}
}
//********************************************************************************************************************************************************************************************************
// ******************************************************************************** H I S T O R I C A L P R I C I N G Y A H O O *********************************************************************
//********************************************************************************************************************************************************************************************************
public static Price GetDailyPrice(String symbol, DateTime pricingDate)
{
if (null == symbol) return null;
CompanyProfile companyProfile = CompanyProfileDA.GetCompanyProfile(symbol);
if (null != companyProfile && companyProfile.FreezePricing)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Pricing for {0} is frozen.", symbol));
return null;
}
Prices prices = GetDailyPrices(symbol, pricingDate, pricingDate);
if (null == prices || 0 == prices.Count) return null;
Price price = prices.FirstOrDefault();
if (!price.Date.Date.Equals(pricingDate.Date))
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("GetDailyPrice: The pricing date returned for '{0}' was different than the date requested. Date requested '{1}', date returned '{2}'", symbol, pricingDate.ToShortDateString(), price.Date.Date.ToShortDateString()));
return null;
}
return price;