Skip to content

Commit

Permalink
Issue #731 - The ListOptionContractsAsAsyncEnumerable extensions me…
Browse files Browse the repository at this point in the history
…thod uses page token now.
  • Loading branch information
OlegRa committed Apr 7, 2024
1 parent cb251fa commit c064e9b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 31 deletions.
5 changes: 2 additions & 3 deletions Alpaca.Markets.Extensions.Tests/AlpacaTradingClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task ListAccountActivitiesAsAsyncEnumerableWorks()
Assert.NotEqual(0, counter);
}

[Fact(Skip = "Disable temporary until extensions package update")]
[Fact]
public async Task ListOptionContractsAsAsyncEnumerableWorks()
{
using var mock = mockClientsFactory.GetAlpacaTradingClientMock();
Expand All @@ -54,8 +54,7 @@ public async Task ListOptionContractsAsAsyncEnumerableWorks()
addSinglePageExpectationOfOptionContracts(mock);

var counter = await validateList(
mock.Client.ListOptionContractsAsAsyncEnumerable(
new OptionContractsRequest(Symbol)));
mock.Client.ListOptionContractsAsAsyncEnumerable(new OptionContractsRequest()));

Assert.NotEqual(0, counter);
}
Expand Down
2 changes: 1 addition & 1 deletion Alpaca.Markets.Extensions/Alpaca.Markets.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" PrivateAssets="compile;contentfiles;build;analyzers" />
<PackageReference Include="System.Threading.Channels" Version="8.0.0" PrivateAssets="compile;contentfiles;build;analyzers" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" PrivateAssets="compile;contentfiles;build;analyzers" />
<PackageReference Include="Alpaca.Markets" Version="7.1.0-beta1" PrivateAssets="compile;contentfiles;build;analyzers;" />
<PackageReference Include="Alpaca.Markets" Version="7.1.0-beta2" PrivateAssets="compile;contentfiles;build;analyzers;" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,18 @@ private static async IAsyncEnumerable<IAccountActivity> getAllAccountActivitiesP
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static OptionContractsRequest getRequestForFirstPage(
OptionContractsRequest request) =>
new(request.UnderlyingSymbol)
new(request.UnderlyingSymbols)
{
ExpirationDateGreaterThanOrEqualTo = request.ExpirationDateGreaterThanOrEqualTo,
ExpirationDateLessThanOrEqualTo = request.ExpirationDateLessThanOrEqualTo,
StrikePriceGreaterThanOrEqualTo = request.StrikePriceGreaterThanOrEqualTo,
StrikePriceLessThanOrEqualTo = request.StrikePriceLessThanOrEqualTo,
ExpirationDateEqualTo = request.ExpirationDateEqualTo,
Pagination = { Size = Pagination.MaxPageSize },
AssetStatus = request.AssetStatus,
OptionStyle = request.OptionStyle,
OptionType = request.OptionType,
RootSymbol = request.RootSymbol,
PageSize = request.PageSize,
PageNumber = 1 // Explicitly set this to 1
RootSymbol = request.RootSymbol
};

private static async IAsyncEnumerable<IOptionContract> getAllOptionContractsPages(
Expand All @@ -197,17 +196,12 @@ private static async IAsyncEnumerable<IOptionContract> getAllOptionContractsPage
var contracts = await client
.ListOptionContractsAsync(request, cancellationToken).ConfigureAwait(false);

if (contracts.Count == 0)
{
break; // The only way to check if paging completed
}

foreach (var item in contracts)
foreach (var item in contracts.Items)
{
yield return item;
}

++request.PageNumber;
} while (request.PageNumber < UInt32.MaxValue);
request.Pagination.Token = contracts.NextPageToken ?? String.Empty;
} while (!String.IsNullOrEmpty(request.Pagination.Token));
}
}
24 changes: 12 additions & 12 deletions Alpaca.Markets.Extensions/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
".NETFramework,Version=v4.6.2": {
"Alpaca.Markets": {
"type": "Direct",
"requested": "[7.1.0-beta1, )",
"resolved": "7.1.0-beta1",
"contentHash": "DKGJ828sdwjDTfU9dNvq7L6ZODqgvxfbjko5pnB/RSEoQeEqJx0uz6Sate+7GLm3tTLsRteuG3UxLrnQJ69iUQ==",
"requested": "[7.1.0-beta2, )",
"resolved": "7.1.0-beta2",
"contentHash": "RXGBzIgj1ZgiUejxBQzOqjBOLhVW1I2AtI+9QXhhSdPHoZDHCdHnhO4awxq/hymkfgT5XtsFPpXhewH3Wkvuqw==",
"dependencies": {
"Newtonsoft.Json": "13.0.3",
"Polly": "8.3.0",
Expand Down Expand Up @@ -314,9 +314,9 @@
".NETStandard,Version=v2.0": {
"Alpaca.Markets": {
"type": "Direct",
"requested": "[7.1.0-beta1, )",
"resolved": "7.1.0-beta1",
"contentHash": "DKGJ828sdwjDTfU9dNvq7L6ZODqgvxfbjko5pnB/RSEoQeEqJx0uz6Sate+7GLm3tTLsRteuG3UxLrnQJ69iUQ==",
"requested": "[7.1.0-beta2, )",
"resolved": "7.1.0-beta2",
"contentHash": "RXGBzIgj1ZgiUejxBQzOqjBOLhVW1I2AtI+9QXhhSdPHoZDHCdHnhO4awxq/hymkfgT5XtsFPpXhewH3Wkvuqw==",
"dependencies": {
"Newtonsoft.Json": "13.0.3",
"Polly": "8.3.0",
Expand Down Expand Up @@ -605,9 +605,9 @@
".NETStandard,Version=v2.1": {
"Alpaca.Markets": {
"type": "Direct",
"requested": "[7.1.0-beta1, )",
"resolved": "7.1.0-beta1",
"contentHash": "DKGJ828sdwjDTfU9dNvq7L6ZODqgvxfbjko5pnB/RSEoQeEqJx0uz6Sate+7GLm3tTLsRteuG3UxLrnQJ69iUQ==",
"requested": "[7.1.0-beta2, )",
"resolved": "7.1.0-beta2",
"contentHash": "RXGBzIgj1ZgiUejxBQzOqjBOLhVW1I2AtI+9QXhhSdPHoZDHCdHnhO4awxq/hymkfgT5XtsFPpXhewH3Wkvuqw==",
"dependencies": {
"Newtonsoft.Json": "13.0.3",
"Polly": "8.3.0",
Expand Down Expand Up @@ -863,9 +863,9 @@
"net6.0": {
"Alpaca.Markets": {
"type": "Direct",
"requested": "[7.1.0-beta1, )",
"resolved": "7.1.0-beta1",
"contentHash": "DKGJ828sdwjDTfU9dNvq7L6ZODqgvxfbjko5pnB/RSEoQeEqJx0uz6Sate+7GLm3tTLsRteuG3UxLrnQJ69iUQ==",
"requested": "[7.1.0-beta2, )",
"resolved": "7.1.0-beta2",
"contentHash": "RXGBzIgj1ZgiUejxBQzOqjBOLhVW1I2AtI+9QXhhSdPHoZDHCdHnhO4awxq/hymkfgT5XtsFPpXhewH3Wkvuqw==",
"dependencies": {
"Newtonsoft.Json": "13.0.3",
"Polly": "8.3.0",
Expand Down
2 changes: 2 additions & 0 deletions Alpaca.Markets/Interfaces/IHistoricalRequest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace Alpaca.Markets;

// TODO: olegra - rename this interface into IRequestWithPagination

/// <summary>
/// Provides unified type-safe access to the historical data request parameters.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Alpaca.Markets/Messages/JsonOptionContractsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ internal sealed class JsonOptionContractsPage : IPage<IOptionContract>
[JsonProperty(PropertyName = "next_page_token", Required = Required.Default)]
public String? NextPageToken { get; set; }

[JsonIgnore]
[ExcludeFromCodeCoverage]
public String Symbol => String.Empty;

public IReadOnlyList<IOptionContract> Items => Contracts.EmptyIfNull();
Expand Down
6 changes: 3 additions & 3 deletions Alpaca.Markets/Parameters/HistoricalBarsRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public HistoricalBarsRequest(
String symbol,
BarTimeFrame timeFrame,
Interval<DateTime> timeInterval)
: this(new[] { symbol.EnsureNotNull() }, timeInterval, timeFrame)
: this([ symbol.EnsureNotNull() ], timeInterval, timeFrame)
{
}

Expand All @@ -54,7 +54,7 @@ public HistoricalBarsRequest(
public HistoricalBarsRequest(
String symbol,
BarTimeFrame timeFrame)
: this(new[] { symbol.EnsureNotNull() }, timeFrame)
: this([ symbol.EnsureNotNull() ], timeFrame)
{
}

Expand Down Expand Up @@ -121,7 +121,7 @@ public HistoricalBarsRequest(
String symbol,
BarTimeFrame timeFrame,
IInclusiveTimeInterval timeInterval)
: this(new[] { symbol.EnsureNotNull() }, timeInterval, timeFrame)
: this([ symbol.EnsureNotNull() ], timeInterval, timeFrame)
{
}

Expand Down

0 comments on commit c064e9b

Please sign in to comment.