Refactorings.
This commit is contained in:
@@ -52,176 +52,48 @@ namespace MarketData.Helper
|
||||
public static String SEC_BASE_URL="https://www.sec.gov";
|
||||
|
||||
|
||||
public static Dictionary<String,bool> RunTests()
|
||||
{
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
Dictionary<String,bool> items=new Dictionary<String,bool>();
|
||||
String symbol="MIDD";
|
||||
String dividendSymbol="AAPL";
|
||||
String insiderTransactionSymbol="AAVL";
|
||||
String etfSymbol="JFNNX";
|
||||
String analystPriceTargetSymbol="MGPI";
|
||||
String sourceCurrency="USD";
|
||||
DateTime analysisDate=dateGenerator.FindPrevBusinessDay(DateTime.Now);
|
||||
public static bool GetWorldTime()
|
||||
{
|
||||
HttpNetResponse httpNetResponse=null;
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetDividendHistory");
|
||||
DividendHistory dividendHistory=GetDividendHistory(dividendSymbol);
|
||||
if(null==dividendHistory||0==dividendHistory.Count)items.Add("GetDividendHistory",false);
|
||||
else items.Add("GetDividendHistory",true);
|
||||
try
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("https://www.timeanddate.com/worldclock/");
|
||||
String strRequest = sb.ToString();
|
||||
WebProxy webProxy=HttpNetRequest.GetProxy();
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("GetWorldTime:{0}",strRequest));
|
||||
httpNetResponse=HttpNetRequest.GetRequestNoEncodingV4A(strRequest, null, webProxy);
|
||||
if(!httpNetResponse.Success)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Request:{0} failed with status {1}",httpNetResponse.Request,httpNetResponse.StatusCode));
|
||||
return false;
|
||||
}
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetPremarketData");
|
||||
PremarketElements premarketElements=GetPremarketData();
|
||||
if(null==premarketElements||0==premarketElements.Count)items.Add("GetPremarketData",false);
|
||||
else items.Add("GetPremarketData",true);
|
||||
if(String.IsNullOrEmpty(httpNetResponse.ResponseString))
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("No data returned for request {0}",strRequest));
|
||||
return false;
|
||||
}
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetEarningsAnnouncements");
|
||||
EarningsAnnouncements earningsAnnouncements=GetEarningsAnnouncements(symbol);
|
||||
if(null==earningsAnnouncements||0==earningsAnnouncements.Count)items.Add("GetEarningsAnnouncements",false);
|
||||
else items.Add("GetEarningsAnnouncements",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetZacksRank");
|
||||
ZacksRank zacksRank=GetZacksRank(symbol);
|
||||
if(null==zacksRank)items.Add("GetZacksRank",false);
|
||||
else items.Add("GetZacksRank",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetSplits");
|
||||
Splits splits=GetSplits();
|
||||
if(null==splits)items.Add("GetSplits",false);
|
||||
else items.Add("GetSplits",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetGDPPerCapita");
|
||||
EconomicIndicators economicIndicators=GetGDPPerCapita();
|
||||
if(null==economicIndicators)items.Add("GetGDPPerCapita",false);
|
||||
else items.Add("GetGDPPerCapita",true);
|
||||
|
||||
//MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetOptions");
|
||||
//Options options=GetOptions(symbol);
|
||||
//if(null==options||0==options.Count) items.Add("GetOptions",false);
|
||||
//else items.Add("GetOptions",true);
|
||||
items.Add("GetOptions",false);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetLatestAnalystRatings");
|
||||
AnalystRatings analystRatings=GetLatestAnalystRatings();
|
||||
if(null==analystRatings||0==analystRatings.Count)items.Add("GetLatestAnalystRatings",false);
|
||||
else items.Add("GetLatestAnalystRatings",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetAnalystRatingsMarketBeat");
|
||||
analystRatings=GetAnalystRatingsMarketBeat(symbol);
|
||||
if(null==analystRatings||0==analystRatings.Count)items.Add("GetAnalystRatingsMarketBeat",false);
|
||||
else items.Add("GetAnalystRatingsMarketBeat",true);;
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetCIK");
|
||||
String strCik=GetCIK(symbol);
|
||||
if(null==strCik)items.Add("GetCIK",false);
|
||||
else items.Add("GetCIK",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetSECFilings");
|
||||
String cik=PricingDA.GetCIKForSymbol(symbol);
|
||||
SECFilings secFilings=GetSECFilings(symbol,cik);
|
||||
if(null==secFilings||0==secFilings.Count)items.Add("GetSECFilings",false);
|
||||
else items.Add("GetSECFilings",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetYieldCurve");
|
||||
YieldCurve yieldCurve=GetYieldCurve(analysisDate.Year);
|
||||
if(null==yieldCurve||0==yieldCurve.Count)items.Add("GetYieldCurve",false);
|
||||
else items.Add("GetYieldCurve",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetETFHoldings");
|
||||
ETFHoldings etfHoldings=GetETFHoldings(etfSymbol);
|
||||
if(null==etfHoldings||0==etfHoldings.Count)items.Add("GetETFHoldings",false);
|
||||
else items.Add("GetETFHoldings",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetInsiderTransactions");
|
||||
InsiderTransactions insiderTransactions=GetInsiderTransactions(insiderTransactionSymbol);
|
||||
if(null==insiderTransactions||0==insiderTransactions.Count)items.Add("GetInsiderTransactions",false);
|
||||
else items.Add("GetInsiderTransactions",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetCompanyProfile");
|
||||
CompanyProfile companyProfile=GetCompanyProfile(symbol);
|
||||
if(null==companyProfile)items.Add("GetCompanyProfile",false);
|
||||
else items.Add("GetCompanyProfile",true);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("GetWorldTime Received {0} bytes of data.",httpNetResponse.ResponseString.Length));
|
||||
|
||||
|
||||
//MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetCompanyDescription");
|
||||
//String companyDescription=GetCompanyDescription(symbol);
|
||||
//if(null==companyDescription)items.Add("GetCompanyDescription",false);
|
||||
//else items.Add("GetCompanyDescription",true);
|
||||
return true;
|
||||
|
||||
Headlines headlines=HeadlinesMarketDataHelper.GetHeadlinesEx(symbol);
|
||||
if(null==headlines || 0==headlines.Count)items.Add("GetHeadlines",false);
|
||||
else items.Add("GetHeadlines",true);
|
||||
|
||||
//MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetAnalystPriceTargetYahoo");
|
||||
//AnalystPriceTarget analystPriceTarget=GetAnalystPriceTargetYahoo(analystPriceTargetSymbol);
|
||||
//if(null==analystPriceTarget)items.Add("GetAnalystPriceTargetYahoo",false);
|
||||
//else items.Add("GetAnalystPriceTargetYahoo",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetAnalystPriceTargetMarketBeat");
|
||||
AnalystPriceTarget analystPriceTarget=GetAnalystPriceTargetMarketBeat(analystPriceTargetSymbol);
|
||||
if(null==analystPriceTarget)items.Add("GetAnalystPriceTargetYahoo",false);
|
||||
else items.Add("GetAnalystPriceTargetMarketBeat",true);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,exception);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(null!=httpNetResponse)httpNetResponse.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetHistoricalValues");
|
||||
Dictionary<TimeSeriesElement.ElementType, TimeSeriesCollection> timeSeries=GetHistoricalValues(symbol);
|
||||
if(null==timeSeries)items.Add("GetHistoricalValues",false);
|
||||
else items.Add("GetHistoricalValues",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetIncomeStatement");
|
||||
List<IncomeStatement> incomeStatement=GetIncomeStatement(symbol,IncomeStatement.PeriodType.Annual);
|
||||
if(null==incomeStatement||0==incomeStatement.Count)items.Add("GetIncomeStatement",false);
|
||||
else items.Add("GetIncomeStatement",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetBalanceSheetNASDAQ");
|
||||
List<BalanceSheet> balanceSheet=GetBalanceSheetNASDAQ(symbol,BalanceSheet.PeriodType.Annual);
|
||||
if(null==balanceSheet||0==balanceSheet.Count)items.Add("GetBalanceSheetNASDAQ",false);
|
||||
else items.Add("GetBalanceSheetNASDAQ",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetCashflowStatement");
|
||||
List<CashflowStatement> cashflowStatement=GetCashflowStatement(symbol,CashflowStatement.PeriodType.Annual);
|
||||
if(null==cashflowStatement||0==cashflowStatement.Count)items.Add("GetCashflowStatement",false);
|
||||
else items.Add("GetCashflowStatement",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetCurrencyConversion");
|
||||
CurrencyConversionCollection currencyConversionCollection=GetCurrencyConversion(sourceCurrency,analysisDate);
|
||||
if(null==currencyConversionCollection||0==currencyConversionCollection.Count)items.Add("GetCurrencyConversion",false);
|
||||
else items.Add("GetCurrencyConversion",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetFundamentalFinViz");
|
||||
Fundamental fundamental=GetFundamentalFinViz(symbol);
|
||||
if(null==fundamental)items.Add("GetFundamentalFinViz",false);
|
||||
else items.Add("GetFundamentalFinViz",true);
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Testing GetFundamental");
|
||||
fundamental=GetFundamental(symbol);
|
||||
if(null==fundamental)items.Add("GetFundamental",false);
|
||||
else items.Add("GetFundamental",true);
|
||||
|
||||
fundamental=FundamentalDA.GetFundamental(symbol);
|
||||
if(!PopulateKeyStatistics(fundamental))items.Add("PopulateKeyStatistics",false);
|
||||
else items.Add("PopulateKeyStatistics",true);
|
||||
|
||||
if(!PopulateFinancials(fundamental))items.Add("PopulateFinancials",false);
|
||||
else items.Add("PopulateFinancials",true);
|
||||
|
||||
Price price=GetLatestPriceYahoo(symbol);
|
||||
if(null==price)items.Add("GetLatestPriceYahoo",false);
|
||||
else items.Add("GetLatestPriceYahoo",true);
|
||||
|
||||
price=GetLatestPriceBigCharts(symbol);
|
||||
if(null==price)items.Add("GetLatestPriceBigCharts",false);
|
||||
else items.Add("GetLatestPriceBigCharts",true);
|
||||
|
||||
price=GetPriceAsOf(symbol,analysisDate);
|
||||
if(null==price)items.Add("GetPriceAsOf",false);
|
||||
else items.Add("GetPriceAsOf",true);
|
||||
|
||||
Prices prices=GetDailyPrices(symbol,analysisDate,analysisDate);
|
||||
if(null==prices||0==prices.Count)items.Add("GetDailyPrices",false);
|
||||
else items.Add("GetDailyPrices",true);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
// ******************************************************************************************************************************************************************************
|
||||
// ************************************************************************************ P R E M A R K E T D A T A ***********************************************************
|
||||
@@ -1528,67 +1400,6 @@ namespace MarketData.Helper
|
||||
// ***************************************************************************************************************************************************************************************
|
||||
// ********************************************************************** E T F H O L D I N G S - Y A H O O F I N A N C E *********************************************************
|
||||
// ***************************************************************************************************************************************************************************************
|
||||
//public static ETFHoldings GetETFHoldings(String etfSymbol)
|
||||
//{
|
||||
// MemoryStream memoryStream = null;
|
||||
// ETFHoldings etfHoldings = new ETFHoldings();
|
||||
// HttpNetResponse httpNetResponse=null;
|
||||
// DateTime modified=DateTime.Now;
|
||||
|
||||
// try
|
||||
// {
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// String strRequest;
|
||||
// etfSymbol = etfSymbol.ToUpper();
|
||||
// sb.Append("http://finance.yahoo.com/q/hl?s=").Append(etfSymbol).Append("+Holdings");
|
||||
// strRequest = sb.ToString();
|
||||
|
||||
// WebProxy webProxy=HttpNetRequest.GetProxy("GetETFHoldings");
|
||||
// MDTrace.WriteLine(LogLevel.DEBUG,String.Format("GetETFHoldings:{0}",strRequest));
|
||||
// httpNetResponse=HttpNetRequest.GetRequestNoEncodingV5A(strRequest,DEFAULT_TIMEOUT_MS,webProxy);
|
||||
// if(!httpNetResponse.Success)
|
||||
// {
|
||||
// MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Request:{0} failed with status {1}",httpNetResponse.Request,httpNetResponse.StatusCode));
|
||||
// return null;
|
||||
// }
|
||||
// String strResponse=Utility.KeepAfter(httpNetResponse.ResponseString,"/* -- Data -- */");
|
||||
// strResponse=Utility.KeepAfterLast(strResponse,"\"holdings\"");
|
||||
// List<List<String>> items=LocateJSONItems(strResponse);
|
||||
// if(null==items||0==items.Count)return null;
|
||||
// for(int index=0;index<items.Count;index+=3)
|
||||
// {
|
||||
// if(index+3>items.Count)break;
|
||||
// List<String> symbolPair=items[index];
|
||||
// List<String> holdingNamePair=items[index+1];
|
||||
// List<String> percentOfAssetsPair=items[index+2];
|
||||
// if(!symbolPair[0].Equals("symbol"))continue;
|
||||
// if(!holdingNamePair[0].Equals("holdingName"))continue;
|
||||
// if(!percentOfAssetsPair[0].Equals("fmt"))continue;
|
||||
// if(String.IsNullOrEmpty(symbolPair[1]))continue;
|
||||
// ETFHolding etfHolding = new ETFHolding();
|
||||
// etfHolding.ETFSymbol = etfSymbol;
|
||||
// etfHolding.HoldingSymbolShareClass=null;
|
||||
// etfHolding.HoldingCompanyName=holdingNamePair[1];
|
||||
// etfHolding.HoldingSymbolShareClass=symbolPair[1];
|
||||
// etfHolding.HoldingSymbol=symbolPair[1];
|
||||
// etfHolding.PercentOfAssets=FeedParser.ParseValue(percentOfAssetsPair[1]);
|
||||
// etfHolding.Modified=modified;
|
||||
// etfHoldings.Add(etfHolding);
|
||||
// }
|
||||
// return etfHoldings;
|
||||
// }
|
||||
// catch (Exception exception)
|
||||
// {
|
||||
// MDTrace.WriteLine(LogLevel.DEBUG,exception);
|
||||
// return null;
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// if (null != memoryStream) memoryStream.Close();
|
||||
// if(null!=httpNetResponse)httpNetResponse.Dispose();
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
public static ETFHoldings GetETFHoldings(String etfSymbol)
|
||||
{
|
||||
@@ -1596,6 +1407,7 @@ namespace MarketData.Helper
|
||||
ETFHoldings etfHoldings = new ETFHoldings();
|
||||
HttpNetResponse httpNetResponse=null;
|
||||
DateTime modified=DateTime.Now;
|
||||
int TIMEOUT_MS=1000*30;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -1607,8 +1419,7 @@ namespace MarketData.Helper
|
||||
|
||||
WebProxy webProxy=HttpNetRequest.GetProxy("GetETFHoldings");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("GetETFHoldings:{0}",strRequest));
|
||||
httpNetResponse=HttpNetRequest.GetRequestNoEncodingV3C(strRequest,webProxy);
|
||||
// httpNetResponse=HttpNetRequest.GetRequestNoEncodingV5A(strRequest,DEFAULT_TIMEOUT_MS,webProxy);
|
||||
httpNetResponse=HttpNetRequest.GetRequestNoEncodingV5(strRequest,TIMEOUT_MS , webProxy);
|
||||
if(!httpNetResponse.Success)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Request:{0} failed with status {1}",httpNetResponse.Request,httpNetResponse.StatusCode));
|
||||
@@ -1616,7 +1427,17 @@ namespace MarketData.Helper
|
||||
}
|
||||
|
||||
List<String> sections = Sections.GetAllItemsInSections(httpNetResponse.ResponseString,"table");
|
||||
if(null == sections || 0==sections.Count)return null;
|
||||
if(null == sections || 1!=sections.Count)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"GetETFHoldings: Unexpected items in section");
|
||||
return null;
|
||||
}
|
||||
String marker="<table class=\"W(100%) M(0) BdB Bdc($seperatorColor)";
|
||||
if(!sections[0].StartsWith(marker))
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("GetETFHoldings: Expected marker {0}",marker));
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] streamBytes=Encoding.ASCII.GetBytes(sections[0]);
|
||||
memoryStream=new MemoryStream(streamBytes);
|
||||
@@ -1631,8 +1452,10 @@ namespace MarketData.Helper
|
||||
etfHolding.ETFSymbol = etfSymbol;
|
||||
etfHolding.HoldingSymbolShareClass = null;
|
||||
etfHolding.HoldingCompanyName = rows[rowIndex].InnerText;
|
||||
etfHolding.HoldingSymbolShareClass = rows[rowIndex+1].InnerText;
|
||||
etfHolding.HoldingSymbol = rows[rowIndex+1].InnerText;
|
||||
etfHolding.HoldingSymbol = etfHolding.HoldingSymbolShareClass = rows[rowIndex+1].InnerText;
|
||||
if(null == etfHolding.HoldingSymbol ||
|
||||
"N/A".Equals(etfHolding.HoldingSymbol) ||
|
||||
"".Equals(etfHolding.HoldingSymbol))continue;
|
||||
etfHolding.PercentOfAssets = FeedParser.ParseValue(rows[rowIndex+2].InnerText);
|
||||
etfHolding.Modified = modified;
|
||||
etfHoldings.Add(etfHolding);
|
||||
@@ -2103,7 +1926,7 @@ namespace MarketData.Helper
|
||||
}
|
||||
}
|
||||
// ***************************************************************************************************************************************************************************
|
||||
// ************************************ A N A L Y S T P R I C E T A R G E T - Y A H O O F I N A N C E / M A R K E T B E A T (B A C K U P )******************************
|
||||
// ******************************************************** A N A L Y S T P R I C E T A R G E T - M A R K E T B E A T ***************************************************
|
||||
// ***************************************************************************************************************************************************************************
|
||||
public static AnalystPriceTarget GetAnalystPriceTarget(String symbol)
|
||||
{
|
||||
@@ -4575,6 +4398,7 @@ namespace MarketData.Helper
|
||||
public static Fundamental GetFundamentalEx(String symbol)
|
||||
{
|
||||
HttpNetResponse httpNetResponse=null;
|
||||
int TIMEOUT_MS=1000*30;
|
||||
try
|
||||
{
|
||||
Fundamental fundamental = new Fundamental();
|
||||
@@ -4585,8 +4409,9 @@ namespace MarketData.Helper
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("GetFundamental {0}",strRequest));
|
||||
WebProxy webProxy=HttpNetRequest.GetProxy("GetFundamentalEx");
|
||||
// httpNetResponse=HttpNetRequest.GetRequestNoEncoding(strRequest,webProxy);
|
||||
httpNetResponse=HttpNetRequest.GetRequestNoEncodingV3C(strRequest,webProxy); // user agents refreshed in this version
|
||||
// httpNetResponse=HttpNetRequest.GetRequestNoEncodingV3C(strRequest,webProxy); // user agents refreshed in this version
|
||||
//MDTrace.WriteLine(LogLevel.DEBUG,String.Format("{0}:{1}",(int)httpNetResponse.StatusCode,httpNetResponse.StatusCode));
|
||||
httpNetResponse=HttpNetRequest.GetRequestNoEncodingV5(strRequest,TIMEOUT_MS, webProxy); // user agents refreshed in this version
|
||||
if(!httpNetResponse.Success)
|
||||
{
|
||||
sb=new StringBuilder();
|
||||
@@ -4735,7 +4560,7 @@ namespace MarketData.Helper
|
||||
public static Price GetLatestPrice(String symbol)
|
||||
{
|
||||
DateTime currentMarketDate=PremarketDA.GetLatestMarketDate();
|
||||
LatestPriceDelegate[] latestPriceDelegates=new LatestPriceDelegate[]{GetLatestPriceYahoo,GetLatestPriceBigCharts,GetLatestPriceFidelity};
|
||||
LatestPriceDelegate[] latestPriceDelegates=new LatestPriceDelegate[]{GetLatestPriceYahoo,GetLatestPriceBigCharts,GetLatestPriceGoogle};
|
||||
Price latestPrice=null;
|
||||
foreach(LatestPriceDelegate latestPriceDelegate in latestPriceDelegates)
|
||||
{
|
||||
@@ -5122,114 +4947,87 @@ namespace MarketData.Helper
|
||||
if(null!=memoryStream){memoryStream.Close();memoryStream.Dispose();}
|
||||
}
|
||||
}
|
||||
// Intraday Pricing from Fidelity - which is being tested 07/22/2021
|
||||
// This is being used in the intra-day price feed.
|
||||
public static Price GetLatestPriceFidelity(String symbol)
|
||||
|
||||
public static Price GetLatestPriceGoogle(String symbol)
|
||||
{
|
||||
HttpNetResponse httpNetResponse=null;
|
||||
MemoryStream memoryStream=null;
|
||||
try
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String strRequest;
|
||||
if(null==symbol) return null;
|
||||
sb.Append("https://quotes.fidelity.com/webxpress/get_quote?QUOTE_TYPE=D&SID_VALUE_ID=").Append(symbol).Append("&submit=Quote");
|
||||
strRequest = sb.ToString();
|
||||
String exchangeNASDAQ="NASDAQ";
|
||||
String exchangeNYSE="NYSE";
|
||||
|
||||
WebProxy webProxy=HttpNetRequest.GetProxy("GetLatestPriceFidelity");
|
||||
httpNetResponse=HttpNetRequest.GetRequestNoEncodingV1(strRequest);
|
||||
sb = new StringBuilder();
|
||||
sb.Append("https://www.google.com/finance/quote/").Append(symbol).Append(":").Append(exchangeNASDAQ);
|
||||
strRequest = sb.ToString();
|
||||
WebProxy webProxy=HttpNetRequest.GetProxy("GetLatestPriceGoogle");
|
||||
httpNetResponse=HttpNetRequest.GetRequestNoEncodingV3C(strRequest, webProxy);
|
||||
if(!httpNetResponse.Success)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Request:{0} failed with status {1}",httpNetResponse.Request,httpNetResponse.StatusCode));
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> divSections = Sections.GetAllItemsInSections(httpNetResponse.ResponseString,"div");
|
||||
if(null==divSections || 0==divSections.Count)return null;
|
||||
List<String> searchPattern = divSections.Where(x => x.Contains("We couldn't find any match for your search.")).ToList();
|
||||
if(null!=searchPattern && searchPattern.Count>0)
|
||||
{
|
||||
httpNetResponse.Dispose();
|
||||
sb = new StringBuilder();
|
||||
sb.Append("https://www.google.com/finance/quote/").Append(symbol).Append(":").Append(exchangeNYSE);
|
||||
strRequest = sb.ToString();
|
||||
httpNetResponse=HttpNetRequest.GetRequestNoEncodingV3C(strRequest, webProxy);
|
||||
if(!httpNetResponse.Success)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Request:{0} failed with status {1}",httpNetResponse.Request,httpNetResponse.StatusCode));
|
||||
return null;
|
||||
}
|
||||
divSections = Sections.GetAllItemsInSections(httpNetResponse.ResponseString,"div");
|
||||
searchPattern = divSections.Where(x => x.Contains("We couldn't find any match for your search.")).ToList();
|
||||
if(null!=searchPattern && searchPattern.Count>0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
List<String> sections = Sections.GetSections(httpNetResponse.ResponseString);
|
||||
sections = Sections.FlattenSection(sections);
|
||||
|
||||
int index=0;
|
||||
|
||||
Price price = new Price();
|
||||
price.Symbol = symbol.ToUpper();
|
||||
price.Source=Price.PriceSource.Fidelity;
|
||||
price.Source=Price.PriceSource.Google;
|
||||
price.Close=price.Open=price.High=price.Low=price.AdjClose=double.NaN;
|
||||
price.Open=0.00;
|
||||
price.Date = DateTime.Now;
|
||||
byte[] streamBytes = Encoding.ASCII.GetBytes(httpNetResponse.ResponseString);
|
||||
memoryStream = new MemoryStream(streamBytes);
|
||||
HtmlDocument htmlDocument = new HtmlDocument();
|
||||
htmlDocument.Load(memoryStream);
|
||||
HtmlNodeCollection table = htmlDocument.DocumentNode.SelectNodes("//*[@class=\"quotesDetailsTable\"]");
|
||||
if(null==table||0==table.Count)return null;
|
||||
|
||||
HtmlNodeCollection rows = table[0].SelectNodes(".//tr");
|
||||
if(null==rows || 0==rows.Count)return null;
|
||||
double bid=double.NaN;
|
||||
double ask=double.NaN;
|
||||
for(int rowIndex=0;rowIndex<rows.Count;rowIndex++)
|
||||
{
|
||||
int itemIndex;
|
||||
List<String> sections=Sections.GetSections(rows[rowIndex].InnerHtml);
|
||||
if(null==sections || 0==sections.Count)continue;
|
||||
if(Sections.FindInSections(sections, "After Hours:", 0,ref index, true))
|
||||
{
|
||||
price.Close=price.AdjClose=FeedParser.ParseValue(sections[index-1]);
|
||||
}
|
||||
else if(Sections.FindInSections(sections, "Share", 0,ref index, true))
|
||||
{
|
||||
price.Close=price.AdjClose=FeedParser.ParseValue(sections[index+1]);
|
||||
}
|
||||
|
||||
itemIndex=sections.FindIndex(delegate(string str){return str.StartsWith("As of:");});
|
||||
if(-1!=itemIndex)
|
||||
{
|
||||
String strDate=Utility.BetweenString(sections[itemIndex],":",",");
|
||||
if(null==strDate)continue;
|
||||
{
|
||||
strDate=strDate.Trim();
|
||||
price.Date=Utility.ParseDate(strDate);
|
||||
}
|
||||
}
|
||||
itemIndex=sections.IndexOf("Last Trade [tick]");
|
||||
if(-1!=itemIndex)
|
||||
{
|
||||
price.Close=FeedParser.ParseValue(sections[itemIndex+2]);
|
||||
}
|
||||
itemIndex=sections.IndexOf("Volume");
|
||||
if(-1!=itemIndex)
|
||||
{
|
||||
price.Volume=FeedParser.ParseValueLong(sections[itemIndex+2]);
|
||||
}
|
||||
itemIndex=sections.IndexOf("Bid");
|
||||
if(-1!=itemIndex)
|
||||
{
|
||||
bid=FeedParser.ParseValue(sections[itemIndex+2]);
|
||||
}
|
||||
itemIndex=sections.IndexOf("Ask");
|
||||
if(-1!=itemIndex)
|
||||
{
|
||||
ask=FeedParser.ParseValue(sections[itemIndex+2]);
|
||||
}
|
||||
itemIndex=sections.IndexOf("Open");
|
||||
if(-1!=itemIndex)
|
||||
{
|
||||
price.Open=FeedParser.ParseValue(sections[itemIndex+2]);
|
||||
}
|
||||
itemIndex=sections.IndexOf("Day High");
|
||||
if(-1!=itemIndex)
|
||||
{
|
||||
price.High=FeedParser.ParseValue(sections[itemIndex+2]);
|
||||
}
|
||||
itemIndex=sections.IndexOf("Day Low");
|
||||
if(-1!=itemIndex)
|
||||
{
|
||||
price.Low=FeedParser.ParseValue(sections[itemIndex+2]);
|
||||
}
|
||||
}
|
||||
if((double.IsNaN(price.Close) || 0==price.Close) && !double.IsNaN(bid) && !double.IsNaN(ask))
|
||||
{
|
||||
price.Close=(bid+ask)/2.00;
|
||||
}
|
||||
if(0!=price.Close && 0==price.Open && 0==price.High && 0==price.Low)
|
||||
{
|
||||
price.Open=price.High=price.Low=price.Close;
|
||||
}
|
||||
price.AdjClose=price.Close;
|
||||
if(double.IsNaN(price.Open))price.Open=0.00;
|
||||
if(double.IsNaN(price.Low))price.Low=0.00;
|
||||
if(double.IsNaN(price.High))price.High=0.00;
|
||||
if(double.IsNaN(price.Open)&&double.IsNaN(price.High)&&double.IsNaN(price.Low)&&double.IsNaN(price.Close))
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("*** No closing price for {0}",price.Symbol));
|
||||
return null;
|
||||
}
|
||||
if(!price.IsValid)return null;
|
||||
return price;
|
||||
if(Sections.FindInSections(sections, "Previous close", 0,ref index, true))
|
||||
{
|
||||
price.Open=FeedParser.ParseValue(sections[index+2]);
|
||||
}
|
||||
|
||||
if(Sections.FindInSections(sections, "Day range", 0,ref index, true))
|
||||
{
|
||||
String itemValue = sections[index+2];
|
||||
String[] highLow = itemValue.Split('-');
|
||||
price.Low=FeedParser.ParseValue(highLow[0]);
|
||||
price.High=FeedParser.ParseValue(highLow[1]);
|
||||
}
|
||||
if(!price.IsValid)return null;
|
||||
return price;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -5239,9 +5037,9 @@ namespace MarketData.Helper
|
||||
finally
|
||||
{
|
||||
if(null!=httpNetResponse)httpNetResponse.Dispose();
|
||||
if(null!=memoryStream){memoryStream.Close();memoryStream.Dispose();}
|
||||
}
|
||||
}
|
||||
|
||||
// *******************************************************************************************************************************************************************************
|
||||
// *******************************************************************************************************************************************************************************
|
||||
// *******************************************************************************************************************************************************************************
|
||||
@@ -5477,26 +5275,10 @@ namespace MarketData.Helper
|
||||
// ****************************************************************************************************************************************************************************************
|
||||
// **************************************************************************** E N D D A T A F E E D S *********************************************************************************
|
||||
// ****************************************************************************************************************************************************************************************
|
||||
// ****************************************************************************************************************************************************************************************
|
||||
// **************************************************************************** H E L P E R M E T H O D S *******************************************************************************
|
||||
// ****************************************************************************************************************************************************************************************
|
||||
private static void WriteNodeToDisk(HtmlNodeCollection rows,String strPathFileName)
|
||||
{
|
||||
StreamWriter streamWriter = File.CreateText(strPathFileName + ".txt");
|
||||
for (int row = 0; row < rows.Count; row++)
|
||||
{
|
||||
streamWriter.WriteLine("row="+row.ToString()+", InnerHtml="+rows[row].InnerHtml);
|
||||
}
|
||||
streamWriter.Flush();
|
||||
streamWriter.Close();
|
||||
}
|
||||
private static void WriteToDisk(String responseString, String strPathFileName)
|
||||
{
|
||||
StreamWriter streamWriter = File.CreateText(strPathFileName);
|
||||
streamWriter.WriteLine(responseString);
|
||||
streamWriter.Flush();
|
||||
streamWriter.Close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ***************************************************************************************************************************************************************************************
|
||||
// ***************************************************************************************************************************************************************************************
|
||||
// ***************************************************************************************************************************************************************************************
|
||||
@@ -5635,5 +5417,39 @@ namespace MarketData.Helper
|
||||
if(referenceDate>DateTime.Now)referenceDate=Utility.Epoch;
|
||||
return referenceDate;
|
||||
}
|
||||
|
||||
// ****************************************************************************************************************************************************************************************
|
||||
// **************************************************************************** H E L P E R M E T H O D S *******************************************************************************
|
||||
// ****************************************************************************************************************************************************************************************
|
||||
private static void WriteNodeToDisk(HtmlNodeCollection rows,String strPathFileName)
|
||||
{
|
||||
StreamWriter streamWriter = File.CreateText(strPathFileName + ".txt");
|
||||
for (int row = 0; row < rows.Count; row++)
|
||||
{
|
||||
streamWriter.WriteLine("row="+row.ToString()+", InnerHtml="+rows[row].InnerHtml);
|
||||
}
|
||||
streamWriter.Flush();
|
||||
streamWriter.Close();
|
||||
}
|
||||
|
||||
private static void WriteToDisk(String responseString, String strPathFileName)
|
||||
{
|
||||
StreamWriter streamWriter = File.CreateText(strPathFileName);
|
||||
streamWriter.WriteLine(responseString);
|
||||
streamWriter.Flush();
|
||||
streamWriter.Close();
|
||||
}
|
||||
|
||||
private static void WriteToDisk(List<String> sections, String strPathFileName)
|
||||
{
|
||||
StreamWriter streamWriter = File.CreateText(strPathFileName);
|
||||
for(int index=0;index<sections.Count;index++)
|
||||
{
|
||||
streamWriter.WriteLine(String.Format("Section[{0}]",index));
|
||||
streamWriter.WriteLine(sections[index]);
|
||||
}
|
||||
streamWriter.Flush();
|
||||
streamWriter.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user