From 08452896f3167bad9501fbfdd7bd9d342540d4fd Mon Sep 17 00:00:00 2001 From: Owdares <147960607+Owdares@users.noreply.github.com> Date: Sun, 3 Dec 2023 12:40:04 +0200 Subject: [PATCH] Added convert endpoints (#1322) --- .../Spot/Trading/ConvertAcceptQuoteAsync.txt | 5 + .../Spot/Trading/ConvertQuoteRequestAsync.txt | 8 + .../Trading/GetConvertListAllPairsAsync.txt | 10 + .../Trading/GetConvertOrderStatusAsync.txt | 11 + ...tConvertQuantityPrecisionPerAssetAsync.txt | 10 + Binance.Net.UnitTests/JsonTests.cs | 2 +- Binance.Net/Binance.Net.xml | 385 +++++++++++++++--- .../BinanceRestClientSpotApiExchangeData.cs | 42 ++ .../BinanceRestClientSpotApiTrading.cs | 67 ++- Binance.Net/Enums/ConvertOrderStatus.cs | 31 ++ Binance.Net/Enums/ValidTime.cs | 31 ++ .../IBinanceRestClientSpotApiExchangeData.cs | 20 + .../IBinanceRestClientSpotApiTrading.cs | 37 ++ .../Spot/Convert/BinanceConvertAssetPair.cs | 45 ++ .../Spot/Convert/BinanceConvertOrderStatus.cs | 58 +++ .../BinanceConvertQuantityPrecisionAsset.cs | 21 + .../Spot/Convert/BinanceConvertQuote.cs | 40 ++ .../Spot/Convert/BinanceConvertResult.cs | 30 ++ .../Spot/{ => Convert}/BinanceConvertTrade.cs | 26 +- 19 files changed, 812 insertions(+), 67 deletions(-) create mode 100644 Binance.Net.UnitTests/JsonResponses/Spot/Trading/ConvertAcceptQuoteAsync.txt create mode 100644 Binance.Net.UnitTests/JsonResponses/Spot/Trading/ConvertQuoteRequestAsync.txt create mode 100644 Binance.Net.UnitTests/JsonResponses/Spot/Trading/GetConvertListAllPairsAsync.txt create mode 100644 Binance.Net.UnitTests/JsonResponses/Spot/Trading/GetConvertOrderStatusAsync.txt create mode 100644 Binance.Net.UnitTests/JsonResponses/Spot/Trading/GetConvertQuantityPrecisionPerAssetAsync.txt create mode 100644 Binance.Net/Enums/ConvertOrderStatus.cs create mode 100644 Binance.Net/Enums/ValidTime.cs create mode 100644 Binance.Net/Objects/Models/Spot/Convert/BinanceConvertAssetPair.cs create mode 100644 Binance.Net/Objects/Models/Spot/Convert/BinanceConvertOrderStatus.cs create mode 100644 Binance.Net/Objects/Models/Spot/Convert/BinanceConvertQuantityPrecisionAsset.cs create mode 100644 Binance.Net/Objects/Models/Spot/Convert/BinanceConvertQuote.cs create mode 100644 Binance.Net/Objects/Models/Spot/Convert/BinanceConvertResult.cs rename Binance.Net/Objects/Models/Spot/{ => Convert}/BinanceConvertTrade.cs (64%) diff --git a/Binance.Net.UnitTests/JsonResponses/Spot/Trading/ConvertAcceptQuoteAsync.txt b/Binance.Net.UnitTests/JsonResponses/Spot/Trading/ConvertAcceptQuoteAsync.txt new file mode 100644 index 000000000..574a2f5fa --- /dev/null +++ b/Binance.Net.UnitTests/JsonResponses/Spot/Trading/ConvertAcceptQuoteAsync.txt @@ -0,0 +1,5 @@ +{ + "orderId":"933256278426274426", + "createTime":1623381330472, + "orderStatus":"PROCESS" //PROCESS/ACCEPT_SUCCESS/SUCCESS/FAIL +} \ No newline at end of file diff --git a/Binance.Net.UnitTests/JsonResponses/Spot/Trading/ConvertQuoteRequestAsync.txt b/Binance.Net.UnitTests/JsonResponses/Spot/Trading/ConvertQuoteRequestAsync.txt new file mode 100644 index 000000000..d913f21fb --- /dev/null +++ b/Binance.Net.UnitTests/JsonResponses/Spot/Trading/ConvertQuoteRequestAsync.txt @@ -0,0 +1,8 @@ +{ + "quoteId":"12415572564", + "ratio":"38163.7", + "inverseRatio":"0.0000262", + "validTimestamp":1623319461670, + "toAmount":"3816.37", + "fromAmount":"0.1" +} \ No newline at end of file diff --git a/Binance.Net.UnitTests/JsonResponses/Spot/Trading/GetConvertListAllPairsAsync.txt b/Binance.Net.UnitTests/JsonResponses/Spot/Trading/GetConvertListAllPairsAsync.txt new file mode 100644 index 000000000..8e944d97a --- /dev/null +++ b/Binance.Net.UnitTests/JsonResponses/Spot/Trading/GetConvertListAllPairsAsync.txt @@ -0,0 +1,10 @@ +[ + { + "fromAsset":"BTC", + "toAsset":"USDT", + "fromAssetMinAmount":"0.0004", + "fromAssetMaxAmount":"50", + "toAssetMinAmount":"20", + "toAssetMaxAmount":"2500000" + } +] \ No newline at end of file diff --git a/Binance.Net.UnitTests/JsonResponses/Spot/Trading/GetConvertOrderStatusAsync.txt b/Binance.Net.UnitTests/JsonResponses/Spot/Trading/GetConvertOrderStatusAsync.txt new file mode 100644 index 000000000..a1d394aee --- /dev/null +++ b/Binance.Net.UnitTests/JsonResponses/Spot/Trading/GetConvertOrderStatusAsync.txt @@ -0,0 +1,11 @@ +{ + "orderId":933256278426274426, + "orderStatus":"SUCCESS", + "fromAsset":"BTC", + "fromAmount":"0.00054414", + "toAsset":"USDT", + "toAmount":"20", + "ratio":"36755", + "inverseRatio":"0.00002721", + "createTime":1623381330472 +} \ No newline at end of file diff --git a/Binance.Net.UnitTests/JsonResponses/Spot/Trading/GetConvertQuantityPrecisionPerAssetAsync.txt b/Binance.Net.UnitTests/JsonResponses/Spot/Trading/GetConvertQuantityPrecisionPerAssetAsync.txt new file mode 100644 index 000000000..cfc4c7d7e --- /dev/null +++ b/Binance.Net.UnitTests/JsonResponses/Spot/Trading/GetConvertQuantityPrecisionPerAssetAsync.txt @@ -0,0 +1,10 @@ +[ + { + "asset": "BTC", + "fraction": 8 + }, + { + "asset": "SHIB", + "fraction": 2 + } +] \ No newline at end of file diff --git a/Binance.Net.UnitTests/JsonTests.cs b/Binance.Net.UnitTests/JsonTests.cs index 9f0053eac..f5b87a752 100644 --- a/Binance.Net.UnitTests/JsonTests.cs +++ b/Binance.Net.UnitTests/JsonTests.cs @@ -71,7 +71,7 @@ await _comparer.ProcessSubject( { "PlaceMarginOrderAsync", new List { "price" } }, { "GetMarginOrdersAsync", new List { "price" } }, }, - parametersToSetNull: new[] { "limit", "quoteQuantity", "fromId", "cancelClientOrderId" }); + parametersToSetNull: new[] { "limit", "quoteQuantity", "fromId", "cancelClientOrderId", "orderId" }); } [Test] diff --git a/Binance.Net/Binance.Net.xml b/Binance.Net/Binance.Net.xml index fad5a54b7..9434ddd93 100644 --- a/Binance.Net/Binance.Net.xml +++ b/Binance.Net/Binance.Net.xml @@ -1454,6 +1454,12 @@ + + + + + + @@ -1589,6 +1595,15 @@ + + + + + + + + + @@ -2869,6 +2884,31 @@ Unknown + + + Convert Order status + + + + + Process + + + + + Accept success + + + + + Success + + + + + Fail + + The status of a deposit @@ -4734,6 +4774,31 @@ Option to Funding + + + Valid Time + + + + + 10 seconds + + + + + 30 seconds + + + + + 1 minute + + + + + 2 minutes + + Wallet type @@ -8923,6 +8988,25 @@ Cancellation token + + + Get list all convert pairs + + + Quote asset + Base asset + Cancellation token + + + + + Get quantity precision per asset + + + The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request + Cancellation token + + Binance Spot trading endpoints, placing and mananging orders. @@ -9555,6 +9639,42 @@ Cancellation token + + + Request a quote for convert asset (selling asset) for base asset (buying asset) + + + Quote asset + Base asset + Quote quantity + Quote quantity + The wallet type for convert + The valid time for quote + The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request + Cancellation token + + + + + Accept the previously requested quote + + + The quote id of the order + + + + + + + Get convert order status + + + The order id of the order + The quote id of the order + + + + Get convert trade history @@ -14018,61 +14138,6 @@ Status - - - Convert trade info - - - - - Quote id - - - - - Order id - - - - - Order status - - - - - From asset - - - - - From quantity - - - - - To asset - - - - - To quantity - - - - - Price ratio - - - - - Inverse price ratio - - - - - Creation time - - Deposit address info @@ -18219,6 +18284,216 @@ Status of the transfer (definitions currently unknown) + + + Convert Pairs + + + + + Quote asset + + + + + Base asset + + + + + Quote asset min quantity + + + + + Quote asset max quantity + + + + + Base asset min quantity + + + + + Base asset max quantity + + + + + Convert trade info + + + + + Order id + + + + + Order status + + + + + Quote asset + + + + + Quote quantity + + + + + Base asset + + + + + Base quantity + + + + + Price ratio + + + + + Inverse price ratio + + + + + Creation time + + + + + Precision per asset + + + + + Asset + + + + + Fraction + + + + + Convert Quote + + + + + Quote id + + + + + Price ratio + + + + + Inverse price ratio + + + + + Valid Timestamp + + + + + Base quantity + + + + + Quote quantity + + + + + Convert Quote + + + + + Order id + + + + + Creation time + + + + + Order status + + + + + Convert trade info + + + + + Quote id + + + + + Order id + + + + + Order status + + + + + Quote asset + + + + + Quote quantity + + + + + Base asset + + + + + Base quantity + + + + + Price ratio + + + + + Inverse price ratio + + + + + Creation time + + Adjust history diff --git a/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiExchangeData.cs b/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiExchangeData.cs index 6bd85ab81..d2daa074e 100644 --- a/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiExchangeData.cs +++ b/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiExchangeData.cs @@ -14,6 +14,7 @@ using Binance.Net.Objects.Models.Spot; using Binance.Net.Objects.Models.Spot.Blvt; using Binance.Net.Objects.Models.Spot.BSwap; +using Binance.Net.Objects.Models.Spot.Convert; using Binance.Net.Objects.Models.Spot.IsolatedMargin; using Binance.Net.Objects.Models.Spot.Margin; using Binance.Net.Objects.Models.Spot.Staking; @@ -65,6 +66,10 @@ public class BinanceRestClientSpotApiExchangeData : IBinanceRestClientSpotApiExc private const string bSwapPoolsEndpoint = "bswap/pools"; private const string bSwapPoolsConfigureEndpoint = "bswap/poolConfigure"; + //Convert + private const string convertListAllConvertPairsEndpoint = "convert/exchangeInfo"; + private const string convertQuantityPrecisionPerAssetEndpoint = "convert/assetInfo"; + private const string api = "api"; private const string publicVersion = "3"; @@ -77,6 +82,9 @@ public class BinanceRestClientSpotApiExchangeData : IBinanceRestClientSpotApiExc private const string bSwapApi = "sapi"; private const string bSwapVersion = "1"; + private const string convertApi = "sapi"; + private const string convertVersion = "1"; + private readonly ILogger _logger; private readonly BinanceRestClientSpotApi _baseClient; @@ -710,5 +718,39 @@ public async Task>> GetMa } #endregion + + #region Convert + + #region Get Convert List All Pairs + + /// + public async Task>> GetConvertListAllPairsAsync(string? quoteAsset = null, string? baseAsset = null, CancellationToken ct = default) + { + if (quoteAsset == null && baseAsset == null) + throw new ArgumentException("Either one or both of the assets must be sent"); + + var parameters = new Dictionary(); + parameters.AddOptionalParameter("fromAsset", quoteAsset); + parameters.AddOptionalParameter("toAsset", baseAsset); + + return await _baseClient.SendRequestInternal>(_baseClient.GetUrl(convertListAllConvertPairsEndpoint, convertApi, convertVersion), HttpMethod.Get, ct, parameters, true, weight: 3000).ConfigureAwait(false); + } + + #endregion + + #region Get Convert Quantity Precision Per Asset + + /// + public async Task>> GetConvertQuantityPrecisionPerAssetAsync(long? receiveWindow = null, CancellationToken ct = default) + { + var parameters = new Dictionary(); + parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); + + return await _baseClient.SendRequestInternal>(_baseClient.GetUrl(convertQuantityPrecisionPerAssetEndpoint, convertApi, convertVersion), HttpMethod.Get, ct, parameters, true, weight: 100).ConfigureAwait(false); + } + + #endregion + + #endregion } } diff --git a/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiTrading.cs b/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiTrading.cs index 3ad35f163..70c97cea3 100644 --- a/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiTrading.cs +++ b/Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiTrading.cs @@ -12,6 +12,7 @@ using Binance.Net.Objects.Models.Spot; using Binance.Net.Objects.Models.Spot.Blvt; using Binance.Net.Objects.Models.Spot.BSwap; +using Binance.Net.Objects.Models.Spot.Convert; using Binance.Net.Objects.Models.Spot.ConvertTransfer; using Binance.Net.Objects.Models.Spot.Margin; using CryptoExchange.Net; @@ -38,6 +39,9 @@ public class BinanceRestClientSpotApiTrading : IBinanceRestClientSpotApiTrading private const string bSwapApi = "sapi"; private const string bSwapVersion = "1"; + private const string convertApi = "sapi"; + private const string convertVersion = "1"; + // Orders private const string openOrdersEndpoint = "openOrders"; private const string allOrdersEndpoint = "allOrders"; @@ -96,6 +100,9 @@ public class BinanceRestClientSpotApiTrading : IBinanceRestClientSpotApiTrading private const string payTradeHistoryEndpoint = "pay/transactions"; // Convert + private const string convertQuoteRequestEndpoint = "convert/getQuote"; + private const string convertAcceptQuoteEndpoint = "convert/acceptQuote"; + private const string convertOrderStatusEndpoint = "convert/orderStatus"; private const string convertTradeHistoryEndpoint = "convert/tradeFlow"; // Convert transfer @@ -1243,6 +1250,62 @@ public async Task>> GetPayTradeHistor #region Convert + #region Convert Quote Request + + /// + public async Task> ConvertQuoteRequestAsync(string quoteAsset, string baseAsset, decimal? quoteQuantity = null, decimal? baseQuantity = null, WalletType? walletType = null, ValidTime? validTime = null, long? receiveWindow = null, CancellationToken ct = default) + { + if (quoteQuantity == null && baseQuantity == null || quoteQuantity != null && baseQuantity != null) + throw new ArgumentException("Either quoteQuantity or baseQuantity must be sent, but not both"); + + var parameters = new Dictionary(); + parameters.AddParameter("fromAsset", quoteAsset); + parameters.AddParameter("toAsset", baseAsset); + parameters.AddOptionalParameter("fromAmount", quoteQuantity?.ToString(CultureInfo.InvariantCulture)); + parameters.AddOptionalParameter("toAmount", baseQuantity?.ToString(CultureInfo.InvariantCulture)); + parameters.AddOptionalParameter("walletType", walletType != null ? JsonConvert.SerializeObject(walletType, new WalletTypeConverter(false)) : null); + parameters.AddOptionalParameter("validTime", EnumConverter.GetString(validTime)); + parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); + + return await _baseClient.SendRequestInternal(_baseClient.GetUrl(convertQuoteRequestEndpoint, convertApi, convertVersion), HttpMethod.Post, ct, parameters, true, weight: 200).ConfigureAwait(false); + } + + #endregion + + #region Convert Accept Quote + + /// + public async Task> ConvertAcceptQuoteAsync(string quoteId, long? receiveWindow = null, CancellationToken ct = default) + { + var parameters = new Dictionary(); + parameters.AddParameter("quoteId", quoteId); + parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); + + return await _baseClient.SendRequestInternal(_baseClient.GetUrl(convertAcceptQuoteEndpoint, convertApi, convertVersion), HttpMethod.Post, ct, parameters, true, weight: 500).ConfigureAwait(false); + } + + #endregion + + #region Get Convert Order Status + + /// + public async Task> GetConvertOrderStatusAsync(string? orderId = null, string? quoteId = null, long? receiveWindow = null, CancellationToken ct = default) + { + if (orderId == null && quoteId == null || orderId != null && quoteId != null) + throw new ArgumentException("Either orderId or quoteId must be sent, but not both"); + + var parameters = new Dictionary(); + parameters.AddOptionalParameter("orderId", orderId); + parameters.AddOptionalParameter("quoteId", quoteId); + parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); + + return await _baseClient.SendRequestInternal(_baseClient.GetUrl(convertOrderStatusEndpoint, convertApi, convertVersion), HttpMethod.Get, ct, parameters, true, weight: 100).ConfigureAwait(false); + } + + #endregion + + #region Get Convert Trade History + /// public async Task>> GetConvertTradeHistoryAsync(DateTime startTime, DateTime endTime, int? limit = null, long? receiveWindow = null, CancellationToken ct = default) { @@ -1252,11 +1315,13 @@ public async Task>> GetConv parameters.AddOptionalParameter("limit", limit); parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - return await _baseClient.SendRequestInternal>(_baseClient.GetUrl(convertTradeHistoryEndpoint, marginApi, marginVersion), HttpMethod.Get, ct, parameters, true, weight: 100).ConfigureAwait(false); + return await _baseClient.SendRequestInternal>(_baseClient.GetUrl(convertTradeHistoryEndpoint, convertApi, convertVersion), HttpMethod.Get, ct, parameters, true, weight: 3000).ConfigureAwait(false); } #endregion + #endregion + #region Convert Transfer /// public async Task> ConvertTransferAsync(string clientTransferId, string asset, decimal quantity, string targetAsset, long? receiveWindow = null, CancellationToken ct = default) diff --git a/Binance.Net/Enums/ConvertOrderStatus.cs b/Binance.Net/Enums/ConvertOrderStatus.cs new file mode 100644 index 000000000..1ed1f2461 --- /dev/null +++ b/Binance.Net/Enums/ConvertOrderStatus.cs @@ -0,0 +1,31 @@ +using CryptoExchange.Net.Attributes; + +namespace Binance.Net.Enums +{ + /// + /// Convert Order status + /// + public enum ConvertOrderStatus + { + /// + /// Process + /// + [Map("PROCESS")] + Process, + /// + /// Accept success + /// + [Map("ACCEPT_SUCCESS")] + AcceptSuccess, + /// + /// Success + /// + [Map("SUCCESS")] + Success, + /// + /// Fail + /// + [Map("FAIL")] + Fail + } +} diff --git a/Binance.Net/Enums/ValidTime.cs b/Binance.Net/Enums/ValidTime.cs new file mode 100644 index 000000000..48a7e818e --- /dev/null +++ b/Binance.Net/Enums/ValidTime.cs @@ -0,0 +1,31 @@ +using CryptoExchange.Net.Attributes; + +namespace Binance.Net.Enums +{ + /// + /// Valid Time + /// + public enum ValidTime + { + /// + /// 10 seconds + /// + [Map("0")] + TenSeconds, + /// + /// 30 seconds + /// + [Map("1")] + ThirtySeconds, + /// + /// 1 minute + /// + [Map("2")] + OneMinute, + /// + /// 2 minutes + /// + [Map("3")] + TwoMinutes + } +} diff --git a/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiExchangeData.cs b/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiExchangeData.cs index 19e2415c3..17e1a4c0f 100644 --- a/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiExchangeData.cs +++ b/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiExchangeData.cs @@ -6,6 +6,7 @@ using Binance.Net.Objects.Models.Spot; using Binance.Net.Objects.Models.Spot.Blvt; using Binance.Net.Objects.Models.Spot.BSwap; +using Binance.Net.Objects.Models.Spot.Convert; using Binance.Net.Objects.Models.Spot.IsolatedMargin; using Binance.Net.Objects.Models.Spot.Margin; using Binance.Net.Objects.Models.Spot.Staking; @@ -427,5 +428,24 @@ Task> GetIsolatedMarginSymbolAsync(st /// Cancellation token /// Task>> GetMarginDelistScheduleAsync(int? receiveWindow = null, CancellationToken ct = default); + + /// + /// Get list all convert pairs + /// + /// + /// Quote asset + /// Base asset + /// Cancellation token + /// + Task>> GetConvertListAllPairsAsync(string? quoteAsset = null, string? baseAsset = null, CancellationToken ct = default); + + /// + /// Get quantity precision per asset + /// + /// + /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request + /// Cancellation token + /// + Task>> GetConvertQuantityPrecisionPerAssetAsync(long? receiveWindow = null, CancellationToken ct = default); } } diff --git a/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiTrading.cs b/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiTrading.cs index 0ff994eb9..94e723557 100644 --- a/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiTrading.cs +++ b/Binance.Net/Interfaces/Clients/SpotApi/IBinanceRestClientSpotApiTrading.cs @@ -8,6 +8,7 @@ using Binance.Net.Objects.Models.Spot; using Binance.Net.Objects.Models.Spot.Blvt; using Binance.Net.Objects.Models.Spot.BSwap; +using Binance.Net.Objects.Models.Spot.Convert; using Binance.Net.Objects.Models.Spot.ConvertTransfer; using Binance.Net.Objects.Models.Spot.Margin; using Binance.Net.Objects.Models.Spot.Staking; @@ -749,6 +750,42 @@ Task> PlaceMarginOCOOrderAsync(string s /// Task>> GetPayTradeHistoryAsync(DateTime? startTime = null, DateTime? endTime = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default); + /// + /// Request a quote for convert asset (selling asset) for base asset (buying asset) + /// + /// + /// Quote asset + /// Base asset + /// Quote quantity + /// Quote quantity + /// The wallet type for convert + /// The valid time for quote + /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request + /// Cancellation token + /// + Task> ConvertQuoteRequestAsync(string quoteAsset, string baseAsset, decimal? quoteQuantity = null, decimal? baseQuantity = null, WalletType? walletType = null, ValidTime? validTime = null, long? receiveWindow = null, CancellationToken ct = default); + + /// + /// Accept the previously requested quote + /// + /// + /// The quote id of the order + /// + /// + /// + Task> ConvertAcceptQuoteAsync(string quoteId, long? receiveWindow = null, CancellationToken ct = default); + + /// + /// Get convert order status + /// + /// + /// The order id of the order + /// The quote id of the order + /// + /// + /// + Task> GetConvertOrderStatusAsync(string? orderId = null, string? quoteId = null, long? receiveWindow = null, CancellationToken ct = default); + /// /// Get convert trade history /// diff --git a/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertAssetPair.cs b/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertAssetPair.cs new file mode 100644 index 000000000..e3c5a3f31 --- /dev/null +++ b/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertAssetPair.cs @@ -0,0 +1,45 @@ +using System; +using Binance.Net.Converters; +using Binance.Net.Enums; +using CryptoExchange.Net.Converters; +using Newtonsoft.Json; + +namespace Binance.Net.Objects.Models.Spot.Convert +{ + /// + /// Convert Pairs + /// + public class BinanceConvertAssetPair + { + /// + /// Quote asset + /// + [JsonProperty("fromAsset")] + public string QuoteAsset { get; set; } = string.Empty; + /// + /// Base asset + /// + [JsonProperty("toAsset")] + public string BaseAsset { get; set; } = string.Empty; + /// + /// Quote asset min quantity + /// + [JsonProperty("fromAssetMinAmount")] + public decimal QuoteAssetMinQuantity { get; set; } + /// + /// Quote asset max quantity + /// + [JsonProperty("fromAssetMaxAmount")] + public decimal QuoteAssetMaxQuantity { get; set; } + /// + /// Base asset min quantity + /// + [JsonProperty("toAssetMinAmount")] + public decimal BaseAssetMinQuantity { get; set; } + /// + /// Base asset max quantity + /// + [JsonProperty("toAssetMaxAmount")] + public decimal BaseAssetMaxQuantity { get; set; } + } +} diff --git a/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertOrderStatus.cs b/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertOrderStatus.cs new file mode 100644 index 000000000..c389e9da5 --- /dev/null +++ b/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertOrderStatus.cs @@ -0,0 +1,58 @@ +using System; +using Binance.Net.Converters; +using Binance.Net.Enums; +using CryptoExchange.Net.Converters; +using Newtonsoft.Json; + +namespace Binance.Net.Objects.Models.Spot.Convert +{ + /// + /// Convert trade info + /// + public class BinanceConvertOrderStatus + { + /// + /// Order id + /// + public string OrderId { get; set; } = string.Empty; + /// + /// Order status + /// + [JsonConverter(typeof(EnumConverter))] + [JsonProperty("orderStatus")] + public ConvertOrderStatus Status { get; set; } + /// + /// Quote asset + /// + [JsonProperty("fromAsset")] + public string QuoteAsset { get; set; } = string.Empty; + /// + /// Quote quantity + /// + [JsonProperty("fromAmount")] + public decimal QuoteQuantity { get; set; } + /// + /// Base asset + /// + [JsonProperty("toAsset")] + public string BaseAsset { get; set; } = string.Empty; + /// + /// Base quantity + /// + [JsonProperty("toAmount")] + public decimal BaseQuantity { get; set; } + /// + /// Price ratio + /// + public decimal Ratio { get; set; } + /// + /// Inverse price ratio + /// + public decimal InverseRatio { get; set; } + /// + /// Creation time + /// + [JsonConverter(typeof(DateTimeConverter))] + public DateTime CreateTime { get; set; } + } +} diff --git a/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertQuantityPrecisionAsset.cs b/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertQuantityPrecisionAsset.cs new file mode 100644 index 000000000..7432b70bf --- /dev/null +++ b/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertQuantityPrecisionAsset.cs @@ -0,0 +1,21 @@ +using System; +using CryptoExchange.Net.Converters; +using Newtonsoft.Json; + +namespace Binance.Net.Objects.Models.Spot.Convert +{ + /// + /// Precision per asset + /// + public class BinanceConvertQuantityPrecisionAsset + { + /// + /// Asset + /// + public string Asset { get; set; } = string.Empty; + /// + /// Fraction + /// + public int Fraction { get; set; } + } +} diff --git a/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertQuote.cs b/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertQuote.cs new file mode 100644 index 000000000..5e86795c1 --- /dev/null +++ b/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertQuote.cs @@ -0,0 +1,40 @@ +using System; +using CryptoExchange.Net.Converters; +using Newtonsoft.Json; + +namespace Binance.Net.Objects.Models.Spot.Convert +{ + /// + /// Convert Quote + /// + public class BinanceConvertQuote + { + /// + /// Quote id + /// + public string? QuoteId { get; set; } + /// + /// Price ratio + /// + public decimal Ratio { get; set; } + /// + /// Inverse price ratio + /// + public decimal InverseRatio { get; set; } + /// + /// Valid Timestamp + /// + public long ValidTimestamp { get; set; } + /// + /// Base quantity + /// + [JsonProperty("toAmount")] + public decimal BaseQuantity { get; set; } + /// + /// Quote quantity + /// + [JsonProperty("fromAmount")] + public decimal QuoteQuantity { get; set; } + + } +} diff --git a/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertResult.cs b/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertResult.cs new file mode 100644 index 000000000..68d20cc1d --- /dev/null +++ b/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertResult.cs @@ -0,0 +1,30 @@ +using System; +using Binance.Net.Converters; +using Binance.Net.Enums; +using CryptoExchange.Net.Converters; +using Newtonsoft.Json; + +namespace Binance.Net.Objects.Models.Spot.Convert +{ + /// + /// Convert Quote + /// + public class BinanceConvertResult + { + /// + /// Order id + /// + public string OrderId { get; set; } = string.Empty; + /// + /// Creation time + /// + [JsonConverter(typeof(DateTimeConverter))] + public DateTime CreateTime { get; set; } + /// + /// Order status + /// + [JsonConverter(typeof(EnumConverter))] + [JsonProperty("orderStatus")] + public ConvertOrderStatus Status { get; set; } + } +} diff --git a/Binance.Net/Objects/Models/Spot/BinanceConvertTrade.cs b/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertTrade.cs similarity index 64% rename from Binance.Net/Objects/Models/Spot/BinanceConvertTrade.cs rename to Binance.Net/Objects/Models/Spot/Convert/BinanceConvertTrade.cs index df47b6cfb..d2b3b3377 100644 --- a/Binance.Net/Objects/Models/Spot/BinanceConvertTrade.cs +++ b/Binance.Net/Objects/Models/Spot/Convert/BinanceConvertTrade.cs @@ -1,8 +1,10 @@ using System; +using Binance.Net.Converters; +using Binance.Net.Enums; using CryptoExchange.Net.Converters; using Newtonsoft.Json; -namespace Binance.Net.Objects.Models.Spot +namespace Binance.Net.Objects.Models.Spot.Convert { /// /// Convert trade info @@ -20,25 +22,29 @@ public class BinanceConvertTrade /// /// Order status /// - public string OrderStatus { get; set; } = string.Empty; + [JsonConverter(typeof(EnumConverter))] + [JsonProperty("orderStatus")] + public ConvertOrderStatus Status { get; set; } /// - /// From asset + /// Quote asset /// - public string FromAsset { get; set; } = string.Empty; + [JsonProperty("fromAsset")] + public string QuoteAsset { get; set; } = string.Empty; /// - /// From quantity + /// Quote quantity /// [JsonProperty("fromAmount")] - public decimal FromQuantity { get; set; } + public decimal QuoteQuantity { get; set; } /// - /// To asset + /// Base asset /// - public string ToAsset { get; set; } = string.Empty; + [JsonProperty("toAsset")] + public string BaseAsset { get; set; } = string.Empty; /// - /// To quantity + /// Base quantity /// [JsonProperty("toAmount")] - public decimal ToQuantity { get; set; } + public decimal BaseQuantity { get; set; } /// /// Price ratio ///