Skip to content

Make GetExchangeAPIsAsync return all instances as previous #684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2021
Merged
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
28 changes: 17 additions & 11 deletions src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static async Task<IExchangeAPI> InitializeAPIAsync(Type? type, Type? kno
}

const int retryCount = 3;

// try up to 3 times to init
for (int i = 1; i <= retryCount; i++)
{
Expand Down Expand Up @@ -495,22 +495,28 @@ public static IExchangeAPI[] GetExchangeAPIs()
/// <summary>
/// Get all cached versions of exchange APIs
/// </summary>
/// <param name="cachedOnly">Whether to only fetch exchanges that were cached</param>
/// <returns>All APIs</returns>
public static async Task<IExchangeAPI[]> GetExchangeAPIsAsync()
public static async Task<IExchangeAPI[]> GetExchangeAPIsAsync(bool cachedOnly = false)
{
var apiList = new List<IExchangeAPI>();
foreach (var kv in apis.ToArray())
if (cachedOnly)
{
if (kv.Value == null)
{
apiList.Add(await GetExchangeAPIAsync(kv.Key));
}
else
var apiList = new List<IExchangeAPI>();
foreach (var kv in apis.ToArray())
{
apiList.Add(await kv.Value);
if (kv.Value == null)
{
apiList.Add(await GetExchangeAPIAsync(kv.Key));
}
else
{
apiList.Add(await kv.Value);
}
}
return apiList.ToArray();
}
return apiList.ToArray();
var tasks = exchangeTypes.Where(type => type != null).Select(GetExchangeAPIAsync);
return await Task.WhenAll(tasks);
}

/// <summary>
Expand Down