From 62f743bc455fa4f2113c48050fa20eb3ff8f296f Mon Sep 17 00:00:00 2001 From: JKorf Date: Thu, 8 Aug 2024 11:17:01 +0200 Subject: [PATCH] Fixed SpotApi.Account.GetUserAssetsAsync deserialization due to too large number being returned, added integration tests --- .../MexcRestIntegrationTests.cs | 92 +++++++++++++++++++ .../SpotApi/MexcRestClientSpotApiAccount.cs | 2 +- Mexc.Net/Objects/Models/Spot/MexcUserAsset.cs | 2 +- 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 Mexc.Net.UnitTests/MexcRestIntegrationTests.cs diff --git a/Mexc.Net.UnitTests/MexcRestIntegrationTests.cs b/Mexc.Net.UnitTests/MexcRestIntegrationTests.cs new file mode 100644 index 0000000..38d8ee4 --- /dev/null +++ b/Mexc.Net.UnitTests/MexcRestIntegrationTests.cs @@ -0,0 +1,92 @@ +using Mexc.Net.Clients; +using Mexc.Net.Objects; +using CryptoExchange.Net.Authentication; +using CryptoExchange.Net.Testing; +using Microsoft.Extensions.Logging; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Mexc.Net.UnitTests +{ + [NonParallelizable] + internal class MexcRestIntegrationTests : RestIntergrationTest + { + public override bool Run { get; set; } = true; + + public MexcRestIntegrationTests() + { + } + + public override MexcRestClient GetClient(ILoggerFactory loggerFactory) + { + var key = Environment.GetEnvironmentVariable("APIKEY"); + var sec = Environment.GetEnvironmentVariable("APISECRET"); + + key = "mx0vglXH1pl1WUt0Kd"; + sec = "d812baf264d24b08817d618bcad3b062"; + + Authenticated = key != null && sec != null; + return new MexcRestClient(null, loggerFactory, opts => + { + opts.OutputOriginalData = true; + opts.ApiCredentials = Authenticated ? new ApiCredentials(key, sec) : null; + }); + } + + [Test] + public async Task TestErrorResponseParsing() + { + if (!ShouldRun()) + return; + + var result = await CreateClient().SpotApi.ExchangeData.GetKlinesAsync("TSTTST", Enums.KlineInterval.OneDay, default); + + Assert.That(result.Success, Is.False); + Assert.That(result.Error.Code, Is.EqualTo(-1121)); + } + + [Test] + public async Task TestSpotAccount() + { + await RunAndCheckResult(client => client.SpotApi.Account.GetAccountInfoAsync(default), true); + await RunAndCheckResult(client => client.SpotApi.Account.GetUserAssetsAsync(default), true); + await RunAndCheckResult(client => client.SpotApi.Account.GetDepositHistoryAsync(default, default, default, default, default, default), true); + await RunAndCheckResult(client => client.SpotApi.Account.GetWithdrawHistoryAsync(default, default, default, default, default, default), true); + await RunAndCheckResult(client => client.SpotApi.Account.GetWithdrawAddressesAsync(default, default, default, default), true); + await RunAndCheckResult(client => client.SpotApi.Account.GetTransferHistoryAsync(Enums.AccountType.Spot, Enums.AccountType.Futures, default, default, default, default, default), true); + await RunAndCheckResult(client => client.SpotApi.Account.GetAssetsForDustTransferAsync(default), true); + await RunAndCheckResult(client => client.SpotApi.Account.GetDustLogAsync(default, default, default, default, default), true); + await RunAndCheckResult(client => client.SpotApi.Account.GetMxDeductionStatusAsync(default), true); + await RunAndCheckResult(client => client.SpotApi.Account.GetTradeFeeAsync("ETHUSDT", default), true); + } + + [Test] + public async Task TestSpotExchangeData() + { + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetServerTimeAsync(default), false); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetApiSymbolsAsync(default), false); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetExchangeInfoAsync(default, default), false); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetOrderBookAsync("ETHUSDT", default, default), false); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetRecentTradesAsync("ETHUSDT", default, default), false); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetAggregatedTradeHistoryAsync("ETHUSDT", default, default, default, default), false); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetKlinesAsync("ETHUSDT",Enums.KlineInterval.OneDay, default, default, default, default), false); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetAveragePriceAsync("ETHUSDT", default), false); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetTickerAsync("ETHUSDT", default), false); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetPricesAsync(default, default), false); + await RunAndCheckResult(client => client.SpotApi.ExchangeData.GetBookPricesAsync(default, default), false); + } + + [Test] + public async Task TestSpotTrading() + { + await RunAndCheckResult(client => client.SpotApi.Trading.GetOpenOrdersAsync("ETHUSDT", default), true); + await RunAndCheckResult(client => client.SpotApi.Trading.GetOrdersAsync("ETHUSDT", default, default, default, default), true); + await RunAndCheckResult(client => client.SpotApi.Trading.GetUserTradesAsync("ETHUSDT", default, default, default, default, default), true); + } + + } +} diff --git a/Mexc.Net/Clients/SpotApi/MexcRestClientSpotApiAccount.cs b/Mexc.Net/Clients/SpotApi/MexcRestClientSpotApiAccount.cs index 2bc9507..607f7b6 100644 --- a/Mexc.Net/Clients/SpotApi/MexcRestClientSpotApiAccount.cs +++ b/Mexc.Net/Clients/SpotApi/MexcRestClientSpotApiAccount.cs @@ -275,7 +275,7 @@ public async Task> GetMxDeductionStatusAsync(Can #endregion - #region Get Mx Deduction Status + #region Get Trade Fee /// public async Task> GetTradeFeeAsync(string symbol, CancellationToken ct = default) diff --git a/Mexc.Net/Objects/Models/Spot/MexcUserAsset.cs b/Mexc.Net/Objects/Models/Spot/MexcUserAsset.cs index ba9e275..988b685 100644 --- a/Mexc.Net/Objects/Models/Spot/MexcUserAsset.cs +++ b/Mexc.Net/Objects/Models/Spot/MexcUserAsset.cs @@ -79,7 +79,7 @@ public record MexcNetwork /// /// Max withdrawal /// - [JsonProperty("withdrawMax")] + [JsonProperty("withdrawMax"), JsonConverter(typeof(BigDecimalConverter))] public decimal WithdrawMax { get; set; } /// /// Minimal withdrawal