diff --git a/README.md b/README.md index 6010eb95..7edacba4 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ The following cryptocurrency services are supported: Exchange constructors are private, to get access to an exchange in code use: -`ExchangeAPI.GetExchangeAPIAsync<>()`. +`ExchangeAPI.GetExchangeAPIAsync()`. ### Installing the CLI diff --git a/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs b/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs index f7a53650..fe07e57b 100644 --- a/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs @@ -605,19 +605,20 @@ public static Task GetExchangeAPIAsync(string exchangeName) /// Type of exchange to get /// Exchange API or null if not found [Obsolete("Use the async version")] - public static IExchangeAPI GetExchangeAPI() + public static T GetExchangeAPI() where T : ExchangeAPI { return GetExchangeAPIAsync().Result; } - public static Task GetExchangeAPIAsync() + public static async Task GetExchangeAPIAsync() where T : ExchangeAPI { // note: this method will be slightly slow (milliseconds) the first time it is called due to cache miss and initialization // subsequent calls with cache hits will be nanoseconds Type type = typeof(T)!; - return GetExchangeAPIAsync(type); + + return (T)await GetExchangeAPIAsync(type); } /// diff --git a/tests/ExchangeSharpTests/ExchangeBinanceAPITests.cs b/tests/ExchangeSharpTests/ExchangeBinanceAPITests.cs index efe35212..3da61adf 100644 --- a/tests/ExchangeSharpTests/ExchangeBinanceAPITests.cs +++ b/tests/ExchangeSharpTests/ExchangeBinanceAPITests.cs @@ -34,22 +34,22 @@ public void DeserializeDiff() string toParse = @"{ ""e"": ""depthUpdate"", - ""E"": 123456789, - ""s"": ""BNBBTC"", - ""U"": 157, - ""u"": 160, - ""b"": [ + ""E"": 123456789, + ""s"": ""BNBBTC"", + ""U"": 157, + ""u"": 160, + ""b"": [ [ - ""0.0024"", + ""0.0024"", ""10"", - [] + [] ] ], - ""a"": [ + ""a"": [ [ - ""0.0026"", - ""100"", - [] + ""0.0026"", + ""100"", + [] ] ] }"; @@ -116,7 +116,7 @@ public async Task CurrenciesParsedCorrectly() requestMaker .MakeRequestAsync( "/capital/config/getall", - ((ExchangeBinanceAPI)binance).BaseUrlSApi + binance.BaseUrlSApi ) .Returns( new IAPIRequestMaker.RequestResult() diff --git a/tests/ExchangeSharpTests/ExchangeMEXCAPITests.cs b/tests/ExchangeSharpTests/ExchangeMEXCAPITests.cs index d571e63c..df77022f 100644 --- a/tests/ExchangeSharpTests/ExchangeMEXCAPITests.cs +++ b/tests/ExchangeSharpTests/ExchangeMEXCAPITests.cs @@ -11,7 +11,7 @@ namespace ExchangeSharpTests; public class MEXCAPITests { private const string MarketSymbol = "ETHBTC"; - private static IExchangeAPI _api; + private static ExchangeMEXCAPI _api; [AssemblyInitialize] public static async Task AssemblyInitialize(TestContext testContext)