Skip to content

Commit

Permalink
Added restClient.UnifiedApi.Account.PresetAccountModeSwitchAsync and …
Browse files Browse the repository at this point in the history
…PrecheckAccountModeSwitchAsync
  • Loading branch information
JKorf committed Dec 13, 2024
1 parent 40ae2b5 commit 8a013a9
Show file tree
Hide file tree
Showing 11 changed files with 764 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
GET
/api/v5/account/set-account-switch-precheck
true
{
"code": "0",
"data": [
{
"acctLv": "3",
"curAcctLv": "4",
"mgnAft": {
"acctAvailEq": "106002.2061970689",
"details": [],
"mgnRatio": "148.1652396878421"
},
"mgnBf": {
"acctAvailEq": "77308.89735228613",
"details": [],
"mgnRatio": "4.460069474634038"
},
"posList": [
{
"lever": "50",
"posId": "2005456500916518912"
},
{
"lever": "50",
"posId": "2005456108363218944"
},
{
"lever": "50",
"posId": "2005456332909477888"
},
{
"lever": "50",
"posId": "2005456415990251520"
}
],
"posTierCheck": [],
"riskOffsetType": "",
"sCode": "0",
"unmatchedInfoCheck": []
}
],
"msg": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
POST
/api/v5/account/account-level-switch-preset
true
{
"code": "0",
"msg": "",
"data": [{
"acctLv": "3",
"curAcctLv": "2",
"lever": "",
"riskOffsetType": ""
}]
}
2 changes: 2 additions & 0 deletions OKX.Net.UnitTests/RestRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public async Task ValidateAccountCalls()
await tester.ValidateAsync(client => client.UnifiedApi.Account.GetBorrowRepayHistoryAsync(), "GetBorrowRepayHistory", nestedJsonProperty: "data");
await tester.ValidateAsync(client => client.UnifiedApi.Account.GetEasyConvertDustAssetsAsync(), "GetEasyConvertDustAssets", nestedJsonProperty: "data", useSingleArrayItem: true);
await tester.ValidateAsync(client => client.UnifiedApi.Account.GetEasyConvertDustHistoryAsync(), "GetEasyConvertDustHistory", nestedJsonProperty: "data");
await tester.ValidateAsync(client => client.UnifiedApi.Account.PresetAccountModeSwitchAsync(AccountLevel.SingleCurrencyMargin), "PresetAccountModeSwitch", nestedJsonProperty: "data");
await tester.ValidateAsync(client => client.UnifiedApi.Account.PrecheckAccountModeSwitchAsync(AccountLevel.SingleCurrencyMargin), "PrecheckAccountModeSwitchAsync", nestedJsonProperty: "data");
}

[Test]
Expand Down
24 changes: 24 additions & 0 deletions OKX.Net/Clients/UnifiedApi/OKXRestClientUnifiedApiAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,30 @@ public virtual async Task<WebCallResult<OKXTransferInfo>> GetTransferAsync(strin
return await _baseClient.SendGetSingleAsync<OKXTransferInfo>(request, parameters, ct).ConfigureAwait(false);
}

/// <inheritdoc />
public virtual async Task<WebCallResult<OKXPresetAccountMode>> PresetAccountModeSwitchAsync(AccountLevel mode, int? leverage = null, RiskOffsetType? riskOffsetType = null, CancellationToken ct = default)
{
var parameters = new ParameterCollection();
parameters.AddEnum("acctLv", mode);
parameters.AddOptionalString("lever", leverage);
parameters.AddOptionalEnum("riskOffsetType", riskOffsetType);

var request = _definitions.GetOrCreate(HttpMethod.Post, $"api/v5/account/account-level-switch-preset", OKXExchange.RateLimiter.EndpointGate, 1, true,
limitGuard: new SingleLimitGuard(5, TimeSpan.FromSeconds(2), RateLimitWindowType.Sliding, keySelector: SingleLimitGuard.PerApiKey));
return await _baseClient.SendGetSingleAsync<OKXPresetAccountMode>(request, parameters, ct).ConfigureAwait(false);
}

/// <inheritdoc />
public virtual async Task<WebCallResult<OKXAccountSwitchCheckResult>> PrecheckAccountModeSwitchAsync(AccountLevel mode, CancellationToken ct = default)
{
var parameters = new ParameterCollection();
parameters.AddEnum("acctLv", mode);

var request = _definitions.GetOrCreate(HttpMethod.Get, $"api/v5/account/set-account-switch-precheck", OKXExchange.RateLimiter.EndpointGate, 1, true,
limitGuard: new SingleLimitGuard(5, TimeSpan.FromSeconds(2), RateLimitWindowType.Sliding, keySelector: SingleLimitGuard.PerApiKey));
return await _baseClient.SendGetSingleAsync<OKXAccountSwitchCheckResult>(request, parameters, ct).ConfigureAwait(false);
}

/// <inheritdoc />
public virtual async Task<WebCallResult<OKXAccountMode>> SetAccountModeAsync(AccountLevel mode, CancellationToken ct = default)
{
Expand Down
33 changes: 33 additions & 0 deletions OKX.Net/Enums/AccountSwitchCheckResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using CryptoExchange.Net.Attributes;
using System;
using System.Collections.Generic;
using System.Text;

namespace OKX.Net.Enums;

/// <summary>
/// Check result
/// </summary>
public enum AccountSwitchCheckResult
{
/// <summary>
/// Passed all checks
/// </summary>
[Map("0")]
Passed,
/// <summary>
/// Unmatched information
/// </summary>
[Map("1")]
UmatchedInfo,
/// <summary>
/// Leverage setting is not finished
/// </summary>
[Map("3")]
LeverageSettingNotFinished,
/// <summary>
/// Position tier or margin check is not passed
/// </summary>
[Map("4")]
PositionTierOrMarginNotPassed
}
19 changes: 19 additions & 0 deletions OKX.Net/Enums/RiskOffsetType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using CryptoExchange.Net.Attributes;
using System;
using System.Collections.Generic;
using System.Text;

namespace OKX.Net.Enums;
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

public enum RiskOffsetType
{
[Map("1")]
SpotDerivativesUsdtOffset,
[Map("2")]
SpotDerivativesCryptoOffset,
[Map("4")]
SpotDerivativesUsdcOffset,
[Map("3")]
DerivativesOnlyMode
}
113 changes: 113 additions & 0 deletions OKX.Net/Enums/UnmatchedInfoType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using CryptoExchange.Net.Attributes;
using System;
using System.Collections.Generic;
using System.Text;

namespace OKX.Net.Enums;
/// <summary>
/// Unmatched info type
/// </summary>
public enum UnmatchedInfoType
{
/// <summary>
/// Asset validation
/// </summary>
[Map("asset_validation")]
AssetValidation,
/// <summary>
/// Order book pending orders
/// </summary>
[Map("pending_orders")]
PendingOrders,
/// <summary>
/// Pending algo orders and trading bots, such as iceberg, recurring buy and twap
/// </summary>
[Map("pending_algos")]
PendingAlgos,
/// <summary>
/// Isolated margin (quick margin and manual transfers
/// </summary>
[Map("isolated_margin")]
IsolatedMargin,
/// <summary>
/// Isolated contract (manual transfers
/// </summary>
[Map("isolated_contract")]
IsolatedContract,
/// <summary>
/// Contract positions in hedge mode
/// </summary>
[Map("contract_long_short")]
ContractLongShort,
/// <summary>
/// Cross margin positions
/// </summary>
[Map("cross_margin")]
CrossMargin,
/// <summary>
/// Cross options buyer
/// </summary>
[Map("cross_option_buyer")]
CrossOptionBuyer,
/// <summary>
/// Isolated options (only applicable to spot mode
/// </summary>
[Map("isolated_option")]
IsolatedOption,
/// <summary>
/// Positions with trial funds
/// </summary>
[Map("growth_fund")]
GrowthFund,
/// <summary>
/// All positions
/// </summary>
[Map("all_positions")]
AllPositions,
/// <summary>
/// Copy trader and customize lead trader can only use spot mode or spot and futures mode
/// </summary>
[Map("spot_lead_copy_only_simple_single")]
SpotLeadCopyOnlySimpleSingle,
/// <summary>
/// Spot customize copy trading
/// </summary>
[Map("stop_spot_custom")]
StopSpotCustom,
/// <summary>
/// Contract customize copy trading
/// </summary>
[Map("stop_futures_custom")]
StopFuturesCustom,
/// <summary>
/// Lead trader can not switch to portfolio margin mode
/// </summary>
[Map("lead_portfolio")]
LeadPortfolio,
/// <summary>
/// You can not switch to spot mode when having smart contract sync
/// </summary>
[Map("futures_smart_sync")]
FuturesSmartSync,
/// <summary>
/// Vip loan
/// </summary>
[Map("vip_fixed_loan")]
VipFixedLoan,
/// <summary>
/// Borrowings
/// </summary>
[Map("repay_borrowings")]
RepayBorrowings,
/// <summary>
/// Due to compliance restrictions, margin trading services are unavailable
/// </summary>
[Map("compliance_restriction")]
ComplianceRestriction,
/// <summary>
/// Due to compliance restrictions, margin trading services are unavailable. if you are not a resident of this region, please complete kyc2 identity verification.
/// </summary>
[Map("compliance_kyc2")]
ComplianceKyc2,
}

Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,26 @@ public interface IOKXRestClientUnifiedApiAccount
/// <returns></returns>
Task<WebCallResult<OKXTransferInfo>> GetTransferAsync(string? transferId = null, string? clientTransferId = null, TransferType? type = null, CancellationToken ct = default);

/// <summary>
/// Preset info for switching account mode
/// <para><a href="https://www.okx.com/docs-v5/en/#trading-account-rest-api-preset-account-mode-switch" /></para>
/// </summary>
/// <param name="mode">Account mode</param>
/// <param name="leverage">Leverage, required when switching from Portfolio margin mode to Spot and futures mode or Multi-currency margin mode, and the user holds cross-margin positions.</param>
/// <param name="riskOffsetType">Risk offset type, applicable when switching from Spot and futures mode or Multi-currency margin mode to Portfolio margin mode.</param>
/// <param name="ct">Cancellation Token</param>
/// <returns></returns>
Task<WebCallResult<OKXPresetAccountMode>> PresetAccountModeSwitchAsync(AccountLevel mode, int? leverage = null, RiskOffsetType? riskOffsetType = null, CancellationToken ct = default);

/// <summary>
/// Run a pre-check for account mode switching
/// <para><a href="https://www.okx.com/docs-v5/en/#trading-account-rest-api-precheck-account-mode-switch" /></para>
/// </summary>
/// <param name="mode">Account mode</param>
/// <param name="ct">Cancellation Token</param>
/// <returns></returns>
Task<WebCallResult<OKXAccountSwitchCheckResult>> PrecheckAccountModeSwitchAsync(AccountLevel mode, CancellationToken ct = default);

/// <summary>
/// Set the account mode
/// <para><a href="https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-account-mode" /></para>
Expand Down
Loading

0 comments on commit 8a013a9

Please sign in to comment.