Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.
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
9 changes: 9 additions & 0 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x

- name: Add github nuget source
run: dotnet nuget add source "https://nuget.pkg.github.com/trakx/index.json" --name "github" --username "trakx-bot" --password ${{secrets.TRAKX_BOT_READONLY_PAT}} --store-password-in-clear-text

- name: Install dependencies
run: dotnet restore ${{env.SOLUTION_PATH}}

- name: Remove github source
run: dotnet nuget remove source "github"

- name: Build
run: dotnet build ${{env.SOLUTION_PATH}} --configuration Release --no-restore

- name: Test
run: dotnet test ${{env.SOLUTION_PATH}} --no-restore --logger GitHubActions --verbosity normal
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;

namespace Trakx.CryptoCompare.ApiClient.Tests.Integration.Rest.Clients
Expand Down Expand Up @@ -36,5 +37,21 @@ public async Task CanCallGenerateCustomAverageEndpoint()
var result = await CryptoCompareClient.Prices.GenerateCustomAverageAsync("BTC", "USD", new[] { "Kraken" });
Assert.NotNull(result);
}

[Fact] public async Task CanCallWithLargeNumberOfFSymbols()
{
var symbols = new[]
{
"bix", "bz", "edo", "ftt", "ht", "kcs", "leo", "okb", "qash", "zb", "ast", "bnt", "dgtx", "hot", "idex",
"knc", "lrc", "nec", "oax", "xin", "zrx", "lnd", "akro", "bcpt", "lba", "lend", "aave", "mkr", "nexo",
"ppt", "rcn", "salt", "comp", "cel", "wbtc", "weth", "link", "seele", "bat", "bal", "omg", "usdc",
"paxg", "uma", "yfi", "snx", "band", "mft", "hedg", "theta", "ren", "cvt", "chz", "rsr", "btc", "eth",
"xrp", "bch", "bnb", "dot", "ltc", "ada", "eos", "waves", "xlm", "sushi", "zil", "xem", "uni", "rune",
"srm", "cake", "luna"
};
var result = await CryptoCompareClient.Prices.MultipleSymbolsPriceAsync(symbols, new[] { "USD", "EUR" });
result.Count.Should().Be(symbols.Length);
Assert.NotNull(result);
}
}
}
43 changes: 41 additions & 2 deletions src/Trakx.CryptoCompare.ApiClient/Rest/Clients/PriceClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using JetBrains.Annotations;
Expand Down Expand Up @@ -64,8 +65,46 @@ public async Task<PriceMultiResponse> MultipleSymbolsPriceAsync(
Check.NotEmpty(toSymbols, nameof(toSymbols));
Check.NotEmpty(fromSymbols, nameof(fromSymbols));

return await this.GetAsync<PriceMultiResponse>(
ApiUrls.PriceMulti(fromSymbols, toSymbols, tryConversion, exchangeName)).ConfigureAwait(false);
var groupsOfSymbols = GroupSymbolsByListsOfMaxCsvCharacters(fromSymbols.ToList());

var fetchTasks = groupsOfSymbols.Select(s => this.GetAsync<PriceMultiResponse>(
ApiUrls.PriceMulti(s, toSymbols, tryConversion, exchangeName)))
.ToArray();

await Task.WhenAll(fetchTasks);

var results = fetchTasks
.SelectMany(t => t.Result)
.ToDictionary(p => p.Key, p => p.Value);
var mergedResults = new PriceMultiResponse(results);

return mergedResults;
}

private static List<List<string>> GroupSymbolsByListsOfMaxCsvCharacters(IReadOnlyList<string> fromSymbolList, int maxLength = 300)
{
var i = 0;
var groupsOfSymbols = new List<List<string>>();

do
{
var includedFromSymbols = new List<string>();
var length = 0;
do
{
if (length + fromSymbolList[i].Length + 1 < maxLength)
{
length += fromSymbolList[i].Length + 1;
includedFromSymbols.Add(fromSymbolList[i]);
i++;
}
else length = maxLength;
} while (length < maxLength && i < fromSymbolList.Count);

groupsOfSymbols.Add(includedFromSymbols);
} while (i < fromSymbolList.Count);

return groupsOfSymbols;
}

/// <summary>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PackageReference Include="Polly" Version="7.2.1" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="System.Reactive.Linq" Version="5.0.0" />
<PackageReference Include="Trakx.Utils" Version="0.1.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Text.Json.Serialization;
using Trakx.CryptoCompare.ApiClient.Serialisation.Converters;
using Trakx.Utils.Serialization.Converters;

namespace Trakx.CryptoCompare.ApiClient.WebSocket.DTOs.Inbound
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Text.Json.Serialization;
using Trakx.CryptoCompare.ApiClient.Serialisation.Converters;
using Trakx.Utils.Serialization.Converters;

namespace Trakx.CryptoCompare.ApiClient.WebSocket.DTOs.Inbound
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Text.Json.Serialization;
using Trakx.CryptoCompare.ApiClient.Serialisation.Converters;
using Trakx.Utils.Serialization.Converters;

namespace Trakx.CryptoCompare.ApiClient.WebSocket.DTOs.Inbound
{
Expand Down