-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
242 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,10 @@ jobs: | |
-warnAsError | ||
- name: Test indicators | ||
id: test-library | ||
env: | ||
ALPACA_KEY: ${{ secrets.ALPACA_KEY }} | ||
ALPACA_SECRET: ${{ secrets.ALPACA_SECRET }} | ||
run: > | ||
dotnet test tests/indicators/Tests.Indicators.csproj | ||
--configuration Release | ||
|
@@ -49,6 +53,7 @@ jobs: | |
--results-directory ./test-indicators | ||
- name: Test other items | ||
id: test-other | ||
run: > | ||
dotnet test tests/other/Tests.Other.csproj | ||
--configuration Release | ||
|
@@ -59,7 +64,7 @@ jobs: | |
- name: Update tests summary | ||
uses: bibipkins/[email protected] | ||
if: github.event_name == 'pull_request' | ||
if: ${{ github.event_name == 'pull_request' && (success() || (failure() && (steps.test-library.conclusion == 'failure' || steps.test-other.conclusion == 'failure'))) }} | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
comment-title: "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Alpaca.Markets; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Skender.Stock.Indicators; | ||
|
||
namespace Tests.Indicators; | ||
|
||
internal class FeedData | ||
{ | ||
internal static async Task<IEnumerable<Quote>> GetQuotes(string symbol) | ||
=> await GetQuotes(symbol, 365 * 2) | ||
.ConfigureAwait(false); | ||
|
||
internal static async Task<IEnumerable<Quote>> GetQuotes(string symbol, int days) | ||
{ | ||
/* This won't run if environment variables not set. | ||
Use FeedData.InconclusiveIfNotSetup() in tests. | ||
(1) get your API keys | ||
https://alpaca.markets/docs/market-data/getting-started/ | ||
(2) manually install in your environment (replace value) | ||
setx ALPACA_KEY "y0ur_Alp@ca_K3Y_v@lue" | ||
setx ALPACA_SECRET "y0ur_Alp@ca_S3cret_v@lue" | ||
****************************************************/ | ||
|
||
// get and validate keys | ||
string alpacaApiKey = Environment.GetEnvironmentVariable("ALPACA_KEY"); | ||
string alpacaSecret = Environment.GetEnvironmentVariable("ALPACA_SECRET"); | ||
|
||
if (string.IsNullOrEmpty(alpacaApiKey) || string.IsNullOrEmpty(alpacaSecret)) | ||
{ | ||
Assert.Inconclusive("Data feed unusable. Environment variables missing."); | ||
} | ||
|
||
ArgumentException.ThrowIfNullOrEmpty(nameof(alpacaApiKey)); | ||
ArgumentException.ThrowIfNullOrEmpty(nameof(alpacaSecret)); | ||
|
||
// connect to Alpaca REST API | ||
SecretKey secretKey = new(alpacaApiKey, alpacaSecret); | ||
|
||
IAlpacaDataClient client = Environments | ||
.Paper | ||
.GetAlpacaDataClient(secretKey); | ||
|
||
// compose request | ||
// (excludes last 15 minutes for free delayed quotes) | ||
DateTime into = DateTime.Now.Subtract(TimeSpan.FromMinutes(16)); | ||
DateTime from = into.Subtract(TimeSpan.FromDays(days)); | ||
|
||
HistoricalBarsRequest request = new(symbol, from, into, BarTimeFrame.Day); | ||
|
||
// fetch minute-bar quotes in Alpaca's format | ||
IPage<IBar> barSet = await client | ||
.ListHistoricalBarsAsync(request) | ||
.ConfigureAwait(false); | ||
|
||
// convert library compatible quotes | ||
IEnumerable<Quote> quotes = barSet | ||
.Items | ||
.Select(bar => new Quote | ||
{ | ||
Date = bar.TimeUtc, | ||
Open = bar.Open, | ||
High = bar.High, | ||
Low = bar.Low, | ||
Close = bar.Close, | ||
Volume = bar.Volume | ||
}) | ||
.OrderBy(x => x.Date); | ||
|
||
return quotes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.