feat(user): add methods to delete submember

This commit is contained in:
Thijmen Maus
2024-02-11 15:25:34 +01:00
parent 2498c5eb9d
commit 304d960567
4 changed files with 66 additions and 38 deletions

View File

@@ -38,6 +38,7 @@ import {
CreateSubMemberParamsV5, CreateSubMemberParamsV5,
CreateSubMemberResultV5, CreateSubMemberResultV5,
CursorListV5, CursorListV5,
DeleteSubMemberParamsV5,
DeliveryPriceV5, DeliveryPriceV5,
DeliveryRecordV5, DeliveryRecordV5,
DepositAddressResultV5, DepositAddressResultV5,
@@ -71,10 +72,10 @@ import {
GetOpenInterestParamsV5, GetOpenInterestParamsV5,
GetOptionDeliveryPriceParamsV5, GetOptionDeliveryPriceParamsV5,
GetOrderbookParamsV5, GetOrderbookParamsV5,
GetPremiumIndexPriceKlineParamsV5,
GetPreUpgradeClosedPnlParamsV5, GetPreUpgradeClosedPnlParamsV5,
GetPreUpgradeOrderHistoryParamsV5, GetPreUpgradeOrderHistoryParamsV5,
GetPreUpgradeTradeHistoryParamsV5, GetPreUpgradeTradeHistoryParamsV5,
GetPremiumIndexPriceKlineParamsV5,
GetPublicTradingHistoryParamsV5, GetPublicTradingHistoryParamsV5,
GetRiskLimitParamsV5, GetRiskLimitParamsV5,
GetSettlementRecordParamsV5, GetSettlementRecordParamsV5,
@@ -90,18 +91,18 @@ import {
InsuranceResponseV5, InsuranceResponseV5,
InternalDepositRecordV5, InternalDepositRecordV5,
InternalTransferRecordV5, InternalTransferRecordV5,
LeverageTokenInfoV5,
LeveragedTokenMarketResultV5, LeveragedTokenMarketResultV5,
LeverageTokenInfoV5,
MMPModifyParamsV5, MMPModifyParamsV5,
MMPStateV5, MMPStateV5,
OHLCKlineV5, OHLCKlineV5,
OHLCVKlineV5, OHLCVKlineV5,
OpenInterestResponseV5, OpenInterestResponseV5,
OptionDeliveryPriceV5, OptionDeliveryPriceV5,
OrderbookResponseV5,
OrderParamsV5, OrderParamsV5,
OrderResultV5, OrderResultV5,
OrderSideV5, OrderSideV5,
OrderbookResponseV5,
PositionInfoParamsV5, PositionInfoParamsV5,
PositionV5, PositionV5,
PublicTradeV5, PublicTradeV5,
@@ -117,18 +118,18 @@ import {
SetLeverageParamsV5, SetLeverageParamsV5,
SetRiskLimitParamsV5, SetRiskLimitParamsV5,
SetRiskLimitResultV5, SetRiskLimitResultV5,
SettlementRecordV5,
SetTPSLModeParamsV5, SetTPSLModeParamsV5,
SetTradingStopParamsV5, SetTradingStopParamsV5,
SettlementRecordV5,
SpotBorrowCheckResultV5, SpotBorrowCheckResultV5,
SpotLeveragedTokenOrderHistoryV5, SpotLeveragedTokenOrderHistoryV5,
SubMemberV5, SubMemberV5,
SwitchIsolatedMarginParamsV5, SwitchIsolatedMarginParamsV5,
SwitchPositionModeParamsV5, SwitchPositionModeParamsV5,
TPSLModeV5,
TickerLinearInverseV5, TickerLinearInverseV5,
TickerOptionV5, TickerOptionV5,
TickerSpotV5, TickerSpotV5,
TPSLModeV5,
TransactionLogV5, TransactionLogV5,
UnifiedAccountUpgradeResultV5, UnifiedAccountUpgradeResultV5,
UniversalTransferParamsV5, UniversalTransferParamsV5,
@@ -136,8 +137,8 @@ import {
UpdateApiKeyParamsV5, UpdateApiKeyParamsV5,
UpdateApiKeyResultV5, UpdateApiKeyResultV5,
WalletBalanceV5, WalletBalanceV5,
WithdrawParamsV5,
WithdrawalRecordV5, WithdrawalRecordV5,
WithdrawParamsV5,
} from './types'; } from './types';
import { REST_CLIENT_TYPE_ENUM } from './util'; import { REST_CLIENT_TYPE_ENUM } from './util';
@@ -1251,9 +1252,8 @@ export class RestClientV5 extends BaseRestClient {
/** /**
* Create a new sub user id. Use master user's api key only. * Create a new sub user id. Use master user's api key only.
* *
* The API key must own one of permissions will be allowed to call the following API endpoint. * The API key must have one of the permissions to be allowed to call the following API endpoint.
* * - master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
* master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
*/ */
createSubMember( createSubMember(
params: CreateSubMemberParamsV5, params: CreateSubMemberParamsV5,
@@ -1264,9 +1264,8 @@ export class RestClientV5 extends BaseRestClient {
/** /**
* To create new API key for those newly created sub UID. Use master user's api key only. * To create new API key for those newly created sub UID. Use master user's api key only.
* *
* TIP * TIP: The API key must have one of the permissions to be allowed to call the following API endpoint.
* The API key must own one of permissions will be allowed to call the following API endpoint. * - master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
* master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
*/ */
createSubUIDAPIKey( createSubUIDAPIKey(
params: CreateSubApiKeyParamsV5, params: CreateSubApiKeyParamsV5,
@@ -1286,9 +1285,8 @@ export class RestClientV5 extends BaseRestClient {
/** /**
* Froze sub uid. Use master user's api key only. * Froze sub uid. Use master user's api key only.
* *
* TIP: The API key must own one of the following permissions will be allowed to call the following API endpoint. * TIP: The API key must have one of the permissions to be allowed to call the following API endpoint.
* * - master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
* master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
*/ */
setSubUIDFrozenState( setSubUIDFrozenState(
subuid: number, subuid: number,
@@ -1310,9 +1308,8 @@ export class RestClientV5 extends BaseRestClient {
/** /**
* Modify the settings of a master API key. Use the API key pending to be modified to call the endpoint. Use master user's API key only. * Modify the settings of a master API key. Use the API key pending to be modified to call the endpoint. Use master user's API key only.
* *
* TIP: The API key must own one of the permissions to call the following API endpoint. * TIP: The API key must have one of the permissions to be allowed to call the following API endpoint.
* * - master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
* Master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
*/ */
updateMasterApiKey( updateMasterApiKey(
params: UpdateApiKeyParamsV5, params: UpdateApiKeyParamsV5,
@@ -1336,8 +1333,9 @@ export class RestClientV5 extends BaseRestClient {
/** /**
* Delete the api key of master account. Use the api key pending to be delete to call the endpoint. Use master user's api key only. * Delete the api key of master account. Use the api key pending to be delete to call the endpoint. Use master user's api key only.
* *
* TIP: The API key must own one of permissions will be allowed to call the following API endpoint. * TIP:
* master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal" * The API key must have one of the permissions to be allowed to call the following API endpoint.
* - master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
* *
* DANGER: BE CAREFUL! The API key used to call this interface will be invalid immediately. * DANGER: BE CAREFUL! The API key used to call this interface will be invalid immediately.
*/ */
@@ -1348,9 +1346,9 @@ export class RestClientV5 extends BaseRestClient {
/** /**
* Delete the api key of sub account. Use the api key pending to be delete to call the endpoint. Use sub user's api key only. * Delete the api key of sub account. Use the api key pending to be delete to call the endpoint. Use sub user's api key only.
* *
* TIP * TIP:
* The API key must own one of permissions will be allowed to call the following API endpoint. * The API key must have one of the permissions to be allowed to call the following API endpoint.
* sub API key: "Account Transfer" * - sub API key: "Account Transfer"
* *
* DANGER: BE CAREFUL! The API key used to call this interface will be invalid immediately. * DANGER: BE CAREFUL! The API key used to call this interface will be invalid immediately.
*/ */
@@ -1358,6 +1356,19 @@ export class RestClientV5 extends BaseRestClient {
return this.postPrivate('/v5/user/delete-sub-api'); return this.postPrivate('/v5/user/delete-sub-api');
} }
/**
* Delete a sub UID. Before deleting the UID, please make sure there are no assets.
*
* TIP:
* The API key must have one of the permissions to be allowed to call the following API endpoint.
* - master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
*/
deleteSubMember(
params: DeleteSubMemberParamsV5,
): Promise<APIResponseV3WithTime<{}>> {
return this.postPrivate('/v5/user/del-submember', params);
}
/** /**
* *
****** Spot Leverage Token APIs ****** Spot Leverage Token APIs

View File

@@ -124,18 +124,3 @@ export interface WithdrawParamsV5 {
forceChain?: number; forceChain?: number;
accountType?: 'SPOT' | 'FUND'; accountType?: 'SPOT' | 'FUND';
} }
export interface CreateSubMemberParamsV5 {
username: string;
password?: string;
/**
* 1: normal, 6: custodial
*/
memberType: 1 | 6;
/**
* 0: quick login disabled (default), 1: quick login enabled
*/
switch?: 0 | 1;
isUta?: boolean;
note?: string;
}

View File

@@ -1,5 +1,21 @@
import { PermissionsV5 } from '../v5-shared'; import { PermissionsV5 } from '../v5-shared';
export interface CreateSubMemberParamsV5 {
username: string;
password?: string;
/**
* 1: normal, 6: custodial
*/
memberType: 1 | 6;
/**
* 0: quick login disabled (default), 1: quick login enabled
*/
switch?: 0 | 1;
isUta?: boolean;
note?: string;
}
export interface CreateSubApiKeyParamsV5 { export interface CreateSubApiKeyParamsV5 {
subuid: number; subuid: number;
note?: string; note?: string;
@@ -19,3 +35,7 @@ export interface UpdateSubApiKeyUpdateParamsV5 {
ips?: string[]; ips?: string[];
permissions: PermissionsV5; permissions: PermissionsV5;
} }
export interface DeleteSubMemberParamsV5 {
subMemberId: number;
}

View File

@@ -409,6 +409,18 @@ describe('Private WRITE V5 REST API Endpoints', () => {
}); });
}); });
it.skip('deleteSubMember()', async () => {
expect(
await api.deleteSubMember({
subMemberId: 1,
}),
).toMatchObject({
// ...successResponseObjectV3(),
// retMsg: '',
retCode: API_ERROR_CODE.SUB_USER_NOT_FOUND,
});
});
it('setSubUIDFrozenState()', async () => { it('setSubUIDFrozenState()', async () => {
expect(await api.setSubUIDFrozenState(0, 1)).toMatchObject({ expect(await api.setSubUIDFrozenState(0, 1)).toMatchObject({
// ...successResponseObjectV3(), // ...successResponseObjectV3(),