CompanyProfile
This commit is contained in:
@@ -1542,55 +1542,74 @@ namespace MarketData.Helper
|
||||
if (null == companyProfile) companyProfile = GetCompanyProfileMorningStar(symbol, nyse);
|
||||
return companyProfile;
|
||||
}
|
||||
// GetCompanyProfile - DataSource Yahoo Finance
|
||||
|
||||
// GetCompanyProfile - DataSource Yahoo Finance
|
||||
public static CompanyProfile GetCompanyProfileYahoo(String symbol)
|
||||
{
|
||||
HttpNetResponse httpNetResponse=null;
|
||||
HttpNetResponse httpNetResponse = null;
|
||||
try
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String strRequest;
|
||||
symbol = symbol.ToUpper();
|
||||
|
||||
WebProxy webProxy=HttpNetRequest.GetProxy("GetCompanyProfileYahoo");
|
||||
WebProxy webProxy = HttpNetRequest.GetProxy("GetCompanyProfileYahoo");
|
||||
sb.Append("http://finance.yahoo.com/q/pr?s=").Append(symbol).Append("+Profile");
|
||||
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);
|
||||
String strIndustry=Sections.LocateItem(httpNetResponse.ResponseString,"Industry",4);
|
||||
String strSector=Sections.LocateItem(httpNetResponse.ResponseString,"Sector",4);
|
||||
if(null==strSector)strSector=Sections.LocateItem(httpNetResponse.ResponseString,"Sector(s)",4);
|
||||
|
||||
if(null!=strIndustry && strIndustry.Contains(Constants.CONST_QUESTION))strIndustry=strIndustry.Replace(Constants.CONST_QUESTION," - ");
|
||||
if(null!=strSector && strSector.Contains(Constants.CONST_QUESTION))strSector=strSector.Replace(Constants.CONST_QUESTION," - ");
|
||||
// Locate Industry
|
||||
String strIndustry = Sections.LocateItem(httpNetResponse.ResponseString, "Industry", 4);
|
||||
if(strIndustry == null)strIndustry = Sections.LocateItem(httpNetResponse.ResponseString, "Industry:??", 2);
|
||||
|
||||
String strDescription=Sections.LocateItem(httpNetResponse.ResponseString,"Description",4);
|
||||
if(null==strIndustry && null==strSector && null==strDescription)return null;
|
||||
// Locate Sector
|
||||
String strSector = Sections.LocateItem(httpNetResponse.ResponseString, "Sector", 4);
|
||||
if (null == strSector) strSector = Sections.LocateItem(httpNetResponse.ResponseString, "Sector(s)", 4);
|
||||
if(null == strSector) strSector = Sections.LocateItem(httpNetResponse.ResponseString, "Sector:??", 3);
|
||||
|
||||
if (null != strIndustry && strIndustry.Contains(Constants.CONST_QUESTION)) strIndustry = strIndustry.Replace(Constants.CONST_QUESTION, " - ");
|
||||
if (null != strSector && strSector.Contains(Constants.CONST_QUESTION)) strSector = strSector.Replace(Constants.CONST_QUESTION, " - ");
|
||||
|
||||
// Locate Description
|
||||
String strDescription = Sections.LocateItem(httpNetResponse.ResponseString, "Description", 4);
|
||||
if(null == strDescription)
|
||||
{
|
||||
List<int> indices = Sections.LocateAllOccurrences(httpNetResponse.ResponseString, "Description");
|
||||
if(indices.Count>0)
|
||||
{
|
||||
List<String> sections = Sections.GetSections(httpNetResponse.ResponseString);
|
||||
strDescription = Sections.GetFirstNonEmptyItemInSection(sections, indices[0]+1);
|
||||
}
|
||||
}
|
||||
|
||||
if (null == strIndustry && null == strSector && null == strDescription) return null;
|
||||
CompanyProfile companyProfile = new CompanyProfile();
|
||||
companyProfile.Symbol = symbol;
|
||||
companyProfile.Sector = strSector;
|
||||
companyProfile.Industry = strIndustry;
|
||||
companyProfile.Description=strDescription;
|
||||
if(null!=companyProfile.Sector)companyProfile.Sector=companyProfile.Sector.Trim();
|
||||
if(null!=companyProfile.Industry)companyProfile.Industry=companyProfile.Industry.Trim();
|
||||
if(null!=companyProfile.Description)companyProfile.Description=Utility.RemoveHtml(companyProfile.Description.Trim());
|
||||
companyProfile.Description = strDescription;
|
||||
if (null != companyProfile.Sector) companyProfile.Sector = companyProfile.Sector.Trim();
|
||||
if (null != companyProfile.Industry) companyProfile.Industry = companyProfile.Industry.Trim();
|
||||
if (null != companyProfile.Description) companyProfile.Description = Utility.RemoveHtml(companyProfile.Description.Trim());
|
||||
return companyProfile;
|
||||
}
|
||||
catch (Exception exception)
|
||||
} catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,exception);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, exception);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(null!=httpNetResponse)httpNetResponse.Dispose();
|
||||
if (null != httpNetResponse) httpNetResponse.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static CompanyProfile GetCompanyProfileMorningStar(String symbol,String exchange)
|
||||
{
|
||||
HttpNetResponse httpNetResponse=null;
|
||||
@@ -1603,7 +1622,9 @@ namespace MarketData.Helper
|
||||
sb.Append(String.Format("https://www.morningstar.com/stocks/{0}/{1}/quote",exchange,symbol));
|
||||
strRequest = sb.ToString();
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,strRequest);
|
||||
httpNetResponse = HttpNetRequest.GetRequestNoEncodingV4(strRequest);
|
||||
// httpNetResponse = HttpNetRequest.GetRequestNoEncodingV5(strRequest, 5000, webProxy);
|
||||
httpNetResponse = HttpNetRequest.GetRequestNoEncodingV5A(strRequest, 10000, webProxy);
|
||||
|
||||
if(!httpNetResponse.Success)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Request:{0} failed with status {1}",httpNetResponse.Request,httpNetResponse.StatusCode));
|
||||
@@ -1624,8 +1645,17 @@ namespace MarketData.Helper
|
||||
|
||||
found=Sections.FindInSections(sections,"Business Description",itemIndex,ref itemIndex);
|
||||
if(found)strDescription=sections[itemIndex+2];
|
||||
else
|
||||
{
|
||||
itemIndex=0;
|
||||
found=Sections.FindInSections(sections,"Company Profile",itemIndex,ref itemIndex);
|
||||
if(found)strDescription = Sections.GetFirstNonEmptyItemInSection(sections, itemIndex+1);
|
||||
}
|
||||
|
||||
if(null==strIndustry && null==strSector)return null;
|
||||
|
||||
if(null!=strDescription && strDescription.Equals("Description Information Not Available"))return null;
|
||||
|
||||
strSector=strSector.Trim();
|
||||
strIndustry=strIndustry.Trim();
|
||||
CompanyProfile companyProfile = new CompanyProfile();
|
||||
@@ -1637,9 +1667,14 @@ namespace MarketData.Helper
|
||||
if(null!=companyProfile.Industry)companyProfile.Industry=companyProfile.Industry.Trim();
|
||||
if(null!=strDescription)companyProfile.Description=companyProfile.Description.Trim();
|
||||
|
||||
if(null!=companyProfile.Industry && companyProfile.Industry.Contains(Constants.CONST_QUESTION))companyProfile.Industry=companyProfile.Industry.Replace(Constants.CONST_QUESTION," - ");
|
||||
if(null!=companyProfile.Sector && companyProfile.Sector.Contains(Constants.CONST_QUESTION))companyProfile.Sector=companyProfile.Sector.Replace(Constants.CONST_QUESTION," - ");
|
||||
// if(companyProfile.Sector.Equals(Constants.CONST_QUESTION) || companyProfile.Industry.Equals(Constants.CONST_QUESTION) || companyProfile.Description.Equals(Constants.CONST_QUESTION))return null;
|
||||
if(null!=companyProfile.Industry && companyProfile.Industry.Contains(Constants.CONST_QUESTION))
|
||||
{
|
||||
companyProfile.Industry=companyProfile.Industry.Replace(Constants.CONST_QUESTION," - ");
|
||||
}
|
||||
if(null!=companyProfile.Sector && companyProfile.Sector.Contains(Constants.CONST_QUESTION))
|
||||
{
|
||||
companyProfile.Sector=companyProfile.Sector.Replace(Constants.CONST_QUESTION," - ");
|
||||
}
|
||||
if((null!=companyProfile.Sector && companyProfile.Sector.Equals(Constants.CONST_QUESTION))
|
||||
|| (null!=companyProfile.Industry && companyProfile.Industry.Equals(Constants.CONST_QUESTION))
|
||||
|| (null!=companyProfile.Description && companyProfile.Description.Equals(Constants.CONST_QUESTION)))return null;
|
||||
@@ -2074,6 +2109,57 @@ namespace MarketData.Helper
|
||||
AnalystPriceTarget analystPriceTarget = GetAnalystPriceTargetMarketBeat(symbol);
|
||||
return analystPriceTarget;
|
||||
}
|
||||
|
||||
//public static AnalystPriceTarget GetAnalystPriceTargetMarketBeat(String symbol)
|
||||
//{
|
||||
// AnalystPriceTarget analystPriceTarget = null;
|
||||
// String nyse="NYSE";
|
||||
// String nasdaq="NASDAQ";
|
||||
|
||||
// try
|
||||
// {
|
||||
// HtmlNodeCollection table = GetMarketBeatAnalystPriceTargetTable(symbol, nasdaq);
|
||||
// if(null==table)table = GetMarketBeatAnalystPriceTargetTable(symbol, nyse);
|
||||
// if(null==table)return null;
|
||||
// HtmlNodeCollection headerColumns=table[0].SelectNodes(".//th");
|
||||
// HtmlNodeCollection dataColumns=table[0].SelectNodes(".//td");
|
||||
|
||||
|
||||
// analystPriceTarget=new AnalystPriceTarget();
|
||||
// analystPriceTarget.Symbol=symbol;
|
||||
// analystPriceTarget.Date=DateTime.Now.Date;
|
||||
// for(int index=0;index<headerColumns.Count;index++)
|
||||
// {
|
||||
// String forecastType = headerColumns[index].InnerText;
|
||||
// String forecastData = dataColumns[index].InnerText;
|
||||
|
||||
// if (forecastType.Equals("High Forecast"))
|
||||
// {
|
||||
// analystPriceTarget.HighTargetPrice = FeedParser.ParseValue(forecastData);
|
||||
// }
|
||||
// else if (forecastType.Equals("Average Forecast"))
|
||||
// {
|
||||
// analystPriceTarget.MeanTargetPrice = FeedParser.ParseValue(forecastData);
|
||||
// analystPriceTarget.MedianTargetPrice = analystPriceTarget.MeanTargetPrice;
|
||||
// }
|
||||
// else if (forecastType.Equals("Low Forecast"))
|
||||
// {
|
||||
// analystPriceTarget.LowTargetPrice = FeedParser.ParseValue(forecastData);
|
||||
// }
|
||||
// }
|
||||
|
||||
// if(double.IsNaN(analystPriceTarget.HighTargetPrice)&&
|
||||
// double.IsNaN(analystPriceTarget.MeanTargetPrice)&&
|
||||
// double.IsNaN(analystPriceTarget.LowTargetPrice)&&
|
||||
// double.IsNaN(analystPriceTarget.MedianTargetPrice))return null;
|
||||
// return analystPriceTarget;
|
||||
// }
|
||||
// catch (Exception exception)
|
||||
// {
|
||||
// MDTrace.WriteLine(LogLevel.DEBUG,exception);
|
||||
// return null;
|
||||
// }
|
||||
//}
|
||||
public static AnalystPriceTarget GetAnalystPriceTargetMarketBeat(String symbol)
|
||||
{
|
||||
AnalystPriceTarget analystPriceTarget = null;
|
||||
@@ -2085,29 +2171,28 @@ namespace MarketData.Helper
|
||||
HtmlNodeCollection table = GetMarketBeatAnalystPriceTargetTable(symbol, nasdaq);
|
||||
if(null==table)table = GetMarketBeatAnalystPriceTargetTable(symbol, nyse);
|
||||
if(null==table)return null;
|
||||
HtmlNodeCollection headerColumns=table[0].SelectNodes(".//th");
|
||||
HtmlNodeCollection dataColumns=table[0].SelectNodes(".//td");
|
||||
|
||||
HtmlNodeCollection rows=table[0].SelectNodes(".//tr");
|
||||
|
||||
if(null == rows || 0==rows.Count)return null;
|
||||
|
||||
analystPriceTarget=new AnalystPriceTarget();
|
||||
analystPriceTarget.Symbol=symbol;
|
||||
analystPriceTarget.Date=DateTime.Now.Date;
|
||||
for(int index=0;index<headerColumns.Count;index++)
|
||||
{
|
||||
String forecastType=headerColumns[index].InnerText;
|
||||
String forecastData=dataColumns[index].InnerText;
|
||||
|
||||
if(forecastType.Equals("High Forecast"))
|
||||
{
|
||||
analystPriceTarget.HighTargetPrice=FeedParser.ParseValue(forecastData);
|
||||
}
|
||||
else if(forecastType.Equals("Average Forecast"))
|
||||
{
|
||||
analystPriceTarget.MeanTargetPrice=FeedParser.ParseValue(forecastData);
|
||||
analystPriceTarget.MedianTargetPrice=analystPriceTarget.MeanTargetPrice;
|
||||
}
|
||||
else if(forecastType.Equals("Low Forecast"))
|
||||
{
|
||||
analystPriceTarget.LowTargetPrice=FeedParser.ParseValue(forecastData);
|
||||
}
|
||||
for(int rowIndex=0;rowIndex<rows.Count;rowIndex++)
|
||||
{
|
||||
HtmlNodeCollection data = rows[rowIndex].SelectNodes(".//td");
|
||||
|
||||
if(null == data || data.Count ==0 || !data[0].InnerText.Equals("Consensus Price Target"))continue;
|
||||
|
||||
analystPriceTarget.HighTargetPrice=
|
||||
analystPriceTarget.LowTargetPrice=
|
||||
analystPriceTarget.MeanTargetPrice=
|
||||
analystPriceTarget.MedianTargetPrice=
|
||||
FeedParser.ParseValue(data[1].InnerText);
|
||||
|
||||
break;
|
||||
}
|
||||
if(double.IsNaN(analystPriceTarget.HighTargetPrice)&&
|
||||
double.IsNaN(analystPriceTarget.MeanTargetPrice)&&
|
||||
@@ -2121,6 +2206,7 @@ namespace MarketData.Helper
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static HtmlNodeCollection GetMarketBeatAnalystPriceTargetTable(String symbol, String exchange)
|
||||
{
|
||||
MemoryStream memoryStream=null;
|
||||
@@ -2147,7 +2233,8 @@ namespace MarketData.Helper
|
||||
memoryStream = new MemoryStream(streamBytes);
|
||||
HtmlDocument htmlDocument = new HtmlDocument();
|
||||
htmlDocument.Load(memoryStream);
|
||||
HtmlNodeCollection table = htmlDocument.DocumentNode.SelectNodes("//*[@class=\"w-100 my-2\"]");
|
||||
// HtmlNodeCollection table = htmlDocument.DocumentNode.SelectNodes("//*[@class=\"w-100 my-2\"]");
|
||||
HtmlNodeCollection table = htmlDocument.DocumentNode.SelectNodes("//*[@id=\"consensus-table\"]");
|
||||
if(null==table || 1!=table.Count)
|
||||
{
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user