Skip to content

Commit fce1fbb

Browse files
authored
Make GetExchangeAPIsAsync return all instances too (#684)
The major version bump introduced a critical breaking change where GetExchangeAPIsAsync no longer returns a list of all exchanges supported, breaking various integrations. This PR changes the default for GetExchangeAPIsAsync to return all instances but also adds an option to use the current logic
1 parent 65e9bef commit fce1fbb

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static async Task<IExchangeAPI> InitializeAPIAsync(Type? type, Type? kno
6565
}
6666

6767
const int retryCount = 3;
68-
68+
6969
// try up to 3 times to init
7070
for (int i = 1; i <= retryCount; i++)
7171
{
@@ -495,22 +495,28 @@ public static IExchangeAPI[] GetExchangeAPIs()
495495
/// <summary>
496496
/// Get all cached versions of exchange APIs
497497
/// </summary>
498+
/// <param name="cachedOnly">Whether to only fetch exchanges that were cached</param>
498499
/// <returns>All APIs</returns>
499-
public static async Task<IExchangeAPI[]> GetExchangeAPIsAsync()
500+
public static async Task<IExchangeAPI[]> GetExchangeAPIsAsync(bool cachedOnly = false)
500501
{
501-
var apiList = new List<IExchangeAPI>();
502-
foreach (var kv in apis.ToArray())
502+
if (cachedOnly)
503503
{
504-
if (kv.Value == null)
505-
{
506-
apiList.Add(await GetExchangeAPIAsync(kv.Key));
507-
}
508-
else
504+
var apiList = new List<IExchangeAPI>();
505+
foreach (var kv in apis.ToArray())
509506
{
510-
apiList.Add(await kv.Value);
507+
if (kv.Value == null)
508+
{
509+
apiList.Add(await GetExchangeAPIAsync(kv.Key));
510+
}
511+
else
512+
{
513+
apiList.Add(await kv.Value);
514+
}
511515
}
516+
return apiList.ToArray();
512517
}
513-
return apiList.ToArray();
518+
var tasks = exchangeTypes.Where(type => type != null).Select(GetExchangeAPIAsync);
519+
return await Task.WhenAll(tasks);
514520
}
515521

516522
/// <summary>

0 commit comments

Comments
 (0)