|
| 1 | +/* |
| 2 | + * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. |
| 3 | + * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | +*/ |
| 15 | + |
| 16 | +using QuantConnect.Logging; |
| 17 | +using System; |
| 18 | +using System.IO; |
| 19 | + |
| 20 | +namespace QuantConnect.DataProcessing |
| 21 | +{ |
| 22 | + /// <summary> |
| 23 | + /// Data downloader/converter class example |
| 24 | + /// </summary> |
| 25 | + public class VendorDataDownloaderConverter : IDisposable |
| 26 | + { |
| 27 | + /// <summary> |
| 28 | + /// Name of the vendor. Only alphanumeric characters, all lowercase and no underscores/spaces. |
| 29 | + /// </summary> |
| 30 | + public const string VendorName = "gaussgodel"; |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Type of data that we are downloading/converting. Only alphanumeric characters, all lowercase and no underscores/spaces. |
| 34 | + /// </summary> |
| 35 | + public const string VendorDataName = "flights"; |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// API key to download data with |
| 39 | + /// </summary> |
| 40 | + private readonly string _apiKey; |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Directory that data will be outputted to |
| 44 | + /// </summary> |
| 45 | + private readonly string _destinationDirectory; |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + /// Has the class been cleaned up yet |
| 49 | + /// </summary> |
| 50 | + private bool _disposed; |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// Creates a new instance of the data downloader/converter |
| 54 | + /// </summary> |
| 55 | + /// <param name="destinationDataFolder">The path to the data folder we want to save data to</param> |
| 56 | + /// <param name="apiKey">The API key to download data with</param> |
| 57 | + public VendorDataDownloaderConverter(string destinationDataFolder, string apiKey = null) |
| 58 | + { |
| 59 | + _apiKey = apiKey; |
| 60 | + _destinationDirectory = Path.Combine( |
| 61 | + destinationDataFolder, |
| 62 | + "alternative", |
| 63 | + VendorName, |
| 64 | + VendorDataName); |
| 65 | + |
| 66 | + // Create the directory ahead of time so that we don't get |
| 67 | + // errors when trying to write to this output directory. |
| 68 | + Directory.CreateDirectory(_destinationDirectory); |
| 69 | + } |
| 70 | + |
| 71 | + /// <summary> |
| 72 | + /// Begins running the downloader/converter |
| 73 | + /// </summary> |
| 74 | + /// <returns>True if downloading/converting was successful, false otherwise</returns> |
| 75 | + public bool Run() |
| 76 | + { |
| 77 | + try |
| 78 | + { |
| 79 | + // Your data downloading/processing code goes here |
| 80 | + } |
| 81 | + catch (Exception e) |
| 82 | + { |
| 83 | + Log.Error(e, $"Failed to download/convert {VendorName} {VendorDataName} data"); |
| 84 | + return false; |
| 85 | + } |
| 86 | + |
| 87 | + return true; |
| 88 | + } |
| 89 | + |
| 90 | + /// <summary> |
| 91 | + /// If you need to shut down things like database connections, threads, or other |
| 92 | + /// resources that require manual shutdown, do it here. This will be called after |
| 93 | + /// we're done with the <see cref="Run"/> method. |
| 94 | + /// |
| 95 | + /// You don't have to implement this if you don't need to cleanup resources after we're done downloading/processing. |
| 96 | + /// </summary> |
| 97 | + public void Dispose() |
| 98 | + { |
| 99 | + if (_disposed) |
| 100 | + { |
| 101 | + return; |
| 102 | + } |
| 103 | + |
| 104 | + // Your cleanup goes here. You don't have to implement it |
| 105 | + // if you have nothing that needs to be cleaned up. |
| 106 | + _disposed = true; |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments