private static void DownloadHistPriceAndCalculateAverage(List <string> ETFList, ref List <QuoteFiveDay> quoteFiveDayList, bool calcLows) { string[] quotesArray = ETFList.ToArray(); System.DateTime fromDate = System.DateTime.Today.AddDays(-5); System.DateTime toDate = System.DateTime.Today.AddDays(-1); MaasOne.Finance.YahooFinance.HistQuotesInterval interval = MaasOne.Finance.YahooFinance.HistQuotesInterval.Daily; //Download MaasOne.Finance.YahooFinance.HistQuotesDownload dl2 = new HistQuotesDownload(); Response <HistQuotesResult> hqResp = dl2.Download(quotesArray, fromDate, toDate, interval); if (hqResp.Connection.State == MaasOne.Base.ConnectionState.Success) { HistQuotesResult result = hqResp.Result; HistQuotesDataChain[] chains = result.Chains; foreach (HistQuotesDataChain chain in chains) { var quoteFiveDayItem = quoteFiveDayList.FirstOrDefault(i => i.Id == chain.ID); if (calcLows) { CalculateAvgFromLows(chain, quoteFiveDayItem); } else { CalculateAvgFromHighs(chain, quoteFiveDayItem); } } } }
public IList <Tuple <DateTime, double> > Download() { Console.WriteLine("Extracting tickers from {0} till today, monthly", fromDate.Date); Console.WriteLine("Ticker: {0}", ticker); Response <HistQuotesResult> response = downloader.Download(ticker, fromDate, DateTime.Now, HistQuotesInterval.Monthly); if (response.Connection.State == MaasOne.Base.ConnectionState.Success) { HistQuotesResult result = response.Result; HistQuotesDataChain chain = result.Chains[0]; IList <Tuple <DateTime, double> > tickerResults = new List <Tuple <DateTime, double> >(); foreach (var item in chain) { Tuple <DateTime, double> periodResult = new Tuple <DateTime, double>(item.TradingDate, item.Close); tickerResults.Add(periodResult); } return(tickerResults); } else { Console.WriteLine("WARNING: Error downloading stock ticker {0}. {1} ", ticker, response.Connection.State); return(null); } }