//YAHOO/AAPL public static string GetJsonData(string source, string codeQuandl, DateTime start, DateTime end){ QuandlDownloadRequest request = new QuandlDownloadRequest(); //request.APIKey = " _qjPeu6SzNYNJ42scYAi"; request.APIKey = "1ztyfXyfPBTeqfshhBdE"; if (codeQuandl == "EPA_SAN") { if (end.Year < 2014) { request.Datacode = new Datacode("YAHOO", "PA_SAN"); } else { request.Datacode = new Datacode(source, codeQuandl); } } else { request.Datacode = new Datacode(source, codeQuandl); } request.Format = FileFormats.JSON; request.Frequency = Frequencies.Daily; request.Transformation = Transformations.None; request.StartDate = start; request.EndDate = end; //Console.WriteLine("The request string is : {0}", request.ToRequestString()); IQuandlConnection connection = new QuandlConnection(); return connection.Request(request); //JObject jObject = JObject.Parse(data); //JArray column_names = (JArray)jObject["column_names"]; }
public static string GetJsonData(string source, string codeQuandl, DateTime start, DateTime end) { QuandlDownloadRequest request = new QuandlDownloadRequest(); request.APIKey = "1ztyfXyfPBTeqfshhBdE"; request.Datacode = new Datacode(source, codeQuandl); request.Format = FileFormats.JSON; request.Frequency = Frequencies.Daily; request.Transformation = Transformations.None; request.StartDate = start; request.EndDate = end; IQuandlConnection connection = new QuandlConnection(); return connection.Request(request); }
static string GetData(IQuandlRequest req, string sym, string dataset, FileFormats form, bool checkcache, bool compressedcache, DebugDelegate d) { if (_d == null) _d = d; try { var path = BarListImpl.GetDBLoc(PROGRAM , dataset+"_"+sym, 30, DateTime.Now, getformatext(form)); if (checkcache) { if (System.IO.File.Exists(path)) { try { var cached = Util.getfile(path, null); if (compressedcache) { var cacheddata = GZip.Uncompress(cached); v(sym + " " + dataset + " found " + cacheddata.Length.ToString("N0") + " bytes of cached data."); return cacheddata; } } catch (Exception ex) { debug("Ignoring cache (will pull directly) after cache error for: " + dataset + " on " + sym + " err: " + ex.Message + ex.StackTrace); } } } var con = new QuandlConnection(); var data = con.Request(req); var isdataok = !qh.isQdlUnderMaintence(data) ; if (isdataok) { v(sym + " " + dataset + " retrieved " + data.Length.ToString("N0") + " bytes of " + dataset + " data."); // save it for later caching if (Util.setfile(path, compressedcache ? GZip.Compress(data) : data)) { v(sym + " " + dataset + " cached " + data.Length.ToString("N0") + " bytes of " + dataset + " data."); } else v(sym + " " + dataset + " error caching " + data.Length.ToString("N0") + " bytes of " + dataset + " data. Will be re-pulled on next attempt."); } else { debug(sym + " " + dataset + " can't be retrieved because quandl is down."); return string.Empty; } return data; } catch (Exception ex) { if (isVerboseDebugging) { debug("An error occurred getting data for: " + dataset + " on symbol: " + sym + " using url: " + req.ToRequestString()); debug("Error for " + dataset + " on symbol: " + sym + ": " + ex.Message + ex.StackTrace); } else debug("An error occurred getting data for: " + dataset + " on symbol: " + sym + ", err: " + ex.Message + ex.StackTrace); return string.Empty; } }
/// <summary> /// Implementation! Connected to Quandl, request the data and then save to a file /// </summary> /// <param name="filename">The filename to save the output to</param> /// <param name="request">The request to make to Quandl</param> private static void RequestToFile(string filename, IQuandlRequest request) { QuandlConnection connection = new QuandlConnection(); var data = connection.Request(request); using (StreamWriter writer = new StreamWriter(filename)) { writer.Write(data); } }