public static string GetLatestDateFromQuandl() { QuandlDownloadRequest request = new QuandlDownloadRequest(); request.APIKey = "Fp8XizZQKq3P1pqcHNxc"; request.Datacode = new Datacode("NSE", "ICICIBANK"); // PRAGUESE is the source, PX is the datacode request.Format = FileFormats.JSON; request.Frequency = Frequencies.Daily; request.StartDate = DateTime.Today.AddDays(-5); request.Sort = SortOrders.Descending; //request.Transformation = Transformations.Difference; QuandlConnection conn = new QuandlConnection(); string json = ""; try { json = conn.Request(request); // request is your QuandlDownloadRequst RootObject obj = JsonConvert.DeserializeObject <RootObject>(json); return(obj.to_date); } catch (Exception ex) { ClsLog.WriteLog("ERROR: Not able to Downlaoding data for " + "ICICIBANK" + ". Exception: " + ex.Message); //ClsDataBase.MarkScriptInvalid("ICICIBANK"); return(null); } }
/// <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); } }
dynamic GetLastAvailableYieldCurveUntil(DateTime date) { QuandlDownloadRequest request = new QuandlDownloadRequest(); request.APIKey = Quandl_APIKey; request.Datacode = new Datacode("USTREASURY", "YIELD"); request.Format = FileFormats.JSON; request.Frequency = Frequencies.None; request.StartDate = date.AddDays(-5); request.EndDate = date; //request.Truncation = 150; request.Sort = SortOrders.Ascending; request.Transformation = Transformations.None; IQuandlConnection connection = new QuandlConnection(); string data = connection.Request(request); dynamic dyn = JObject.Parse(data); //the last available data point dynamic lastcurve = dyn.data.Last; return(lastcurve); }
public static void DownlaodBulkEodData(ref BackgroundWorker BGW, List <DateTime> Dates) { try { Collection <ClsScriptsMaster> ScriptCodes = ClsDataBase.GetScriptsCode(false); Collection <ClsPriceDataSet> ColEodData = new Collection <ClsPriceDataSet>(); ArrayList TempData = new ArrayList(); string json = ""; ClsDashBoard ObjDashBoard = new ClsDashBoard(); ClsDashBoard.OverallPbarMax = ScriptCodes.Count; //ClsDashBoard.ChangeOPbarValue = false; //ClsDashBoard.OverallPbarMax = ScriptCodes.Count; int i = 1; int j = 1; foreach (var Scode in ScriptCodes) { ClsLog.WriteLog("Starting Data Download for script: " + Scode.ScriptsName + "(" + Scode.ScriptsCode + ")"); QuandlDownloadRequest request = new QuandlDownloadRequest(); request.APIKey = "Fp8XizZQKq3P1pqcHNxc"; request.Datacode = new Datacode("NSE", Scode.ScriptsCode); // PRAGUESE is the source, PX is the datacode request.Format = FileFormats.JSON; request.Frequency = Frequencies.Daily; request.StartDate = Dates[0]; if (Dates.Count > 1) { request.EndDate = Dates[Dates.Count - 1]; } //request.Truncation = 150; request.Sort = SortOrders.Descending; //request.Transformation = Transformations.Difference; QuandlConnection conn = new QuandlConnection(); try { json = conn.Request(request); // request is your QuandlDownloadRequst } catch (Exception ex) { ClsLog.WriteLog("ERROR: Not able to Downlaoding data for " + Scode.ScriptsCode + ". Exception: " + ex.Message); ClsDataBase.MarkScriptInvalid(Scode.ScriptsCode); continue; } RootObject obj = JsonConvert.DeserializeObject <RootObject>(json); ClsDashBoard.ScriptOStatus = "Total Scripts: " + ScriptCodes.Count.ToString() + " Downloading " + i.ToString() + " Of " + ScriptCodes.Count.ToString(); ClsDashBoard.OverallProgress = i; ClsDashBoard.ScriptPbarMax = 0; ClsDashBoard.ChangeSPbarValue = true; BGW.ReportProgress(0); ClsDashBoard.ScriptSStatus = Scode.ScriptsCode + " Total Records:" + obj.data.Count.ToString(); ClsLog.WriteLog(Scode.ScriptsCode + " Total Records:" + obj.data.Count.ToString()); ClsDashBoard.ScriptPbarMax = obj.data.Count; ClsDashBoard.ChangeSPbarValue = true; BGW.ReportProgress(0); i = i + 1; j = 0; //ClsDashBoard.ScriptPbarMax = obj.data.Count; if (obj.data.Count != 0) { foreach (var item in obj.data) { ColEodData.Add(new ClsPriceDataSet() { ScriptId = Scode.ScriptId, Date = Convert.ToDateTime(item[0].ToString()), OpenPrice = item[1] != null ? Convert.ToDouble(item[1].ToString()) : 0.0, HighPrice = item[2] != null ? Convert.ToDouble(item[2].ToString()) : 0.0, LowPrice = item[3] != null ? Convert.ToDouble(item[3].ToString()) : 0.0, LastPrice = item[4] != null ? Convert.ToDouble(item[4].ToString()) : 0.0, ClosePrice = item[5] != null ? Convert.ToDouble(item[5].ToString()) : 0.0, TotalVal = item[6] != null ? Convert.ToDouble(item[6].ToString()) : 0.0, TurnOver = item[7] != null ? Convert.ToDouble(item[7].ToString()) : 0.0 }); ClsDashBoard.ScriptProgress = j; BGW.ReportProgress(0); j = j + 1; } } else { ColEodData.Add(new ClsPriceDataSet() { ScriptId = Scode.ScriptId, Date = request.StartDate, OpenPrice = 0.0, HighPrice = 0.0, LowPrice = 0.0, LastPrice = 0.0, ClosePrice = 0.0, TotalVal = 0.0, TurnOver = 0.0 }); ClsDashBoard.ScriptProgress = j; BGW.ReportProgress(0); j = j + 1; } ClsDataBase.UpdateEodData(ColEodData, Scode.TableName); ColEodData.Clear(); ClsLog.WriteLog("Data Download for script: " + Scode.ScriptsName + "(" + Scode.ScriptsCode + ") Completed."); } ClsLog.WriteLog("Running EMA DMA SP..."); ClsDashBoard.ScriptOStatus = "Data Download Complete. Running EMA DMA Update SP."; ClsDashBoard.ScriptSStatus = "Data Download Complete. Running EMA DMA Update SP."; BGW.ReportProgress(0); ClsDataBase.UpdateEmaDma(); ClsLog.WriteLog("Running EMA DMA SP...Completed"); } catch (Exception ex) { ClsLog.WriteLog(ex.Message); } }
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); } }