diff --git a/Binance.Net.UnitTests/BinanceRestIntegrationTests.cs b/Binance.Net.UnitTests/BinanceRestIntegrationTests.cs index 8a8ee495e..ae6ad82ce 100644 --- a/Binance.Net.UnitTests/BinanceRestIntegrationTests.cs +++ b/Binance.Net.UnitTests/BinanceRestIntegrationTests.cs @@ -12,7 +12,7 @@ namespace Binance.Net.UnitTests [NonParallelizable] internal class BinanceRestIntegrationTests : RestIntergrationTest { - public override bool Run { get; set; } = false; + public override bool Run { get; set; } = true; public BinanceRestIntegrationTests() { @@ -107,7 +107,7 @@ public async Task TestSpotExchangeData() await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetServerTimeAsync(CancellationToken.None), false); await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetExchangeInfoAsync(CancellationToken.None), false); await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetSystemStatusAsync(CancellationToken.None), false); - await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetAssetDetailsAsync(5000, CancellationToken.None), false); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetAssetDetailsAsync(5000, CancellationToken.None), true); await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetProductsAsync(CancellationToken.None), false); await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetOrderBookAsync("ETHUSDT", 1, CancellationToken.None), false); await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetRecentTradesAsync("ETHUSDT", 1, CancellationToken.None), false); @@ -123,17 +123,17 @@ public async Task TestSpotExchangeData() await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetPriceAsync("ETHUSDT", CancellationToken.None), false); await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetPricesAsync(CancellationToken.None), false); await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetBookPriceAsync("ETHUSDT", CancellationToken.None), false); - await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetMarginAssetsAsync(null, CancellationToken.None), false); - await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetMarginSymbolsAsync(null, CancellationToken.None), false); - await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetMarginPriceIndexAsync("ETHUSDT", CancellationToken.None), false); - await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetIsolatedMarginSymbolsAsync("ETHUSDT", 5000, CancellationToken.None), false); - await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetLeveragedTokenInfoAsync(5000, CancellationToken.None), false); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetMarginAssetsAsync(null, CancellationToken.None), true); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetMarginSymbolsAsync(null, CancellationToken.None), true); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetMarginPriceIndexAsync("ETHUSDT", CancellationToken.None), true); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetIsolatedMarginSymbolsAsync("ETHUSDT", 5000, CancellationToken.None), true); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetLeveragedTokenInfoAsync(5000, CancellationToken.None), true); await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetLeveragedTokensHistoricalKlinesAsync("ETHUP", Enums.KlineInterval.OneHour, null, null, null, null, CancellationToken.None), false); - await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetCrossMarginCollateralRatioAsync(null, CancellationToken.None), false); - await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetFutureHourlyInterestRateAsync(new[] { "ETH" }, false, null, CancellationToken.None), false); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetCrossMarginCollateralRatioAsync(null, CancellationToken.None), true); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetFutureHourlyInterestRateAsync(new[] { "ETH" }, false, null, CancellationToken.None), true); await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetMarginDelistScheduleAsync(null, CancellationToken.None), false); await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetConvertListAllPairsAsync(null, null, CancellationToken.None), false); - await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetDelistScheduleAsync(null, CancellationToken.None), false); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetDelistScheduleAsync(null, CancellationToken.None), true); // Needs more permissions //await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetConvertQuantityPrecisionPerAssetAsync(null, CancellationToken.None), false); @@ -190,7 +190,7 @@ public async Task TestUsdFuturesExchangeData() await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetExchangeInfoAsync(CancellationToken.None), false); await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetOrderBookAsync("ETHUSDT", 5, CancellationToken.None), false); await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetRecentTradesAsync("ETHUSDT", 1, CancellationToken.None), false); - await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetTradeHistoryAsync("ETHUSDT", 1, null, CancellationToken.None), false); + await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetTradeHistoryAsync("ETHUSDT", 1, null, CancellationToken.None), true); await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetAggregatedTradeHistoryAsync("ETHUSDT", null, null, null, 10, CancellationToken.None), false); await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetFundingInfoAsync(CancellationToken.None), false); await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetFundingRatesAsync("ETHUSDT", null, null, null, CancellationToken.None), false); @@ -249,7 +249,7 @@ public async Task TestCoinFuturesExchangeData() await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetExchangeInfoAsync(CancellationToken.None), false); await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetOrderBookAsync("ETHUSD_PERP", 5, CancellationToken.None), false); await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetRecentTradesAsync("ETHUSD_PERP", 1, CancellationToken.None), false); - await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetTradeHistoryAsync("ETHUSD_PERP", 1, null, CancellationToken.None), false); + await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetTradeHistoryAsync("ETHUSD_PERP", 1, null, CancellationToken.None), true); await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetAggregatedTradeHistoryAsync("ETHUSD_PERP", null, null, null, 10, CancellationToken.None), false); await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetKlinesAsync("ETHUSD_PERP", Enums.KlineInterval.OneHour, DateTime.UtcNow.AddDays(-1), DateTime.UtcNow, 1, CancellationToken.None), false); await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetTickersAsync(null, null, CancellationToken.None), false); diff --git a/Binance.Net.UnitTests/RestIntergrationTest.cs b/Binance.Net.UnitTests/RestIntergrationTest.cs deleted file mode 100644 index 3506e6c28..000000000 --- a/Binance.Net.UnitTests/RestIntergrationTest.cs +++ /dev/null @@ -1,74 +0,0 @@ -using Binance.Net.UnitTests.TestImplementations; -using CryptoExchange.Net; -using CryptoExchange.Net.Objects; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Linq.Expressions; -using System.Text; -using System.Threading.Tasks; - -namespace Binance.Net.UnitTests -{ - public abstract class RestIntergrationTest - { - public abstract TClient GetClient(ILoggerFactory loggerFactory); - public virtual bool Run { get; set; } - public bool Authenticated { get; set; } - - protected TClient CreateClient() - { - var fact = new LoggerFactory(); - fact.AddProvider(new TraceLoggerProvider()); - return GetClient(fact); - } - - protected bool ShouldRun() - { - var integrationTests = Environment.GetEnvironmentVariable("INTEGRATION"); - if (!Run && integrationTests != "1") - return false; - - return true; - } - - public async Task RunAndCheckResult(Expression>>> expre, bool authRequest) - { - if (!ShouldRun()) - return; - - var client = CreateClient(); - - var expressionBody = (MethodCallExpression)expre.Body; - if (authRequest && !Authenticated) - { - Debug.WriteLine($"Skipping {expressionBody.Method.Name}, not authenticated"); - return; - } - - var listener = new EnumValueTraceListener(); - Trace.Listeners.Add(listener); - - WebCallResult result; - try - { - result = await expre.Compile().Invoke(client); - } - catch (Exception ex) - { - throw new Exception($"Method {expressionBody.Method.Name} threw an exception: " + ex.ToLogString()); - } - finally - { - Trace.Listeners.Remove(listener); - } - - if (!result.Success) - throw new Exception($"Method {expressionBody.Method.Name} returned error: " + result.Error); - - Debug.WriteLine($"{expressionBody.Method.Name} {result}"); - } - } -} diff --git a/Binance.Net.UnitTests/TestImplementations/EnumValueTraceListener.cs b/Binance.Net.UnitTests/TestImplementations/EnumValueTraceListener.cs deleted file mode 100644 index fb33cc243..000000000 --- a/Binance.Net.UnitTests/TestImplementations/EnumValueTraceListener.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Diagnostics; - -namespace Binance.Net.UnitTests.TestImplementations -{ - internal class EnumValueTraceListener : TraceListener - { - public override void Write(string message) - { - if (message.Contains("Cannot map")) - throw new Exception("Enum value error: " + message); - } - - public override void WriteLine(string message) - { - if (message.Contains("Cannot map")) - throw new Exception("Enum value error: " + message); - } - } -} diff --git a/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApi.cs b/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApi.cs index 5624dc7de..26905afba 100644 --- a/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApi.cs +++ b/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApi.cs @@ -134,12 +134,12 @@ internal async Task> PlaceOrderInternal(Uri ur parameters.AddOptionalParameter("quoteOrderQty", quoteQuantity?.ToString(CultureInfo.InvariantCulture)); parameters.AddOptionalParameter("newClientOrderId", clientOrderId); parameters.AddOptionalParameter("price", price?.ToString(CultureInfo.InvariantCulture)); - parameters.AddEnum("timeInForce", timeInForce); + parameters.AddOptionalEnum("timeInForce", timeInForce); parameters.AddOptionalParameter("stopPrice", stopPrice?.ToString(CultureInfo.InvariantCulture)); parameters.AddOptionalParameter("icebergQty", icebergQty?.ToString(CultureInfo.InvariantCulture)); - parameters.AddEnum("sideEffectType", sideEffectType); + parameters.AddOptionalEnum("sideEffectType", sideEffectType); parameters.AddOptionalParameter("isIsolated", isIsolated); - parameters.AddEnum("newOrderRespType", orderResponseType); + parameters.AddOptionalEnum("newOrderRespType", orderResponseType); parameters.AddOptionalParameter("trailingDelta", trailingDelta); parameters.AddOptionalParameter("strategyId", strategyId); parameters.AddOptionalParameter("strategyType", strategyType);