static string DataTypeToURL(DataFeed.DataType dataType) { switch (dataType) { case DataType.Daily: return("d"); case DataType.Monthly: return("m"); case DataType.Weekly: return("w"); case DataType.Dividends: return("v"); default: return(""); } }
public bool GetSeries(DateTime start, DateTime end, Equity equity, DataFeed.DataType dataType, out TA.PriceVolumeSeries series) { string symbol = equity.Symbol; bool result = false; series = null; do { int size = (int)Math.Round((end - start).TotalDays); if (size <= 0) { break; } // preallocate some memory series = new TA.PriceVolumeSeries(size); string url; result = buildURL(symbol, start, end, dataType, out url); if (!result) { break; } Console.WriteLine("Get data from URL " + url + " between " + start + " and " + end); HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse(); Stream readStream = httpResponse.GetResponseStream(); result = fillDataArray(readStream, series); }while (false); return(result); }
/// <summary> /// Example /// MMM Apr 5, 1970 - 27 Feb,2009, daily /// http://ichart.finance.yahoo.com/table.csv?s=MMM&a=03&b=5&c=1970&d=01&e=27&f=2009&g=d&ignore=.csv /// </summary> static bool buildURL(string symbol, DateTime start, DateTime end, DataFeed.DataType dataType, out string url) { url = ""; string dataTypeURL = DataTypeToURL(dataType); if (dataTypeURL == "") { return(false); } symbol = symbol.ToUpper(); url = "http://ichart.finance.yahoo.com/table.csv?s=" + symbol + "&a=" + Month2Str(start.Month) + "&b=" + start.Day + "&c=" + start.Year + "&d=" + end.Month + "&e=" + end.Day + "&e=" + end.Year + "&g=" + dataTypeURL + "&ignore=.csv"; return(true); }