//To get all items by running this on all tickers. public static void GetAllFRItemFromNASDAQ(string[] tickers, string reportType) { string periodType = "Annual"; string numPeriods = "10"; string reportParam = FinancialReportsConfig.params_NASDAQ[reportType]; string periodParam = FinancialReportsConfig.params_NASDAQ[periodType]; var keys = (Dictionary<string, int>)FinancialReportsConfig.mappings_NASDAQ[reportType]; List<string[]> list = new List<string[]>(); list.Add(new string[] { "ticker", "not in key", "previous key", "next key", "number" }); foreach (string ticker in tickers) { Dictionary<string, object> data = new Dictionary<string, object>(); try { WebData webData = new WebData(string.Format(Constants.NASDAQFinancialReportingURL, reportParam, periodParam, numPeriods, ticker)); data = webData.ReadNASDAQFRHtmlTable().ElementAt(1); } catch { } data.Each((d, i) => { int nexti = i + 1 == data.Count ? i : i + 1; if (!keys.ContainsKey(d.Key)) list.Add(new string[] { ticker, d.Key, data.ElementAt(i - 1).Key, data.ElementAt(nexti).Key, i.ToString() }); } ); //list.Add(new string[]{"","","","",""}); } Excel.Worksheet ws = ExcelUtil.Worksheet("Test_" + reportType); ws.Range("A2").Resize(list.Count, list[0].Length).Formula = ExcelUtil.To2DArray(list); }
public static bool LoadReportFromNASDAQ(string ticker, string reportType, string periodType, int numPeriods = 10) { string reportParam = FinancialReportsConfig.params_NASDAQ[reportType]; string periodParam = FinancialReportsConfig.params_NASDAQ[periodType]; var keys = (Dictionary<string, int>)FinancialReportsConfig.mappings_NASDAQ[reportType]; try { WebData webData = new WebData(string.Format(Constants.NASDAQFinancialReportingURL, reportParam, periodParam, numPeriods, ticker)); IEnumerable<Dictionary<string, object>> data = webData.ReadNASDAQFRHtmlTable(); data = data.Reverse(); DataToExcelColumnHeaderTable(data, keys, reportType, reportType.Replace(" ", "") + "_" + periodType, "Right"); return true; } catch(Exception e) { Excel.Worksheet ws = ExcelUtil.Worksheet("Error"); Excel.Range error = ws.Range("A1"); error.Value = ticker + " " + e.Message; return false; } }