public void BacktestingData_CanBeDownloadedAndSaved_Successfully() { var minutePath = Path.Combine(_dataFolder, "forex/oanda/minute/eurusd/20131011_quote.zip"); var dailyPath = Path.Combine(_dataFolder, "forex/oanda/daily/eurusd.zip"); if (File.Exists(dailyPath)) { File.Delete(dailyPath); } if (File.Exists(minutePath)) { File.Delete(minutePath); } var downloadedMinuteData = _api.DownloadData(new Symbol(SecurityIdentifier.GenerateForex("EURUSD", Market.Oanda), "EURUSD"), Resolution.Minute, new DateTime(2013, 10, 11)); var downloadedDailyData = _api.DownloadData(new Symbol(SecurityIdentifier.GenerateForex("EURUSD", Market.Oanda), "EURUSD"), Resolution.Daily, new DateTime(2013, 10, 07)); Assert.IsTrue(downloadedMinuteData); Assert.IsTrue(downloadedDailyData); Assert.IsTrue(File.Exists(dailyPath)); Assert.IsTrue(File.Exists(minutePath)); }
/// <summary> /// Attempt to download data using the Api for and return a FileStream of that data. /// </summary> /// <param name="key"></param> /// <param name="symbol"></param> /// <param name="date"></param> /// <param name="resolution"></param> /// <returns>A FileStream of the data</returns> private FileStream DownloadData(string filepath, Symbol symbol, DateTime date, Resolution resolution) { Log.Trace("ApiDataProvider.Fetch(): Attempting to get data from QuantConnect.com's data library for symbol({0}), resolution({1}) and date({2}).", symbol.Value, resolution, date.Date.ToShortDateString()); var downloadSuccessful = _api.DownloadData(symbol, resolution, date); if (downloadSuccessful) { Log.Trace("ApiDataProvider.Fetch(): Successfully retrieved data for symbol({0}), resolution({1}) and date({2}).", symbol.Value, resolution, date.Date.ToShortDateString()); return(new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read)); } // Failed to download Log.Error("ApiDataProvider.Fetch(): Unable to remotely retrieve data for path {0}. " + "Please make sure you have the necessary data in your online QuantConnect data library.", filepath); return(null); }
public bool Fetch(Symbol symbol, DateTime date, Resolution resolution, TickType tickType) { Log.Trace( string.Format( "Attempting to get data from QuantConnect.com's data library for symbol({0}), resolution({1}) and date({2}).", symbol.ID, resolution, date.Date.ToShortDateString())); var api = new Api.Api(); api.Initialize(_uid, _token, _dataPath); var download = api.DownloadData(symbol, resolution, date); if (download) { Log.Trace( string.Format( "Successfully retrieved data for symbol({0}), resolution({1}) and date({2}).", symbol.ID, resolution, date.Date.ToShortDateString())); return(true); } Log.Error( string.Format( "Unable to remotely retrieve data for symbol({0}), resolution({1}) and date({2}). Please make sure you have the necessary data in your online QuantConnect data library.", symbol.ID, resolution, date.Date.ToShortDateString())); return(false); }
/// <summary> /// Attempt to download data using the Api for and return a FileStream of that data. /// </summary> /// <param name="filePath">The path to store the file</param> /// <returns>A FileStream of the data</returns> protected virtual bool DownloadData(string filePath) { if (Log.DebuggingEnabled) { Log.Debug($"ApiDataProvider.Fetch(): Attempting to get data from QuantConnect.com's data library for {filePath}."); } if (_api.DownloadData(filePath, _organizationId)) { Log.Trace($"ApiDataProvider.Fetch(): Successfully retrieved data for {filePath}."); return(true); } // Failed to download; _api.DownloadData() will post error return(false); }
/// <summary> /// Retrieves data to be used in an algorithm. /// If file does not exist, an attempt is made to download them from the api /// </summary> /// <param name="key">A string representing where the data is stored</param> /// <returns>A <see cref="Stream"/> of the data requested</returns> public Stream Fetch(string key) { if (File.Exists(key)) { return(new FileStream(key, FileMode.Open, FileAccess.Read)); } // If the file cannot be found on disc, attempt to retrieve it from the API Symbol symbol; DateTime date; Resolution resolution; if (LeanData.TryParsePath(key, out symbol, out date, out resolution)) { Log.Trace("ApiDataProvider.Fetch(): Attempting to get data from QuantConnect.com's data library for symbol({0}), resolution({1}) and date({2}).", symbol.Value, resolution, date.Date.ToShortDateString()); var downloadSuccessful = _api.DownloadData(symbol, resolution, date); if (downloadSuccessful) { Log.Trace("ApiDataProvider.Fetch(): Successfully retrieved data for symbol({0}), resolution({1}) and date({2}).", symbol.Value, resolution, date.Date.ToShortDateString()); return(new FileStream(key, FileMode.Open, FileAccess.Read)); } } Log.Error("ApiDataProvider.Fetch(): Unable to remotely retrieve data for path {0}. " + "Please make sure you have the necessary data in your online QuantConnect data library.", key); return(null); }