Skip to content

Commit c60968d

Browse files
Initial code for DataBento Implementation.
1 parent 7e66db5 commit c60968d

27 files changed

Lines changed: 2968 additions & 0 deletions

.github/workflows/build.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build & Test
2+
3+
on:
4+
push:
5+
branches: ['*']
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-24.04
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
16+
- name: Liberate disk space
17+
uses: jlumbroso/free-disk-space@main
18+
with:
19+
tool-cache: true
20+
large-packages: false
21+
docker-images: false
22+
swap-storage: false
23+
24+
- name: Checkout Lean Same Branch
25+
id: lean-same-branch
26+
uses: actions/checkout@v2
27+
continue-on-error: true
28+
with:
29+
ref: ${{ github.ref }}
30+
repository: QuantConnect/Lean
31+
path: Lean
32+
33+
- name: Checkout Lean Master
34+
if: steps.lean-same-branch.outcome != 'success'
35+
uses: actions/checkout@v2
36+
with:
37+
repository: QuantConnect/Lean
38+
path: Lean
39+
40+
- name: Move Lean
41+
run: mv Lean ../Lean
42+
43+
- uses: addnab/docker-run-action@v3
44+
with:
45+
image: quantconnect/lean:foundation
46+
options: --workdir /__w/Lean.DataSource.SDK/Lean.DataSource.SDK -v /home/runner/work:/__w
47+
shell: bash
48+
run: |
49+
# BuildDataSource
50+
dotnet build ./QuantConnect.DataSource.csproj /p:Configuration=Release /v:quiet /p:WarningLevel=1 && \
51+
# BuildTests
52+
dotnet build ./tests/Tests.csproj /p:Configuration=Release /v:quiet /p:WarningLevel=1 && \
53+
# Run Tests
54+
dotnet test ./tests/bin/Release/net9.0/Tests.dll

Demonstration.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
17+
using QuantConnect.Data;
18+
using QuantConnect.Util;
19+
using QuantConnect.Orders;
20+
using QuantConnect.Algorithm;
21+
using QuantConnect.DataSource;
22+
23+
namespace QuantConnect.DataLibrary.Tests
24+
{
25+
/// <summary>
26+
/// Example algorithm using the custom data type as a source of alpha
27+
/// </summary>
28+
public class CustomDataAlgorithm : QCAlgorithm
29+
{
30+
private Symbol _customDataSymbol;
31+
private Symbol _equitySymbol;
32+
33+
/// <summary>
34+
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
35+
/// </summary>
36+
public override void Initialize()
37+
{
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;
42+
}
43+
44+
/// <summary>
45+
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
46+
/// </summary>
47+
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
48+
public override void OnData(Slice slice)
49+
{
50+
var data = slice.Get<DataBentoDataType>();
51+
if (!data.IsNullOrEmpty())
52+
{
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+
}
62+
}
63+
}
64+
65+
/// <summary>
66+
/// Order fill event handler. On an order fill update the resulting information is passed to this method.
67+
/// </summary>
68+
/// <param name="orderEvent">Order event details containing details of the events</param>
69+
public override void OnOrderEvent(OrderEvent orderEvent)
70+
{
71+
if (orderEvent.Status.IsFill())
72+
{
73+
Debug($"Purchased Stock: {orderEvent.Symbol}");
74+
}
75+
}
76+
}
77+
}

DemonstrationUniverse.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+
17+
using System.Linq;
18+
using QuantConnect.Data.UniverseSelection;
19+
using QuantConnect.DataSource;
20+
21+
namespace QuantConnect.Algorithm.CSharp
22+
{
23+
/// <summary>
24+
/// Example algorithm using the custom data type as a source of alpha
25+
/// </summary>
26+
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+
}
78+
}

Lean.DataSource.DataBento.sln

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.5.2.0
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuantConnect.DataSource", "QuantConnect.DataSource.csproj", "{367AEEDC-F0B3-7F47-539D-10E5EC242C2A}"
6+
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}"
10+
EndProject
11+
Global
12+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
13+
Debug|Any CPU = Debug|Any CPU
14+
Release|Any CPU = Release|Any CPU
15+
EndGlobalSection
16+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
17+
{367AEEDC-F0B3-7F47-539D-10E5EC242C2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{367AEEDC-F0B3-7F47-539D-10E5EC242C2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{367AEEDC-F0B3-7F47-539D-10E5EC242C2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{367AEEDC-F0B3-7F47-539D-10E5EC242C2A}.Release|Any CPU.Build.0 = Release|Any CPU
21+
{4B379C8F-16CE-1972-73E3-C14F6410D428}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{4B379C8F-16CE-1972-73E3-C14F6410D428}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{4B379C8F-16CE-1972-73E3-C14F6410D428}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{4B379C8F-16CE-1972-73E3-C14F6410D428}.Release|Any CPU.Build.0 = Release|Any CPU
25+
{9CF47860-2CEA-F379-09D8-9AEF27965D12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{9CF47860-2CEA-F379-09D8-9AEF27965D12}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{9CF47860-2CEA-F379-09D8-9AEF27965D12}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{9CF47860-2CEA-F379-09D8-9AEF27965D12}.Release|Any CPU.Build.0 = Release|Any CPU
29+
EndGlobalSection
30+
GlobalSection(SolutionProperties) = preSolution
31+
HideSolutionNode = FALSE
32+
EndGlobalSection
33+
GlobalSection(ExtensibilityGlobals) = postSolution
34+
SolutionGuid = {CE272A88-90FF-4452-B402-D3AD0D08FB15}
35+
EndGlobalSection
36+
EndGlobal

0 commit comments

Comments
 (0)