Add UnemploymentData

This commit is contained in:
2025-11-21 10:52:34 -05:00
parent 2e93e544ba
commit feb3ad4f5f
6 changed files with 467 additions and 168 deletions

View File

@@ -35,7 +35,8 @@ namespace MarketData.Services
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATEANALYSTRATINGS");
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATESECFILINGSWATCHLIST /WATCHLIST:");
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATECOMPANYPROFILES");
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATEGDPPERCAPITA");
MDTrace.WriteLine(LogLevel.DEBUG, "UPDATEGDPPERCAPITA");
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATEUNEMPLOYMENTPERCAPITA");
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATEETFHOLDINGS");
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATEFINANCIALSTATEMENTS");
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATEFUNDAMENTALS");
@@ -78,7 +79,8 @@ namespace MarketData.Services
tasks.Add("UPDATEANALYSTRATINGS",TaskUpdateAnalystRatings);
tasks.Add("UPDATESECFILINGSWATCHLIST",TaskUpdateSECFilingsWatchList);
tasks.Add("UPDATECOMPANYPROFILES",TaskUpdateCompanyProfiles);
tasks.Add("UPDATEGDPPERCAPITA",TaskUpdateGDPPerCapita);
tasks.Add("UPDATEGDPPERCAPITA", TaskUpdateGDPPerCapita);
tasks.Add("UPDATEUNEMPLOYMENTPERCAPITA", TaskUpdateUnemploymentPerCapita);
tasks.Add("UPDATEETFHOLDINGS",TaskUpdateETFHoldings);
tasks.Add("UPDATEFINANCIALSTATEMENTS",TaskUpdateFinancialStatements);
tasks.Add("UPDATEFUNDAMENTALS",TaskUpdateFundamentals);
@@ -219,6 +221,12 @@ namespace MarketData.Services
await Task.FromResult(true);
}
public async Task TaskUpdateUnemploymentPerCapita(CommandArgs commandArgs)
{
LoadUnemploymentPerCapita();
await Task.FromResult(true);
}
public async Task TaskUpdateCompanyProfiles(CommandArgs commandArgs)
{
UpdateCompanyProfiles();
@@ -577,6 +585,7 @@ namespace MarketData.Services
{
UpdateYieldCurve(); // www.treasury.gov
LoadGDPPerCapita(); // api.worldbank.org
LoadUnemploymentPerCapita(); // api.worldbank.org
LoadConsumerPriceIndex(); // Load consumer price index data from Bureau of Labor Statistics
resetEvents[STAGE_3].Set();
MDTrace.WriteLine(LogLevel.DEBUG,$"STAGE_3 complete.");
@@ -746,65 +755,105 @@ namespace MarketData.Services
{
MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms).");
}
}
}
/// <summary>
/// Loads the GDP Data from WorldBank
/// </summary>
public static void LoadGDPPerCapita()
{
Profiler profiler = new Profiler();
try
{
MDTrace.WriteLine(LogLevel.DEBUG,"Started.");
EconomicIndicators economicIndicators=MarketDataHelper.GetGDPPerCapita();
if(null==economicIndicators||0==economicIndicators.Count)
MDTrace.WriteLine(LogLevel.DEBUG, "Started.");
EconomicIndicators economicIndicators = MarketDataHelper.GetGDPPerCapita();
if (null == economicIndicators || 0 == economicIndicators.Count)
{
MDTrace.WriteLine(LogLevel.DEBUG,"No data, see log file for potential issues.");
MDTrace.WriteLine(LogLevel.DEBUG, "No data, see log file for potential issues.");
return;
}
List<String> distinctCountry=(from EconomicIndicator economicIndicator in economicIndicators select economicIndicator.CountryCode).Distinct().ToList();
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Downloaded {0} countries.",distinctCountry.Count));
MDTrace.WriteLine(LogLevel.DEBUG,"Saving...");
if(EconomicIndicatorDA.InsertUpdateEconomicIndicators(economicIndicators))
List<String> distinctCountry = (from EconomicIndicator economicIndicator in economicIndicators select economicIndicator.CountryCode).Distinct().ToList();
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Downloaded {0} countries.", distinctCountry.Count));
MDTrace.WriteLine(LogLevel.DEBUG, "Saving...");
if (EconomicIndicatorDA.InsertUpdateEconomicIndicators(economicIndicators))
{
MDTrace.WriteLine(LogLevel.DEBUG,$"Save complete.");
MDTrace.WriteLine(LogLevel.DEBUG, $"Save complete.");
}
else
{
MDTrace.WriteLine(LogLevel.DEBUG,"Failed to save economic indicators.");
MDTrace.WriteLine(LogLevel.DEBUG, "Failed to save economic indicators.");
}
}
catch(Exception exception)
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception:{0}",exception.ToString()));
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Exception:{0}", exception.ToString()));
}
finally
{
MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)");
MDTrace.WriteLine(LogLevel.DEBUG, $"Done, total took {profiler.End()}(ms)");
}
}
/// <summary>
/// Loads the Unemployment Data from WorldBank
/// </summary>
public static void LoadUnemploymentPerCapita()
{
Profiler profiler = new Profiler();
try
{
MDTrace.WriteLine(LogLevel.DEBUG, "Started.");
EconomicIndicators economicIndicators = MarketDataHelper.GetUnemploymentPerCapita();
if (null == economicIndicators || 0 == economicIndicators.Count)
{
MDTrace.WriteLine(LogLevel.DEBUG, "No data, see log file for potential issues.");
return;
}
List<String> distinctCountry = (from EconomicIndicator economicIndicator in economicIndicators select economicIndicator.CountryCode).Distinct().ToList();
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Downloaded {0} countries.", distinctCountry.Count));
MDTrace.WriteLine(LogLevel.DEBUG, "Saving...");
if (EconomicIndicatorDA.InsertUpdateEconomicIndicators(economicIndicators))
{
MDTrace.WriteLine(LogLevel.DEBUG, $"Save complete.");
}
else
{
MDTrace.WriteLine(LogLevel.DEBUG, "Failed to save economic indicators.");
}
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Exception:{0}", exception.ToString()));
}
finally
{
MDTrace.WriteLine(LogLevel.DEBUG, $"Done, total took {profiler.End()}(ms)");
}
}
public static void UpdateYieldCurve() // maintains current year of yield curve data
{
Profiler profiler = new Profiler();
try
{
int year = DateTime.Now.Year;
MDTrace.WriteLine(LogLevel.DEBUG,"Retrieving yield curve for year "+year);
YieldCurve yieldCurve=MarketDataHelper.GetYieldCurve(year);
MDTrace.WriteLine(LogLevel.DEBUG, "Retrieving yield curve for year " + year);
YieldCurve yieldCurve = MarketDataHelper.GetYieldCurve(year);
if (null == yieldCurve)
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Failed to get YieldCurve for {0}", year));
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Failed to get YieldCurve for {0}", year));
return;
}
MDTrace.WriteLine(LogLevel.DEBUG,"Got "+yieldCurve.Count+" points for "+year);
MDTrace.WriteLine(LogLevel.DEBUG, "Got " + yieldCurve.Count + " points for " + year);
YieldCurveDA.InsertOrUpdate(yieldCurve);
}
catch(Exception exception)
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,$"Exception: {exception.ToString()}");
MDTrace.WriteLine(LogLevel.DEBUG, $"Exception: {exception.ToString()}");
}
finally
{
MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()}(ms)");
MDTrace.WriteLine(LogLevel.DEBUG, $"Done, total took {profiler.End()}(ms)");
}
}

View File

@@ -1,7 +1,7 @@
{
"market_data" : "Database=market_data;Datasource=adrastea;Username=guest;Password=guest",
"portfolio_data" : "Database=portfolio_data;Datasource=adrastea;Username=guest;Password=guest",
"user_data" : "Database=user_data;Datasource=adrastea;Username=guest;Password=guest",
"market_data" : "Database=market_data;Datasource=isonoe;Username=guest;Password=guest",
"portfolio_data" : "Database=portfolio_data;Datasource=isonoe;Username=guest;Password=guest",
"user_data" : "Database=user_data;Datasource=isonoe;Username=guest;Password=guest",
"sms_smtpaddress" : "smtp.gmail.com",
"sms_smsusername" : "skessler1964@gmail.com",
"sms_smspassword" : "xjfo isnf gmyi zovr",

View File

@@ -7,33 +7,96 @@ namespace MarketData.DataAccess
{
public class EconomicIndicatorDA
{
private EconomicIndicatorDA()
{
}
public static EconomicIndicators GetEconomicIndicators()
private EconomicIndicatorDA()
{
MySqlConnection sqlConnection=null;
MySqlCommand sqlCommand=null;
MySqlDataReader sqlDataReader=null;
EconomicIndicators economicIndicators=new EconomicIndicators();
try
{
}
/// <summary>
/// Retrieves a distinct list of indicator_code
/// </summary>
/// <returns></returns>
public static List<String> GetDistinctIndicators()
{
MySqlConnection sqlConnection = null;
MySqlCommand sqlCommand = null;
MySqlDataReader sqlDataReader = null;
List<String> indicators = new List<String>();
try
{
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
sqlCommand=sqlConnection.CreateCommand();
StringBuilder sb=new StringBuilder();
sb.Append("select country_code,country_name,indicator_code,indicator_name,indicator_value,year,source from EconomicIndicators");
sqlCommand.CommandText=sb.ToString();
sqlDataReader=sqlCommand.ExecuteReader();
while(sqlDataReader.Read())
sqlCommand = sqlConnection.CreateCommand();
StringBuilder sb = new StringBuilder();
sb.Append("select distinct(indicator_code) from EconomicIndicators ");
sb.Append("ORDER BY 1 asc");
sqlCommand.CommandText = sb.ToString();
sqlDataReader = sqlCommand.ExecuteReader();
while (sqlDataReader.Read())
{
EconomicIndicator economicIndicator=new EconomicIndicator();
if(!sqlDataReader.IsDBNull(0))economicIndicator.CountryCode=sqlDataReader.GetString(0);
if(!sqlDataReader.IsDBNull(1))economicIndicator.CountryName=sqlDataReader.GetString(1);
if(!sqlDataReader.IsDBNull(2))economicIndicator.IndicatorCode=sqlDataReader.GetString(2);
if(!sqlDataReader.IsDBNull(3))economicIndicator.IndicatorName=sqlDataReader.GetString(3);
if(!sqlDataReader.IsDBNull(4))economicIndicator.IndicatorValue=sqlDataReader.GetDouble(4);
if(!sqlDataReader.IsDBNull(5))economicIndicator.Year=sqlDataReader.GetInt32(5);
if(!sqlDataReader.IsDBNull(6))economicIndicator.Source=sqlDataReader.GetString(6);
indicators.Add(sqlDataReader.GetString(0).ToUpper());
}
sqlDataReader.Close();
sqlDataReader.Dispose();
sqlCommand.Dispose();
sqlConnection.Close();
sqlConnection.Dispose();
return indicators;
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Exception:{0}", exception.ToString()));
return null;
}
finally
{
if (null != sqlDataReader)
{
sqlDataReader.Close();
sqlDataReader.Dispose();
}
if (null != sqlCommand)
{
sqlCommand.Dispose();
}
if (null != sqlConnection)
{
sqlConnection.Close();
sqlConnection.Dispose();
}
}
}
/// <summary>
/// Retrieve all records
/// </summary>
/// <returns></returns>
public static EconomicIndicators GetEconomicIndicators(String indicatorCode, String countryCode="USA")
{
MySqlConnection sqlConnection = null;
MySqlCommand sqlCommand = null;
MySqlDataReader sqlDataReader = null;
EconomicIndicators economicIndicators = new EconomicIndicators();
try
{
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
sqlCommand = sqlConnection.CreateCommand();
StringBuilder sb = new StringBuilder();
sb.Append("select country_code,country_name,indicator_code,indicator_name,indicator_value,year,source from EconomicIndicators").Append(" ");
sb.Append("where indicator_code=").Append(SqlUtils.AddQuotes(indicatorCode)).Append(" ");
sb.Append("AND country_code = ").Append(SqlUtils.AddQuotes(countryCode)).Append(" ");
sb.Append("ORDER BY YEAR ASC");
sqlCommand.CommandText = sb.ToString();
sqlDataReader = sqlCommand.ExecuteReader();
while (sqlDataReader.Read())
{
EconomicIndicator economicIndicator = new EconomicIndicator();
if (!sqlDataReader.IsDBNull(0)) economicIndicator.CountryCode = sqlDataReader.GetString(0);
if (!sqlDataReader.IsDBNull(1)) economicIndicator.CountryName = sqlDataReader.GetString(1);
if (!sqlDataReader.IsDBNull(2)) economicIndicator.IndicatorCode = sqlDataReader.GetString(2);
if (!sqlDataReader.IsDBNull(3)) economicIndicator.IndicatorName = sqlDataReader.GetString(3);
if (!sqlDataReader.IsDBNull(4)) economicIndicator.IndicatorValue = sqlDataReader.GetDouble(4);
if (!sqlDataReader.IsDBNull(5)) economicIndicator.Year = sqlDataReader.GetInt32(5);
if (!sqlDataReader.IsDBNull(6)) economicIndicator.Source = sqlDataReader.GetString(6);
economicIndicators.Add(economicIndicator);
}
sqlDataReader.Close();
@@ -41,103 +104,179 @@ namespace MarketData.DataAccess
sqlCommand.Dispose();
sqlConnection.Close();
sqlConnection.Dispose();
return economicIndicators;
}
catch(Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception:{0}",exception.ToString()));
return null;
}
return economicIndicators;
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Exception:{0}", exception.ToString()));
return null;
}
finally
{
if(null!=sqlDataReader)
if (null != sqlDataReader)
{
sqlDataReader.Close();
sqlDataReader.Dispose();
}
if(null!=sqlCommand)
if (null != sqlCommand)
{
sqlCommand.Dispose();
}
if(null!=sqlConnection)
if (null != sqlConnection)
{
sqlConnection.Close();
sqlConnection.Dispose();
}
}
}
public static bool InsertUpdateEconomicIndicators(EconomicIndicators economicIndicators)
{
MySqlConnection sqlConnection=null;
MySqlCommand sqlCommand=null;
MySqlTransaction sqlTransaction=null;
try
{
/// <summary>
/// Retrieve all records
/// </summary>
/// <returns></returns>
public static EconomicIndicators GetEconomicIndicators()
{
MySqlConnection sqlConnection = null;
MySqlCommand sqlCommand = null;
MySqlDataReader sqlDataReader = null;
EconomicIndicators economicIndicators = new EconomicIndicators();
try
{
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
sqlCommand = sqlConnection.CreateCommand();
StringBuilder sb = new StringBuilder();
sb.Append("select country_code,country_name,indicator_code,indicator_name,indicator_value,year,source from EconomicIndicators");
sqlCommand.CommandText = sb.ToString();
sqlDataReader = sqlCommand.ExecuteReader();
while (sqlDataReader.Read())
{
EconomicIndicator economicIndicator = new EconomicIndicator();
if (!sqlDataReader.IsDBNull(0)) economicIndicator.CountryCode = sqlDataReader.GetString(0);
if (!sqlDataReader.IsDBNull(1)) economicIndicator.CountryName = sqlDataReader.GetString(1);
if (!sqlDataReader.IsDBNull(2)) economicIndicator.IndicatorCode = sqlDataReader.GetString(2);
if (!sqlDataReader.IsDBNull(3)) economicIndicator.IndicatorName = sqlDataReader.GetString(3);
if (!sqlDataReader.IsDBNull(4)) economicIndicator.IndicatorValue = sqlDataReader.GetDouble(4);
if (!sqlDataReader.IsDBNull(5)) economicIndicator.Year = sqlDataReader.GetInt32(5);
if (!sqlDataReader.IsDBNull(6)) economicIndicator.Source = sqlDataReader.GetString(6);
economicIndicators.Add(economicIndicator);
}
sqlDataReader.Close();
sqlDataReader.Dispose();
sqlCommand.Dispose();
sqlConnection.Close();
sqlConnection.Dispose();
return economicIndicators;
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Exception:{0}", exception.ToString()));
return null;
}
finally
{
if (null != sqlDataReader)
{
sqlDataReader.Close();
sqlDataReader.Dispose();
}
if (null != sqlCommand)
{
sqlCommand.Dispose();
}
if (null != sqlConnection)
{
sqlConnection.Close();
sqlConnection.Dispose();
}
}
}
/// <summary>
/// Upsert items
/// </summary>
/// <returns></returns>
public static bool InsertUpdateEconomicIndicators(EconomicIndicators economicIndicators)
{
MySqlConnection sqlConnection = null;
MySqlCommand sqlCommand = null;
MySqlTransaction sqlTransaction = null;
try
{
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
sqlTransaction = sqlConnection.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);
sqlCommand=sqlConnection.CreateCommand();
sqlCommand.Transaction=sqlTransaction;
List<String> distinctCountryCodes=(from EconomicIndicator economicIndicator in economicIndicators select economicIndicator.CountryCode).Distinct().ToList();
for(int index=0;index<distinctCountryCodes.Count;index++)
sqlCommand = sqlConnection.CreateCommand();
sqlCommand.Transaction = sqlTransaction;
List<String> distinctCountryCodes = (from EconomicIndicator economicIndicator in economicIndicators select economicIndicator.CountryCode).Distinct().ToList();
for (int index = 0; index < distinctCountryCodes.Count; index++)
{
String countryCode=distinctCountryCodes[index];
List<int> years=(from EconomicIndicator economicIndicator in economicIndicators select economicIndicator.Year).Distinct().ToList();
DeleteEconomicIndicator(countryCode,years,sqlCommand,sqlTransaction);
String countryCode = distinctCountryCodes[index];
List<int> years = (from EconomicIndicator economicIndicator in economicIndicators select economicIndicator.Year).Distinct().ToList();
DeleteEconomicIndicator(countryCode, years, sqlCommand, sqlTransaction);
}
InsertEconomicIndicators(economicIndicators,sqlCommand,sqlTransaction);
InsertEconomicIndicators(economicIndicators, sqlCommand, sqlTransaction);
sqlTransaction.Commit();
sqlTransaction.Dispose();
sqlCommand.Dispose();
sqlConnection.Close();
sqlConnection.Dispose();
sqlConnection=null;
sqlCommand=null;
sqlTransaction=null;
return true;
}
catch(Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception:{0}",exception.ToString()));
return false;
}
sqlConnection = null;
sqlCommand = null;
sqlTransaction = null;
return true;
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Exception:{0}", exception.ToString()));
return false;
}
finally
{
if(null!=sqlConnection)
if (null != sqlConnection)
{
sqlConnection.Close();
sqlConnection.Dispose();
}
if(null!=sqlCommand)
if (null != sqlCommand)
{
sqlCommand.Dispose();
}
if(null!=sqlTransaction)
if (null != sqlTransaction)
{
sqlTransaction.Dispose();
}
}
}
public static bool DeleteEconomicIndicator(String countryCode,List<int> years,MySqlCommand sqlCommand,MySqlTransaction sqlTransaction)
{
String strQuery=null;
try
{
StringBuilder sb=new StringBuilder();
}
/// <summary>
/// Remove items
/// </summary>
/// <returns></returns>
private static bool DeleteEconomicIndicator(String countryCode, List<int> years, MySqlCommand sqlCommand, MySqlTransaction sqlTransaction)
{
String strQuery = null;
try
{
StringBuilder sb = new StringBuilder();
sb.Append("delete from EconomicIndicators ").Append(" where ");
sb.Append("country_code=").Append("'").Append(countryCode).Append("'").Append(" and ");
sb.Append("year in ").Append(SqlUtils.CreateInClause(years));
strQuery=sb.ToString();
sqlCommand.CommandText=strQuery;
strQuery = sb.ToString();
sqlCommand.CommandText = strQuery;
sqlCommand.ExecuteNonQuery();
return true;
}
catch(Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception:{0}, query was {1}",exception.ToString(),strQuery));
return false;
}
}
public static bool InsertEconomicIndicators(EconomicIndicators economicIndicators,MySqlCommand sqlCommand,MySqlTransaction sqlTransaction)
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Exception:{0}, query was {1}", exception.ToString(), strQuery));
return false;
}
}
/// <summary>
/// Insert items
/// </summary>
/// <returns></returns>
private static bool InsertEconomicIndicators(EconomicIndicators economicIndicators,MySqlCommand sqlCommand,MySqlTransaction sqlTransaction)
{
String strQuery=null;
try

View File

@@ -20,31 +20,32 @@ using MarketDataLib.Utility;
using MarketData.Configuration;
using System.Text.Json;
//Zacks Rank - Zacks
//Splits - EODDATA
//GDP Data - WorldBank
//Dividend History - NASDAQ
//Options - NASDAQ
//Analyst Ratings - Briefing.com
//SEC Filings - SEC.GOV (EDGAR)
//Yield Curve - Treasury.Gov
//ETF Holdings - Yahoo Finance
//Insider Transactions - Insider Tracking.com
//Company Profile - MorningStar + Reuters
//Headlines - Seeking Alpha + NASDAQ
//CIK Codes - SEC.GOV
//Analyst Price Target - Yahoo Finance , Market Beat as backup
//Historical - MorningStar
//Income Statement - NASDAQ
//Balance Sheet - NASDAQ
//Statement of Cashflows - MorningStar
//Fundamentals - 2 Sources....Yahoo Finance & FINVIZ
// Zacks Rank - Zacks
// Splits - EODDATA
// GDP Data - WorldBank
// Employment Data - WorldBank
// Dividend History - NASDAQ
// Options - NASDAQ
// Analyst Ratings - Briefing.com
// SEC Filings - SEC.GOV (EDGAR)
// Yield Curve - Treasury.Gov
// ETF Holdings - Yahoo Finance
// Insider Transactions - Insider Tracking.com
// Company Profile - MorningStar + Reuters
// Headlines - Seeking Alpha + NASDAQ
// CIK Codes - SEC.GOV
// Analyst Price Target - Yahoo Finance , Market Beat as backup
// Historical - MorningStar
// Income Statement - NASDAQ
// Balance Sheet - NASDAQ
// Statement of Cashflows - MorningStar
// Fundamentals - 2 Sources....Yahoo Finance & FINVIZ
// a) Key Statistics
// b) Financials
//Intraday Pricing - Yahoo Finance + BigCharts
//Historical Pricing - BigCharts + Yahoo Finance
//CompanyDescription - Reuters
//Premarket - CNN
// Intraday Pricing - Yahoo Finance + RobinHood
// Historical Pricing - Yahoo Finance
// CompanyDescription - Reuters
// Premarket - CNN
namespace MarketData.Helper
{
@@ -395,50 +396,94 @@ namespace MarketData.Helper
if (null != httpNetResponse) httpNetResponse.Dispose();
}
}
// ***************************************************************************************************************************************************************************************
// ************************************************************************** G D P P E R C A P I T A D A T A W O R L D B A N K *************************************************
// ***************************************************************************************************************************************************************************************
public static EconomicIndicators GetGDPPerCapita(bool debug=false)
{
HttpNetResponse httpNetResponse=null;
try
{
// Retrieve compressed CSV from World Bank web site and write to disk
StringBuilder sb=new StringBuilder();
String strRequest;
String currentWorkingDirectory=Directory.GetCurrentDirectory();
String strExtractFolder=currentWorkingDirectory+"/"+"extracts";
String strFileName="API_NY.GDP.MKTP.CD_DS2_V2_USD.zip";
String strPathFileName=currentWorkingDirectory+"/"+strFileName;
sb.Append("http://api.worldbank.org/v2/en/indicator/NY.GDP.MKTP.CD?downloadformat=csv");
strRequest=sb.ToString();
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Downloading {0} from {1}",strFileName,strRequest));
httpNetResponse=HttpNetRequest.GetRequestStreamZIP(strRequest);
if(!httpNetResponse.Success)
// ***************************************************************************************************************************************************************************************
// ************************************************************************** W O R L D B A N K F E E D *************************************************
// ***************************************************************************************************************************************************************************************
public static EconomicIndicators GetUnemploymentPerCapita(bool debug = false)
{
HttpNetResponse httpNetResponse = null;
try
{
StringBuilder sb = new StringBuilder();
String strRequest;
String currentWorkingDirectory = Directory.GetCurrentDirectory();
String strExtractFolder = currentWorkingDirectory + "/" + "extracts";
String strFileName = "API_SL.UEM.TOTL.ZS_DS2_en_csv_v2_254884.zip";
String strPathFileName = currentWorkingDirectory + "/" + strFileName;
sb.Append("http://api.worldbank.org/v2/en/indicator/SL.UEM.TOTL.ZS?downloadformat=csv");
strRequest = sb.ToString();
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Downloading {0} from {1}", strFileName, strRequest));
httpNetResponse = HttpNetRequest.GetRequestStreamZIP(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;
}
if(File.Exists(strPathFileName))File.Delete(strPathFileName);
FileStream outStream=new FileStream(strPathFileName,FileMode.Create);
byte[] streamBytes=httpNetResponse.ResponseStream.GetBuffer();
outStream.Write(streamBytes,0,streamBytes.Length);
outStream.Flush();
outStream.Close();
if (File.Exists(strPathFileName)) File.Delete(strPathFileName);
FileStream outStream = new FileStream(strPathFileName, FileMode.Create);
byte[] streamBytes = httpNetResponse.ResponseStream.GetBuffer();
outStream.Write(streamBytes, 0, streamBytes.Length);
outStream.Flush();
outStream.Close();
outStream.Dispose();
return EconomicIndicators.FromZipFile(strPathFileName,strExtractFolder,debug);
}
catch(Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,exception);
return EconomicIndicators.FromZipFile(strPathFileName, strExtractFolder, debug);
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG, exception);
return null;
}
finally
{
if(null!=httpNetResponse)httpNetResponse.Dispose();
}
}
}
finally
{
if (null != httpNetResponse) httpNetResponse.Dispose();
}
}
/// <summary>
/// Retrieves GDP Data from WorlBank as zip file, decompresses the zip file, reads and imports the CSV contents and returns EconomicIndicators
/// </summary>
/// <param name="debug"></param>
/// <returns></returns>
public static EconomicIndicators GetGDPPerCapita(bool debug = false)
{
HttpNetResponse httpNetResponse = null;
try
{
StringBuilder sb = new StringBuilder();
String strRequest;
String currentWorkingDirectory = Directory.GetCurrentDirectory();
String strExtractFolder = currentWorkingDirectory + "/" + "extracts";
String strFileName = "API_NY.GDP.MKTP.CD_DS2_V2_USD.zip";
String strPathFileName = currentWorkingDirectory + "/" + strFileName;
sb.Append("http://api.worldbank.org/v2/en/indicator/NY.GDP.MKTP.CD?downloadformat=csv");
strRequest = sb.ToString();
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Downloading {0} from {1}", strFileName, strRequest));
httpNetResponse = HttpNetRequest.GetRequestStreamZIP(strRequest);
if (!httpNetResponse.Success)
{
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Request:{0} failed with status {1}", httpNetResponse.Request, httpNetResponse.StatusCode));
return null;
}
if (File.Exists(strPathFileName)) File.Delete(strPathFileName);
FileStream outStream = new FileStream(strPathFileName, FileMode.Create);
byte[] streamBytes = httpNetResponse.ResponseStream.GetBuffer();
outStream.Write(streamBytes, 0, streamBytes.Length);
outStream.Flush();
outStream.Close();
outStream.Dispose();
return EconomicIndicators.FromZipFile(strPathFileName, strExtractFolder, debug);
}
catch (Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG, exception);
return null;
}
finally
{
if (null != httpNetResponse) httpNetResponse.Dispose();
}
}
// ***************************************************************************************************************************************************************************************
// ************************************************************************** D I V I D E N D H I S T O R Y N A S D A Q ***********************************************************
// ***************************************************************************************************************************************************************************************