Skip to content

Commit d6e734a

Browse files
Updates for tests and bug fixes
1 parent 8208365 commit d6e734a

19 files changed

Lines changed: 278 additions & 711 deletions

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,16 @@ modules.order
5050
Module.symvers
5151
Mkfile.old
5252
dkms.conf
53+
54+
# Build results
55+
[Dd]ebug/
56+
[Dd]ebugPublic/
57+
[Rr]elease/
58+
[Rr]eleases/
59+
x64/
60+
x86/
61+
.vs/
62+
build/
63+
bld/
64+
[Bb]in/
65+
[Oo]bj/

Demonstration.cs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
33
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
44
*
@@ -19,6 +19,8 @@
1919
using QuantConnect.Orders;
2020
using QuantConnect.Algorithm;
2121
using QuantConnect.DataSource;
22+
using QuantConnect.Data.Market;
23+
using QuantConnect.Securities.Future;
2224

2325
namespace QuantConnect.DataLibrary.Tests
2426
{
@@ -27,18 +29,18 @@ namespace QuantConnect.DataLibrary.Tests
2729
/// </summary>
2830
public class CustomDataAlgorithm : QCAlgorithm
2931
{
30-
private Symbol _customDataSymbol;
31-
private Symbol _equitySymbol;
32+
private Future _esFuture;
3233

3334
/// <summary>
3435
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
3536
/// </summary>
3637
public override void Initialize()
3738
{
38-
SetStartDate(2013, 10, 07); //Set Start Date
39-
SetEndDate(2013, 10, 11); //Set End Date
40-
_equitySymbol = AddEquity("SPY").Symbol;
41-
_customDataSymbol = AddData<DataBentoDataType>(_equitySymbol).Symbol;
39+
SetStartDate(2021, 10, 07); //Set Start Date
40+
SetEndDate(2021, 10, 11); //Set End Date
41+
_esFuture = AddFuture("ES");
42+
43+
_esFuture.SetFilter(0, 182);
4244
}
4345

4446
/// <summary>
@@ -47,18 +49,9 @@ public override void Initialize()
4749
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
4850
public override void OnData(Slice slice)
4951
{
50-
var data = slice.Get<DataBentoDataType>();
51-
if (!data.IsNullOrEmpty())
52+
if (!Portfolio.Invested)
5253
{
53-
// based on the custom data property we will buy or short the underlying equity
54-
if (data[_customDataSymbol].SomeCustomProperty == "buy")
55-
{
56-
SetHoldings(_equitySymbol, 1);
57-
}
58-
else if (data[_customDataSymbol].SomeCustomProperty == "sell")
59-
{
60-
SetHoldings(_equitySymbol, -1);
61-
}
54+
SetHoldings(_esFuture.Symbol, 1);
6255
}
6356
}
6457

DemonstrationUniverse.cs

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,55 +24,5 @@ namespace QuantConnect.Algorithm.CSharp
2424
/// Example algorithm using the custom data type as a source of alpha
2525
/// </summary>
2626
public class CustomDataUniverse : QCAlgorithm
27-
{
28-
/// <summary>
29-
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
30-
/// </summary>
31-
public override void Initialize()
32-
{
33-
// Data ADDED via universe selection is added with Daily resolution.
34-
UniverseSettings.Resolution = Resolution.Daily;
35-
36-
SetStartDate(2022, 2, 14);
37-
SetEndDate(2022, 2, 18);
38-
SetCash(100000);
39-
40-
// add a custom universe data source (defaults to usa-equity)
41-
var universe = AddUniverse<DataBentoDataUniverse>(data =>
42-
{
43-
foreach (DataBentoDataUniverse datum in data)
44-
{
45-
Log($"{datum.Symbol},{datum.SomeCustomProperty},{datum.SomeNumericProperty}");
46-
}
47-
48-
// define our selection criteria
49-
return from DataBentoDataUniverse d in data
50-
where d.SomeCustomProperty == "buy"
51-
select d.Symbol;
52-
});
53-
54-
var history = History(universe, 1).ToList();
55-
if (history.Count != 1)
56-
{
57-
throw new System.Exception($"Unexpected historical data count!");
58-
}
59-
foreach (var dataForDate in history)
60-
{
61-
var coarseData = dataForDate.ToList();
62-
if (coarseData.Count < 300)
63-
{
64-
throw new System.Exception($"Unexpected historical universe data!");
65-
}
66-
}
67-
}
68-
69-
/// <summary>
70-
/// Event fired each time that we add/remove securities from the data feed
71-
/// </summary>
72-
/// <param name="changes">Security additions/removals for this time step</param>
73-
public override void OnSecuritiesChanged(SecurityChanges changes)
74-
{
75-
Log(changes.ToString());
76-
}
77-
}
27+
{ }
7828
}

Lean.DataSource.DataBento.sln

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio Version 17
33
VisualStudioVersion = 17.5.2.0
44
MinimumVisualStudioVersion = 10.0.40219.1
5-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuantConnect.DataSource", "QuantConnect.DataSource.csproj", "{367AEEDC-F0B3-7F47-539D-10E5EC242C2A}"
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuantConnect.DataBento", "QuantConnect.DataBento\QuantConnect.DataSource.DataBento.csproj", "{367AEEDC-F0B3-7F47-539D-10E5EC242C2A}"
66
EndProject
7-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataProcessing", "DataProcessing\DataProcessing.csproj", "{4B379C8F-16CE-1972-73E3-C14F6410D428}"
8-
EndProject
9-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "tests\Tests.csproj", "{9CF47860-2CEA-F379-09D8-9AEF27965D12}"
7+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuantConnect.DataBento.Tests", "QuantConnect.DataBento.Tests\QuantConnect.DataSource.DataBento.Tests.csproj", "{9CF47860-2CEA-F379-09D8-9AEF27965D12}"
108
EndProject
119
Global
1210
GlobalSection(SolutionConfigurationPlatforms) = preSolution

QuantConnect.DataBento.Tests/DataBentoDataDownloaderTests.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,20 @@
2121
using QuantConnect.Data.Market;
2222
using QuantConnect.Lean.DataSource.DataBento;
2323
using QuantConnect.Logging;
24+
using QuantConnect.Configuration;
2425

25-
namespace QuantConnect.DataLibrary.Tests
26+
namespace QuantConnect.Lean.DataSource.DataBento.Tests
2627
{
2728
[TestFixture]
2829
public class DataBentoDataDownloaderTests
2930
{
3031
private DataBentoDataDownloader _downloader;
32+
private readonly string _apiKey = Config.Get("databento-api-key");
3133

3234
[SetUp]
3335
public void SetUp()
3436
{
35-
TestSetup.GlobalSetup();
36-
_downloader = new DataBentoDataDownloader();
37+
_downloader = new DataBentoDataDownloader(_apiKey);
3738
}
3839

3940
[TearDown]
@@ -98,21 +99,12 @@ public void DownloadsHistoricalData(string ticker, SecurityType securityType, st
9899
Assert.Greater(tick.Value, 0, "Tick value should be positive");
99100
Assert.GreaterOrEqual(tick.Quantity, 0, "Tick quantity should be non-negative");
100101
}
101-
else if (data is DataBentoDataType dataBentoData)
102-
{
103-
Assert.Greater(dataBentoData.Close, 0, "DataBento close price should be positive");
104-
Assert.GreaterOrEqual(dataBentoData.Volume, 0, "DataBento volume should be non-negative");
105-
Assert.Greater(dataBentoData.High, 0, "DataBento high price should be positive");
106-
Assert.Greater(dataBentoData.Low, 0, "DataBento low price should be positive");
107-
Assert.Greater(dataBentoData.Open, 0, "DataBento open price should be positive");
108-
Assert.IsNotNull(dataBentoData.RawSymbol, "RawSymbol should not be null");
109-
}
110102
}
111103
}
112104

113105
[Test]
114-
[TestCase("ZNM3", SecurityType.Future, Market.CBOT, Resolution.Daily, TickType.Trade)]
115-
[TestCase("ZNM3", SecurityType.Future, Market.CBOT, Resolution.Hour, TickType.Trade)]
106+
[TestCase("ZNM3", SecurityType.Future, Market.CME, Resolution.Daily, TickType.Trade)]
107+
[TestCase("ZNM3", SecurityType.Future, Market.CME, Resolution.Hour, TickType.Trade)]
116108
[Explicit("This test requires a configured DataBento API key")]
117109
public void DownloadsFuturesHistoricalData(string ticker, SecurityType securityType, string market, Resolution resolution, TickType tickType)
118110
{
@@ -176,7 +168,7 @@ public void DataIsSortedByTime()
176168
for (int i = 1; i < downloadResponse.Count; i++)
177169
{
178170
Assert.GreaterOrEqual(downloadResponse[i].Time, downloadResponse[i - 1].Time,
179-
$"Data should be sorted by time. Item {i} time {downloadResponse[i].Time} should be >= item {i-1} time {downloadResponse[i-1].Time}");
171+
$"Data should be sorted by time. Item {i} time {downloadResponse[i].Time} should be >= item {i - 1} time {downloadResponse[i - 1].Time}");
180172
}
181173
}
182174

QuantConnect.DataBento.Tests/DataBentoDataProviderHistoryTests.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,25 @@
1919
using NUnit.Framework;
2020
using QuantConnect.Data;
2121
using QuantConnect.Util;
22-
using QuantConnect.Tests;
2322
using QuantConnect.Lean.DataSource.DataBento;
2423
using QuantConnect.Securities;
2524
using System.Collections.Generic;
2625
using QuantConnect.Logging;
26+
using QuantConnect.Data.Market;
27+
using QuantConnect.Configuration;
2728

28-
namespace QuantConnect.DataLibrary.Tests
29+
namespace QuantConnect.Lean.DataSource.DataBento.Tests
2930
{
3031
[TestFixture]
3132
public class DataBentoDataProviderHistoryTests
3233
{
3334
private DataBentoProvider _historyDataProvider;
35+
private readonly string _apiKey = Config.Get("databento-api-key");
3436

3537
[SetUp]
3638
public void SetUp()
3739
{
38-
TestSetup.GlobalSetup();
39-
_historyDataProvider = new DataBentoProvider();
40+
_historyDataProvider = new DataBentoProvider(_apiKey);
4041
}
4142

4243
[TearDown]
@@ -49,12 +50,11 @@ internal static IEnumerable<TestCaseData> TestParameters
4950
{
5051
get
5152
{
52-
TestGlobals.Initialize();
5353

5454
// DataBento futures
5555
var esMini = Symbol.Create("ESM3", SecurityType.Future, Market.CME);
56-
var znNote = Symbol.Create("ZNM3", SecurityType.Future, Market.CBOT);
57-
var gcGold = Symbol.Create("GCM3", SecurityType.Future, Market.COMEX);
56+
var znNote = Symbol.Create("ZNM3", SecurityType.Future, Market.CME);
57+
var gcGold = Symbol.Create("GCM3", SecurityType.Future, Market.CME);
5858

5959
// test cases for supported futures
6060
yield return new TestCaseData(esMini, Resolution.Daily, TickType.Trade, TimeSpan.FromDays(5), false)
@@ -104,7 +104,7 @@ public void GetsHistory(Symbol symbol, Resolution resolution, TickType tickType,
104104

105105
try
106106
{
107-
var slices = _historyDataProvider.GetHistory(new[] { request }, TimeZones.Utc)?.ToList();
107+
var slices = _historyDataProvider.GetHistory(request)?.Select(data => new Slice(data.Time, new[] { data }, data.Time.ConvertToUtc(request.DataTimeZone))).ToList();
108108

109109
if (expectsNoData)
110110
{
@@ -151,12 +151,22 @@ public void GetsHistory(Symbol symbol, Resolution resolution, TickType tickType,
151151
public void GetHistoryWithMultipleSymbols()
152152
{
153153
var symbol1 = Symbol.Create("ESM3", SecurityType.Future, Market.CME);
154-
var symbol2 = Symbol.Create("ZNM3", SecurityType.Future, Market.CBOT);
154+
var symbol2 = Symbol.Create("ZNM3", SecurityType.Future, Market.CME);
155155

156156
var request1 = GetHistoryRequest(Resolution.Daily, TickType.Trade, symbol1, TimeSpan.FromDays(3));
157157
var request2 = GetHistoryRequest(Resolution.Daily, TickType.Trade, symbol2, TimeSpan.FromDays(3));
158158

159-
var slices = _historyDataProvider.GetHistory(new[] { request1, request2 }, TimeZones.Utc)?.ToList();
159+
var history1 = _historyDataProvider.GetHistory(request1);
160+
var history2 = _historyDataProvider.GetHistory(request2);
161+
162+
var allData = new List<BaseData>();
163+
if (history1 != null) allData.AddRange(history1);
164+
if (history2 != null) allData.AddRange(history2);
165+
166+
// timezone from the first request
167+
var slices = allData.GroupBy(d => d.Time)
168+
.Select(g => new Slice(g.Key, g.ToList(), g.Key.ConvertToUtc(request1.DataTimeZone)))
169+
.ToList();
160170

161171
Assert.IsNotNull(slices, "Expected to receive history data for multiple symbols");
162172

0 commit comments

Comments
 (0)