Skip to content

Commit 4adeb3a

Browse files
committed
Adds template downloader/converter classes
1 parent 331adf1 commit 4adeb3a

6 files changed

Lines changed: 212 additions & 1 deletion

File tree

DataLibrary/DataLibrary.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net5.0</TargetFramework>
5+
<RootNamespace>QuantConnect.DataLibrary</RootNamespace>
56
</PropertyGroup>
67

78
<ItemGroup>

DataLibrary/MyCustomDataType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
using QuantConnect.Data;
2323
using System.Collections.Generic;
2424

25-
namespace DataLibrary
25+
namespace QuantConnect.DataLibrary
2626
{
2727
/// <summary>
2828
/// Example custom data type
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
<AssemblyName>process</AssemblyName>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="QuantConnect.Common" Version="2.5.11800" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\DataLibrary\DataLibrary.csproj" />
15+
</ItemGroup>
16+
17+
</Project>

DataProcessing/Program.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 System;
17+
using QuantConnect.Configuration;
18+
using QuantConnect.Logging;
19+
using QuantConnect.Util;
20+
21+
namespace QuantConnect.DataProcessing
22+
{
23+
/// <summary>
24+
/// Entrypoint for the data downloader/converter
25+
/// </summary>
26+
public class Program
27+
{
28+
/// <summary>
29+
/// Entrypoint of the program
30+
/// </summary>
31+
/// <returns>Exit code. 0 equals successful, and any other value indicates the downloader/converter failed.</returns>
32+
public static int Main()
33+
{
34+
// Get the configuration values required for your data downloader/converter.
35+
// You will most likely be getting and setting up the values your downloader/converter need here.
36+
var destinationDataFolderDirectory = Config.Get("temp-output-directory", "/temp-output-directory");
37+
var apiKey = Config.Get($"{VendorDataDownloaderConverter.VendorName}-{VendorDataDownloaderConverter.VendorDataName}-api-key", null);
38+
39+
VendorDataDownloaderConverter instance;
40+
try
41+
{
42+
// Pass in the values we got from the configuration into the downloader/converter.
43+
instance = new VendorDataDownloaderConverter(destinationDataFolderDirectory, apiKey);
44+
}
45+
catch (Exception err)
46+
{
47+
Log.Error(err, $"The downloader/converter for {VendorDataDownloaderConverter.VendorDataName} {VendorDataDownloaderConverter.VendorDataName} data failed to be constructed");
48+
return 1;
49+
}
50+
51+
// No need to edit anything below here for most use cases.
52+
// The downloader/converter is ran and cleaned up for you safely here.
53+
try
54+
{
55+
// Run the data downloader/converter.
56+
var success = instance.Run();
57+
if (!success)
58+
{
59+
Log.Error($"QuantConnect.DataProcessing.Program.Main(): Failed to download/process {VendorDataDownloaderConverter.VendorName} {VendorDataDownloaderConverter.VendorDataName} data");
60+
return 1;
61+
}
62+
}
63+
catch (Exception err)
64+
{
65+
Log.Error(err, $"The downloader/converter for {VendorDataDownloaderConverter.VendorDataName} {VendorDataDownloaderConverter.VendorDataName} data exited unexpectedly");
66+
return 1;
67+
}
68+
finally
69+
{
70+
// Run cleanup of the downloader/converter once it has finished or crashed.
71+
instance.DisposeSafely();
72+
}
73+
74+
// The downloader/converter was successful
75+
return 0;
76+
}
77+
}
78+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
}

MyCustomDataType.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataLibrary", "DataLibrary\
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{46223B6F-6400-4C76-9066-441E8ACB6A21}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataProcessing", "DataProcessing\DataProcessing.csproj", "{9F1E4E69-1D72-4432-93FD-2257EE8FCE0A}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -20,6 +22,10 @@ Global
2022
{46223B6F-6400-4C76-9066-441E8ACB6A21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2123
{46223B6F-6400-4C76-9066-441E8ACB6A21}.Release|Any CPU.ActiveCfg = Release|Any CPU
2224
{46223B6F-6400-4C76-9066-441E8ACB6A21}.Release|Any CPU.Build.0 = Release|Any CPU
25+
{9F1E4E69-1D72-4432-93FD-2257EE8FCE0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{9F1E4E69-1D72-4432-93FD-2257EE8FCE0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{9F1E4E69-1D72-4432-93FD-2257EE8FCE0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{9F1E4E69-1D72-4432-93FD-2257EE8FCE0A}.Release|Any CPU.Build.0 = Release|Any CPU
2329
EndGlobalSection
2430
GlobalSection(SolutionProperties) = preSolution
2531
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)