Skip to content

Commit dd64d7f

Browse files
authored
fix: GetExchangeApi generic resolves T (#871)
* fix: GetExchangeApi generic resolves T * test: updating tests to match new return
1 parent df39e23 commit dd64d7f

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ The following cryptocurrency services are supported:
7575

7676
Exchange constructors are private, to get access to an exchange in code use:
7777

78-
`ExchangeAPI.GetExchangeAPIAsync<>()`.
78+
`ExchangeAPI.GetExchangeAPIAsync<T>()`.
7979

8080
### Installing the CLI
8181

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -605,19 +605,20 @@ public static Task<IExchangeAPI> GetExchangeAPIAsync(string exchangeName)
605605
/// <typeparam name="T">Type of exchange to get</typeparam>
606606
/// <returns>Exchange API or null if not found</returns>
607607
[Obsolete("Use the async version")]
608-
public static IExchangeAPI GetExchangeAPI<T>()
608+
public static T GetExchangeAPI<T>()
609609
where T : ExchangeAPI
610610
{
611611
return GetExchangeAPIAsync<T>().Result;
612612
}
613613

614-
public static Task<IExchangeAPI> GetExchangeAPIAsync<T>()
614+
public static async Task<T> GetExchangeAPIAsync<T>()
615615
where T : ExchangeAPI
616616
{
617617
// note: this method will be slightly slow (milliseconds) the first time it is called due to cache miss and initialization
618618
// subsequent calls with cache hits will be nanoseconds
619619
Type type = typeof(T)!;
620-
return GetExchangeAPIAsync(type);
620+
621+
return (T)await GetExchangeAPIAsync(type);
621622
}
622623

623624
/// <summary>

tests/ExchangeSharpTests/ExchangeBinanceAPITests.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ public void DeserializeDiff()
3434
string toParse =
3535
@"{
3636
""e"": ""depthUpdate"",
37-
""E"": 123456789,
38-
""s"": ""BNBBTC"",
39-
""U"": 157,
40-
""u"": 160,
41-
""b"": [
37+
""E"": 123456789,
38+
""s"": ""BNBBTC"",
39+
""U"": 157,
40+
""u"": 160,
41+
""b"": [
4242
[
43-
""0.0024"",
43+
""0.0024"",
4444
""10"",
45-
[]
45+
[]
4646
]
4747
],
48-
""a"": [
48+
""a"": [
4949
[
50-
""0.0026"",
51-
""100"",
52-
[]
50+
""0.0026"",
51+
""100"",
52+
[]
5353
]
5454
]
5555
}";
@@ -116,7 +116,7 @@ public async Task CurrenciesParsedCorrectly()
116116
requestMaker
117117
.MakeRequestAsync(
118118
"/capital/config/getall",
119-
((ExchangeBinanceAPI)binance).BaseUrlSApi
119+
binance.BaseUrlSApi
120120
)
121121
.Returns(
122122
new IAPIRequestMaker.RequestResult<string>()

tests/ExchangeSharpTests/ExchangeMEXCAPITests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace ExchangeSharpTests;
1111
public class MEXCAPITests
1212
{
1313
private const string MarketSymbol = "ETHBTC";
14-
private static IExchangeAPI _api;
14+
private static ExchangeMEXCAPI _api;
1515

1616
[AssemblyInitialize]
1717
public static async Task AssemblyInitialize(TestContext testContext)

0 commit comments

Comments
 (0)