Merge remote-tracking branch 'origin/MKDT_BIGCHART'
This commit is contained in:
@@ -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,165 @@ 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)
|
||||
/// <summary>
|
||||
/// This is a modified version of the above query. It uses a cookie collection that contains the datadome cookie.
|
||||
/// If this query starts to fail then you should try the query in developer tools in the chromium browser and capture the
|
||||
/// datadome value and update it here in the GetCookieCollection() below.
|
||||
/// </summary>
|
||||
/// <param name="symbol"></param>
|
||||
/// <param name="asOf"></param>
|
||||
/// <returns></returns>
|
||||
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
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Pricing for {0} is frozen.",symbol));
|
||||
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");
|
||||
strRequest = sb.ToString();
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"{strRequest}");
|
||||
|
||||
CookieCollection cookieCollection = GetCookieCollection("www.marketwatch.com");
|
||||
|
||||
httpNetResponse = HttpNetRequest.GetRequestNoEncodingV2(strRequest,cookieCollection,new Uri("https://www.marketwatch.com/investing"));
|
||||
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=\"table table--overflow align--center\"]");
|
||||
|
||||
if (null == tables || 0 == tables.Count) return null;
|
||||
HtmlNodeCollection rows = tables[0].SelectNodes(".//tr");
|
||||
if (rows.Count < 2) return null;
|
||||
HtmlNodeCollection data = rows[1].SelectNodes(".//td");
|
||||
if (data.Count != 6)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("The price retrieved for {0} does not contain the correct number of data elements (expected 6 data elements).", symbol));
|
||||
return null;
|
||||
}
|
||||
Price price = new Price();
|
||||
price.Source = Price.PriceSource.BigCharts;
|
||||
price.Symbol = symbol.ToUpper();
|
||||
String[] dateElements = data[0].InnerText.Trim().Split(" ");
|
||||
|
||||
price.Date = Utility.ParseDate(dateElements[0].Replace("\n",null));
|
||||
price.Open = Utility.ParseCurrency(data[1].InnerText.Trim().Replace("\n",null));
|
||||
price.High = Utility.ParseCurrency(data[2].InnerText.Trim().Replace("\n",null));
|
||||
price.Low = Utility.ParseCurrency(data[3].InnerText.Trim().Replace("\n",null));
|
||||
price.Close = price.AdjClose = Utility.ParseCurrency(data[4].InnerText.Trim().Replace("\n",null));
|
||||
price.Volume = FeedParser.ParseValueLong(data[5].InnerText.Trim());
|
||||
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 exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Exception : {0}", exception.ToString()));
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
private static CookieCollection GetCookieCollection(String cookieDomain)
|
||||
{
|
||||
String[] cookies = {
|
||||
"datadome=VLSWQ1PWL4SV2rljkJEV7GUOK3T11Sm73RP17IwDEtRzfWHykYwy7ZoeSPrjwmbwvGRAenazmLVTpyCB6Yqlw6vUL6Wbqq4zML5DGuHLxNU4LgAQ7Ko9tztglqjIGLZE",
|
||||
};
|
||||
CookieCollection cookieCollection = new CookieCollection();
|
||||
for (int index = 0; index < cookies.Count(); index++)
|
||||
{
|
||||
String strCookie = cookies[index];
|
||||
if (strCookie.EndsWith(";")) strCookie = strCookie.Substring(0, strCookie.Length - 1);
|
||||
String[] pairs = strCookie.Split('=');
|
||||
cookieCollection.Add(new Cookie()
|
||||
{
|
||||
Name = pairs[0],
|
||||
Value = pairs[1],
|
||||
Domain = cookieDomain
|
||||
});
|
||||
}
|
||||
return cookieCollection;
|
||||
}
|
||||
|
||||
//********************************************************************************************************************************************************************************************************
|
||||
// ******************************************************************************** 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;
|
||||
|
||||
Reference in New Issue
Block a user