From 553e2661d6d5f26346071b40425aa09a6ee765a8 Mon Sep 17 00:00:00 2001 From: JKorf Date: Thu, 4 Jan 2024 11:44:51 +0100 Subject: [PATCH] Added UnifiedApi.Account.GetTransferAsync endpoint --- .../Unified/Account/GetTransferAsync.txt | 17 ++++ .../Account/SetIsolatedMarginModeAsync.txt | 9 ++ OKX.Net.UnitTests/JsonTests.cs | 6 +- .../OKXRestClientUnifiedApiAccount.cs | 15 ++++ OKX.Net/Enums/OKXTransferStatus.cs | 25 ++++++ OKX.Net/Enums/OKXTransferType.cs | 7 +- .../IOKXRestClientUnifiedApiAccount.cs | 11 +++ OKX.Net/OKX.Net.xml | 84 +++++++++++++++++++ OKX.Net/Objects/Funding/OKXTransferInfo.cs | 65 ++++++++++++++ 9 files changed, 236 insertions(+), 3 deletions(-) create mode 100644 OKX.Net.UnitTests/JsonResponses/Unified/Account/GetTransferAsync.txt create mode 100644 OKX.Net.UnitTests/JsonResponses/Unified/Account/SetIsolatedMarginModeAsync.txt create mode 100644 OKX.Net/Enums/OKXTransferStatus.cs create mode 100644 OKX.Net/Objects/Funding/OKXTransferInfo.cs diff --git a/OKX.Net.UnitTests/JsonResponses/Unified/Account/GetTransferAsync.txt b/OKX.Net.UnitTests/JsonResponses/Unified/Account/GetTransferAsync.txt new file mode 100644 index 0000000..9847dd4 --- /dev/null +++ b/OKX.Net.UnitTests/JsonResponses/Unified/Account/GetTransferAsync.txt @@ -0,0 +1,17 @@ +{ + "code": "0", + "data": [ + { + "amt": "1.5", + "ccy": "USDT", + "clientId": "", + "from": "18", + "state": "success", + "subAcct": "test", + "to": "6", + "transId": "1", + "type": "1" + } + ], + "msg": "" +} \ No newline at end of file diff --git a/OKX.Net.UnitTests/JsonResponses/Unified/Account/SetIsolatedMarginModeAsync.txt b/OKX.Net.UnitTests/JsonResponses/Unified/Account/SetIsolatedMarginModeAsync.txt new file mode 100644 index 0000000..e98b0ea --- /dev/null +++ b/OKX.Net.UnitTests/JsonResponses/Unified/Account/SetIsolatedMarginModeAsync.txt @@ -0,0 +1,9 @@ +{ + "code": "0", + "data": [ + { + "isoMode": "automatic" + } + ], + "msg": "" +} \ No newline at end of file diff --git a/OKX.Net.UnitTests/JsonTests.cs b/OKX.Net.UnitTests/JsonTests.cs index 705795d..f577388 100644 --- a/OKX.Net.UnitTests/JsonTests.cs +++ b/OKX.Net.UnitTests/JsonTests.cs @@ -36,7 +36,9 @@ await _comparer.ProcessSubject("Unified/Account", c => c.UnifiedApi.Account, "SetGreeksAsync", "TransferAsync", "ConvertDustAsync", - "WithdrawAsync" + "WithdrawAsync", + "GetTransferAsync", + "SetIsolatedMarginModeAsync", }, ignoreProperties: new Dictionary> { @@ -72,7 +74,7 @@ public async Task ValidateTradingCalls() { await _comparer.ProcessSubject("Unified/Trading", c => c.UnifiedApi.Trading, useNestedJsonPropertyForAllCompare: new List { "data" }, - parametersToSetNull: new[] { "pageSize", "quoteQuantity", "clientOrderId" }, + parametersToSetNull: new[] { "pageSize", "quoteQuantity", "clientAlgoId" }, ignoreProperties: new Dictionary> { }, diff --git a/OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApiAccount.cs b/OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApiAccount.cs index 0720a9b..7a33e8c 100644 --- a/OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApiAccount.cs +++ b/OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApiAccount.cs @@ -799,4 +799,19 @@ public virtual async Task> SetIsolat return result.As(result.Data.Data.FirstOrDefault()); } + + /// + public virtual async Task> GetTransferAsync(string? transferId = null, string? clientTransferId = null, OKXTransferType? type = null, CancellationToken ct = default) + { + var parameters = new ParameterCollection(); + parameters.AddOptional("transId", transferId); + parameters.AddOptional("clientId", clientTransferId); + parameters.AddOptionalEnum("type", type); + + var result = await _baseClient.ExecuteAsync>>(_baseClient.GetUri("api/v5/asset/transfer-state"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); + if (!result.Success) return result.AsError(result.Error!); + if (result.Data.ErrorCode > 0) return result.AsError(new OKXRestApiError(result.Data.ErrorCode, result.Data.ErrorMessage!, null)); + + return result.As(result.Data.Data.FirstOrDefault()); + } } diff --git a/OKX.Net/Enums/OKXTransferStatus.cs b/OKX.Net/Enums/OKXTransferStatus.cs new file mode 100644 index 0000000..c3bf4c2 --- /dev/null +++ b/OKX.Net/Enums/OKXTransferStatus.cs @@ -0,0 +1,25 @@ +using CryptoExchange.Net.Attributes; + +namespace OKX.Net.Enums; + +/// +/// Status of a transfer +/// +public enum OKXTransferStatus +{ + /// + /// Success + /// + [Map("success")] + Success, + /// + /// Pending transfer + /// + [Map("pending")] + Pending, + /// + /// Transfer failed + /// + [Map("failed")] + Failed +} diff --git a/OKX.Net/Enums/OKXTransferType.cs b/OKX.Net/Enums/OKXTransferType.cs index cc3caa7..b602913 100644 --- a/OKX.Net/Enums/OKXTransferType.cs +++ b/OKX.Net/Enums/OKXTransferType.cs @@ -1,9 +1,14 @@ -namespace OKX.Net.Enums; +using CryptoExchange.Net.Attributes; + +namespace OKX.Net.Enums; #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public enum OKXTransferType { + [Map("0")] TransferWithinAccount, + [Map("1")] MasterAccountToSubAccount, + [Map("2")] SubAccountToMasterAccount, } \ No newline at end of file diff --git a/OKX.Net/Interfaces/Clients/UnifiedApi/IOKXRestClientUnifiedApiAccount.cs b/OKX.Net/Interfaces/Clients/UnifiedApi/IOKXRestClientUnifiedApiAccount.cs index 927bf78..fa21467 100644 --- a/OKX.Net/Interfaces/Clients/UnifiedApi/IOKXRestClientUnifiedApiAccount.cs +++ b/OKX.Net/Interfaces/Clients/UnifiedApi/IOKXRestClientUnifiedApiAccount.cs @@ -417,10 +417,21 @@ public interface IOKXRestClientUnifiedApiAccount /// /// Set isolated margin mode for the Margin or Contracts instrument type + /// /// /// Instrument type, only Margin and Contracts supported /// Isolated margin mode /// Cancellation Token /// Task> SetIsolatedMarginModeAsync(OKXInstrumentType instumentType, OKXIsolatedMarginMode isolatedMarginMode, CancellationToken ct = default); + + /// + /// Get info on a transfer + /// + /// + /// Transfer id, either this or clientTransferId needs to be provided + /// Client transfer id, either this or transferId needs to be provided + /// Cancellation Token + /// + Task> GetTransferAsync(string? transferId = null, string? clientTransferId = null, OKXTransferType? type = null, CancellationToken ct = default); } \ No newline at end of file diff --git a/OKX.Net/OKX.Net.xml b/OKX.Net/OKX.Net.xml index da6c1d8..62c8185 100644 --- a/OKX.Net/OKX.Net.xml +++ b/OKX.Net/OKX.Net.xml @@ -199,6 +199,9 @@ + + + @@ -798,6 +801,26 @@ Cancel both + + + Status of a transfer + + + + + Success + + + + + Pending transfer + + + + + Transfer failed + + Trigger price tpye @@ -1294,12 +1317,23 @@ Set isolated margin mode for the Margin or Contracts instrument type + Instrument type, only Margin and Contracts supported Isolated margin mode Cancellation Token + + + Get info on a transfer + + + Transfer id, either this or clientTransferId needs to be provided + Client transfer id, either this or transferId needs to be provided + Cancellation Token + + Unified exchange data endpoints @@ -4350,6 +4384,56 @@ Pending amount + + + Transfer info + + + + + Asset + + + + + Transfer id + + + + + Quantity + + + + + From account + + + + + To account + + + + + Client id + + + + + Type of transfer + + + + + Name of the sub account + + + + + Type of transfer + + Transfer response diff --git a/OKX.Net/Objects/Funding/OKXTransferInfo.cs b/OKX.Net/Objects/Funding/OKXTransferInfo.cs new file mode 100644 index 0000000..b0cd06f --- /dev/null +++ b/OKX.Net/Objects/Funding/OKXTransferInfo.cs @@ -0,0 +1,65 @@ +using OKX.Net.Converters; +using OKX.Net.Enums; + +namespace OKX.Net.Objects.Funding; + +/// +/// Transfer info +/// +public class OKXTransferInfo +{ + /// + /// Asset + /// + [JsonProperty("ccy")] + public string Asset { get; set; } = string.Empty; + + /// + /// Transfer id + /// + [JsonProperty("transId")] + public long? TransferId { get; set; } + + /// + /// Quantity + /// + [JsonProperty("amt")] + public decimal Quantity { get; set; } + + /// + /// From account + /// + [JsonProperty("from"), JsonConverter(typeof(AccountConverter))] + public OKXAccount? From { get; set; } + + /// + /// To account + /// + [JsonProperty("to"), JsonConverter(typeof(AccountConverter))] + public OKXAccount? To { get; set; } + + /// + /// Client id + /// + [JsonProperty("clientId")] + public string? ClientId { get; set; } + + /// + /// Type of transfer + /// + [JsonProperty("type")] + [JsonConverter(typeof(EnumConverter))] + public OKXTransferType Type { get; set; } + + /// + /// Name of the sub account + /// + [JsonProperty("subAcct")] + public string? SubAccountName { get; set; } + + /// + /// Type of transfer + /// + [JsonProperty("state")] + public OKXTransferStatus Status { get; set; } +} \ No newline at end of file