Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/_tests-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ on:
required: true
type: string

permissions:
contents: read
pull-requests: write
checks: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ on:
schedule:
- cron: '0 2 * * *' # each day at 2 AM UTC
workflow_dispatch: # manual trigger


permissions:
contents: read
pull-requests: write
checks: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/deploy-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ name: "Deploy Nuget"
on:
workflow_dispatch: # Manual trigger

permissions:
contents: read
pull-requests: write
checks: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/tests-alphavantage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ on:
workflow_dispatch: # Manual trigger
schedule:
- cron: '0 2 * * *' # Runs nightly at 2 AM UTC on main branch


permissions:
contents: read
pull-requests: write
checks: write
id-token: write

jobs:
run-test:
uses: ./.github/workflows/_tests-template.yml
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/tests-datahub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ on:
schedule:
- cron: '0 2 * * *' # Runs nightly at 2 AM UTC on main branch

permissions:
contents: read
pull-requests: write
checks: write
id-token: write

jobs:
run-test:
uses: ./.github/workflows/_tests-template.yml
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/tests-xetra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ on:
schedule:
- cron: '0 2 * * *' # Runs nightly at 2 AM UTC on main branch

permissions:
contents: read
pull-requests: write
checks: write
id-token: write

jobs:
run-test:
uses: ./.github/workflows/_tests-template.yml
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/tests-yahoo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ on:
schedule:
- cron: '0 2 * * *' # Runs nightly at 2 AM UTC on main branch

permissions:
contents: read
pull-requests: write
checks: write
id-token: write

jobs:
run-test:
uses: ./.github/workflows/_tests-template.yml
Expand Down
5 changes: 5 additions & 0 deletions release-notes/v1.0.11.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### What's Changed

* Fix: Making Polly AsyncPolicy optional.


2 changes: 1 addition & 1 deletion src/Finance.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<PackageId>Finance.NET</PackageId>
<Version>1.0.10</Version>
<Version>1.0.11</Version>
<Authors>Thorsten Alpers</Authors>
<Owners>Thorsten Alpers</Owners>
<Description>A .NET library for retrieving real-time and historical financial data from Yahoo Finance and other popular sources.</Description>
Expand Down
52 changes: 44 additions & 8 deletions src/Services/AlphaVantageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,51 @@

namespace Finance.Net.Services;
/// <inheritdoc />
public class AlphaVantageService(ILogger<AlphaVantageService> logger,
IHttpClientFactory httpClientFactory,
IOptions<FinanceNetConfiguration> options,
IReadOnlyPolicyRegistry<string> policyRegistry) : IAlphaVantageService
public class AlphaVantageService : IAlphaVantageService
{
private readonly ILogger<AlphaVantageService> _logger = logger ?? throw new ArgumentNullException(nameof(logger));
private readonly IHttpClientFactory _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
private readonly FinanceNetConfiguration _options = options?.Value ?? throw new ArgumentNullException(nameof(options));
private readonly AsyncPolicy _retryPolicy = policyRegistry?.Get<AsyncPolicy>(Constants.DefaultHttpRetryPolicy) ?? throw new ArgumentNullException(nameof(policyRegistry));
private readonly ILogger<AlphaVantageService> _logger;
private readonly IHttpClientFactory _httpClientFactory;
private readonly FinanceNetConfiguration _options;
private readonly IAsyncPolicy _retryPolicy;

/// <inheritdoc />
public AlphaVantageService(
ILogger<AlphaVantageService> logger,
IHttpClientFactory httpClientFactory,
IOptions<FinanceNetConfiguration> options,
IReadOnlyPolicyRegistry<string>? policyRegistry = null)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
_options = options?.Value ?? throw new ArgumentNullException(nameof(options));

if (policyRegistry != null &&
policyRegistry.TryGet<IAsyncPolicy>(Constants.DefaultHttpRetryPolicy, out var found))
{
_retryPolicy = found;
}
else
{
_retryPolicy = Policy
.Handle<HttpRequestException>()
.Or<TaskCanceledException>()
.WaitAndRetryAsync(
3,
attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt - 1)),
(ex, ts, retryCount, ctx) =>
{
_logger.LogWarning(
"Retry {RetryCount} wegen {Reason}, warte {Delay}s",
retryCount,
ex?.Message ?? "Unbekannt",
ts.TotalSeconds);
});

_logger.LogWarning(
"Retry-Policy '{PolicyKey}' nicht gefunden – verwende Default (3x Retry, Backoff).",
Constants.DefaultHttpRetryPolicy);
}
}

/// <inheritdoc />
public async Task<InstrumentOverview?> GetOverviewAsync(string symbol, CancellationToken token = default)
Expand Down
7 changes: 5 additions & 2 deletions tests/Services/AlphaVantageServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ public void Constructor_Throws()
_mockHttpClientFactory.Object,
null,
_mockPolicyRegistry.Object));
Assert.Throws<ArgumentNullException>(() => new AlphaVantageService(

var service = new AlphaVantageService(
_mockLogger.Object,
_mockHttpClientFactory.Object,
_mockOptions.Object,
null));
null);

Assert.That(service, Is.Not.Null);
}

[Test]
Expand Down
Loading