//[TestMethod] public void TestDownloadHistoricalData() { const string symbol = "MEG"; const int numYears = 10; string downloadStr = "http://www.pse.com.ph/servlet/PSEChartServlet?securitySymbol=%s&years=%f"; downloadStr = downloadStr.Replace("%s", symbol).Replace("%f", numYears.ToString()); var downloadUri = new Uri(downloadStr); var downloader = new HistoricalDataDownloader(downloadUri); downloader.Download(); HistoricalDataReader reader = downloader.GetReader(); var outputSettings = new CSVOutputSettings(); outputSettings.CSVFormat = "S,D,O,H,L,C,V,F"; outputSettings.Delimiter = ","; outputSettings.OutputDirectory = "C:\\Users\\yeahbah\\Documents\\projects"; outputSettings.Filename = symbol + ".csv"; outputSettings.DateFormat = "MM/DD/YYYY"; reader.ToCSV(outputSettings); }
private void DoDownloadHistoricalData(int numYears) { Dictionary <string, string> indexDict = new Dictionary <string, string>(); indexDict.Add("^PSEi", "PSE"); indexDict.Add("^ALLSHARES", "ALL"); indexDict.Add("^FINANCIAL", "FIN"); indexDict.Add("^INDUSTRIAL", "IND"); indexDict.Add("^HOLDING", "HDG"); indexDict.Add("^PROPERTY", "PRO"); indexDict.Add("^SERVICE", "SVC"); indexDict.Add("^MINING-OIL", "M-O"); foreach (string symbol in this.selectedStocks) { string tmpSymbol = symbol; string downloadStr; if (tmpSymbol.Contains("^")) { tmpSymbol = indexDict[symbol]; downloadStr = "http://www.pse.com.ph/servlet/ChartForPhisixServlet?indexID=%s&years=%f"; } else { downloadStr = "http://www.pse.com.ph/servlet/PSEChartServlet?securitySymbol=%s&years=%f"; } downloadStr = downloadStr.Replace("%s", tmpSymbol).Replace("%f", numYears.ToString()); this.csvOutputSettings.Filename = symbol + ".csv"; HistoricalDataDownloader downloader = new HistoricalDataDownloader(new Uri(downloadStr)); downloader.Download(); HistoricalDataReader reader = downloader.GetReader(symbol); reader.ToCSV(this.csvOutputSettings); } if (this.selectedStocks.Count > 0) { labelStatus.Text = "Done"; } else { labelStatus.Text = "No stock symbols selected"; } }