Skip to content

Commit

Permalink
Added UnifiedApi.Account.GetTransferAsync endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Jan 4, 2024
1 parent 0aa3ca2 commit 553e266
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"code": "0",
"data": [
{
"isoMode": "automatic"
}
],
"msg": ""
}
6 changes: 4 additions & 2 deletions OKX.Net.UnitTests/JsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ await _comparer.ProcessSubject("Unified/Account", c => c.UnifiedApi.Account,
"SetGreeksAsync",
"TransferAsync",
"ConvertDustAsync",
"WithdrawAsync"
"WithdrawAsync",
"GetTransferAsync",
"SetIsolatedMarginModeAsync",
},
ignoreProperties: new Dictionary<string, List<string>>
{
Expand Down Expand Up @@ -72,7 +74,7 @@ public async Task ValidateTradingCalls()
{
await _comparer.ProcessSubject("Unified/Trading", c => c.UnifiedApi.Trading,
useNestedJsonPropertyForAllCompare: new List<string> { "data" },
parametersToSetNull: new[] { "pageSize", "quoteQuantity", "clientOrderId" },
parametersToSetNull: new[] { "pageSize", "quoteQuantity", "clientAlgoId" },
ignoreProperties: new Dictionary<string, List<string>>
{
},
Expand Down
15 changes: 15 additions & 0 deletions OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApiAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -799,4 +799,19 @@ public virtual async Task<WebCallResult<OKXAccountIsolatedMarginMode>> SetIsolat

return result.As(result.Data.Data.FirstOrDefault());
}

/// <inheritdoc />
public virtual async Task<WebCallResult<OKXTransferInfo>> 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<OKXRestApiResponse<IEnumerable<OKXTransferInfo>>>(_baseClient.GetUri("api/v5/asset/transfer-state"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false);
if (!result.Success) return result.AsError<OKXTransferInfo>(result.Error!);
if (result.Data.ErrorCode > 0) return result.AsError<OKXTransferInfo>(new OKXRestApiError(result.Data.ErrorCode, result.Data.ErrorMessage!, null));

return result.As(result.Data.Data.FirstOrDefault());
}
}
25 changes: 25 additions & 0 deletions OKX.Net/Enums/OKXTransferStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using CryptoExchange.Net.Attributes;

namespace OKX.Net.Enums;

/// <summary>
/// Status of a transfer
/// </summary>
public enum OKXTransferStatus
{
/// <summary>
/// Success
/// </summary>
[Map("success")]
Success,
/// <summary>
/// Pending transfer
/// </summary>
[Map("pending")]
Pending,
/// <summary>
/// Transfer failed
/// </summary>
[Map("failed")]
Failed
}
7 changes: 6 additions & 1 deletion OKX.Net/Enums/OKXTransferType.cs
Original file line number Diff line number Diff line change
@@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,21 @@ public interface IOKXRestClientUnifiedApiAccount

/// <summary>
/// Set isolated margin mode for the Margin or Contracts instrument type
/// <para><a href="https://www.okx.com/docs-v5/en/#trading-account-rest-api-isolated-margin-trading-settings" /></para>
/// </summary>
/// <param name="instumentType">Instrument type, only Margin and Contracts supported</param>
/// <param name="isolatedMarginMode">Isolated margin mode</param>
/// <param name="ct">Cancellation Token</param>
/// <returns></returns>
Task<WebCallResult<OKXAccountIsolatedMarginMode>> SetIsolatedMarginModeAsync(OKXInstrumentType instumentType, OKXIsolatedMarginMode isolatedMarginMode, CancellationToken ct = default);

/// <summary>
/// Get info on a transfer
/// <para><a href="https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-funds-transfer-state" /></para>
/// </summary>
/// <param name="transferId">Transfer id, either this or clientTransferId needs to be provided</param>
/// <param name="clientTransferId">Client transfer id, either this or transferId needs to be provided</param>
/// <param name="ct">Cancellation Token</param>
/// <returns></returns>
Task<WebCallResult<OKXTransferInfo>> GetTransferAsync(string? transferId = null, string? clientTransferId = null, OKXTransferType? type = null, CancellationToken ct = default);

Check warning on line 436 in OKX.Net/Interfaces/Clients/UnifiedApi/IOKXRestClientUnifiedApiAccount.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'type' has no matching param tag in the XML comment for 'IOKXRestClientUnifiedApiAccount.GetTransferAsync(string?, string?, OKXTransferType?, CancellationToken)' (but other parameters do)

Check warning on line 436 in OKX.Net/Interfaces/Clients/UnifiedApi/IOKXRestClientUnifiedApiAccount.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'type' has no matching param tag in the XML comment for 'IOKXRestClientUnifiedApiAccount.GetTransferAsync(string?, string?, OKXTransferType?, CancellationToken)' (but other parameters do)

Check warning on line 436 in OKX.Net/Interfaces/Clients/UnifiedApi/IOKXRestClientUnifiedApiAccount.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'type' has no matching param tag in the XML comment for 'IOKXRestClientUnifiedApiAccount.GetTransferAsync(string?, string?, OKXTransferType?, CancellationToken)' (but other parameters do)

Check warning on line 436 in OKX.Net/Interfaces/Clients/UnifiedApi/IOKXRestClientUnifiedApiAccount.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'type' has no matching param tag in the XML comment for 'IOKXRestClientUnifiedApiAccount.GetTransferAsync(string?, string?, OKXTransferType?, CancellationToken)' (but other parameters do)
}
84 changes: 84 additions & 0 deletions OKX.Net/OKX.Net.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions OKX.Net/Objects/Funding/OKXTransferInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using OKX.Net.Converters;
using OKX.Net.Enums;

namespace OKX.Net.Objects.Funding;

/// <summary>
/// Transfer info
/// </summary>
public class OKXTransferInfo
{
/// <summary>
/// Asset
/// </summary>
[JsonProperty("ccy")]
public string Asset { get; set; } = string.Empty;

/// <summary>
/// Transfer id
/// </summary>
[JsonProperty("transId")]
public long? TransferId { get; set; }

/// <summary>
/// Quantity
/// </summary>
[JsonProperty("amt")]
public decimal Quantity { get; set; }

/// <summary>
/// From account
/// </summary>
[JsonProperty("from"), JsonConverter(typeof(AccountConverter))]
public OKXAccount? From { get; set; }

/// <summary>
/// To account
/// </summary>
[JsonProperty("to"), JsonConverter(typeof(AccountConverter))]
public OKXAccount? To { get; set; }

/// <summary>
/// Client id
/// </summary>
[JsonProperty("clientId")]
public string? ClientId { get; set; }

/// <summary>
/// Type of transfer
/// </summary>
[JsonProperty("type")]
[JsonConverter(typeof(EnumConverter))]
public OKXTransferType Type { get; set; }

/// <summary>
/// Name of the sub account
/// </summary>
[JsonProperty("subAcct")]
public string? SubAccountName { get; set; }

/// <summary>
/// Type of transfer
/// </summary>
[JsonProperty("state")]
public OKXTransferStatus Status { get; set; }
}

0 comments on commit 553e266

Please sign in to comment.