From d4add6d9645f8de2bafdcb9ca09c963354d98356 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Thu, 16 Feb 2023 15:30:01 +0000 Subject: [PATCH] add v5 user rest endpoints --- src/rest-client-v5.ts | 124 ++++++++++++++++++++++++++++++++++ src/types/request/index.ts | 1 + src/types/request/v5-asset.ts | 7 ++ src/types/request/v5-user.ts | 21 ++++++ src/types/response/index.ts | 1 + src/types/response/v5-user.ts | 58 ++++++++++++++++ src/types/v5-shared.ts | 19 ++++++ 7 files changed, 231 insertions(+) create mode 100644 src/types/request/v5-user.ts create mode 100644 src/types/response/v5-user.ts diff --git a/src/rest-client-v5.ts b/src/rest-client-v5.ts index 02a83a9..4bb3ff9 100644 --- a/src/rest-client-v5.ts +++ b/src/rest-client-v5.ts @@ -107,6 +107,14 @@ import { GetWithdrawalRecordsParamsV5, WithdrawalRecordV5, WithdrawParamsV5, + CreateSubMemberParamsV5, + CreateSubMemberResultV5, + CreateSubApiKeyParamsV5, + CreateSubApiKeyResultV5, + SubMemberV5, + ApiKeyInfoV5, + UpdateApiKeyResultV5, + UpdateApiKeyParamsV5, } from './types'; import { REST_CLIENT_TYPE_ENUM } from './util'; import BaseRestClient from './util/BaseRestClient'; @@ -1016,6 +1024,122 @@ export class RestClientV5 extends BaseRestClient { ): Promise> { return this.postPrivate('/v5/asset/withdraw/cancel', { id }); } + + /** + * + ****** User APIs + * + */ + + /** + * 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. + * + * master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal" + */ + createSubMember( + params: CreateSubMemberParamsV5 + ): Promise> { + return this.postPrivate('/v5/user/create-sub-member', params); + } + + /** + * To create new API key for those newly created sub UID. 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. + * master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal" + */ + createSubUIDAPIKey( + params: CreateSubApiKeyParamsV5 + ): Promise> { + return this.postPrivate('/v5/user/create-sub-api', params); + } + + /** + * This endpoint allows you to get a list of all sub UID of master account. + */ + getSubUIDList(): Promise< + APIResponseV3WithTime<{ subMembers: SubMemberV5[] }> + > { + return this.getPrivate('/v5/user/query-sub-members'); + } + + /** + * 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. + * + * master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal" + */ + setSubUIDFrozenState( + subuid: number, + frozen: 0 | 1 + ): Promise> { + return this.postPrivate('/v5/user/frozen-sub-member', { subuid, frozen }); + } + + /** + * Get the information of the api key. Use the api key pending to be checked to call the endpoint. Both master and sub user's api key are applicable. + * + * TIP: Any permission can access this endpoint. + */ + getQueryApiKey(): Promise> { + return this.getPrivate('/v5/user/query-api'); + } + + /** + * 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. + * + * Master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal" + */ + updateMasterApiKey( + params: UpdateApiKeyParamsV5 + ): Promise> { + return this.postPrivate('/v5/user/update-api', params); + } + + /** + * This endpoint modifies the settings of a sub API key. + * Use the API key pending to be modified to call the endpoint. + * Only the API key that calls this interface can be modified. + * + * The API key must own "Account Transfer" permission to be allowed to call this API endpoint. + */ + updateSubApiKey( + params: UpdateApiKeyParamsV5 + ): Promise> { + return this.postPrivate('/v5/user/update-sub-api', params); + } + + /** + * 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. + * master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal" + * + * DANGER: BE CAREFUL! The API key used to call this interface will be invalid immediately. + */ + deleteMasterApiKey(): Promise> { + return this.postPrivate('/v5/user/delete-api'); + } + + /** + * 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 + * The API key must own one of permissions will be allowed to call the following API endpoint. + * sub API key: "Account Transfer" + * + * DANGER: BE CAREFUL! The API key used to call this interface will be invalid immediately. + */ + deleteSubApiKey(): Promise> { + return this.postPrivate('/v5/user/delete-sub-api'); + } + // // // diff --git a/src/types/request/index.ts b/src/types/request/index.ts index bcca1a3..62950e2 100644 --- a/src/types/request/index.ts +++ b/src/types/request/index.ts @@ -13,3 +13,4 @@ export * from './v5-asset'; export * from './v5-market'; export * from './v5-position'; export * from './v5-trade'; +export * from './v5-user'; diff --git a/src/types/request/v5-asset.ts b/src/types/request/v5-asset.ts index 104d522..a1af232 100644 --- a/src/types/request/v5-asset.ts +++ b/src/types/request/v5-asset.ts @@ -127,3 +127,10 @@ export interface WithdrawParamsV5 { forceChain?: number; accountType?: string; } + +export interface CreateSubMemberParamsV5 { + username: string; + memberType: 1 | 6; + switch?: 0 | 1; + note?: string; +} diff --git a/src/types/request/v5-user.ts b/src/types/request/v5-user.ts new file mode 100644 index 0000000..f1d60cf --- /dev/null +++ b/src/types/request/v5-user.ts @@ -0,0 +1,21 @@ +import { PermissionsV5 } from '../v5-shared'; + +export interface CreateSubApiKeyParamsV5 { + subuid: number; + note?: string; + readOnly: 0 | 1; + ips?: string[]; + permissions: PermissionsV5; +} + +export interface UpdateApiKeyParamsV5 { + readOnly?: 0 | 1; + ips?: string[]; + permissions: PermissionsV5; +} + +export interface UpdateSubApiKeyUpdateParamsV5 { + readOnly?: number; + ips?: string[]; + permissions: PermissionsV5; +} diff --git a/src/types/response/index.ts b/src/types/response/index.ts index 43642ce..c2edf86 100644 --- a/src/types/response/index.ts +++ b/src/types/response/index.ts @@ -9,3 +9,4 @@ export * from './v5-asset'; export * from './v5-market'; export * from './v5-position'; export * from './v5-trade'; +export * from './v5-user'; diff --git a/src/types/response/v5-user.ts b/src/types/response/v5-user.ts new file mode 100644 index 0000000..18cea54 --- /dev/null +++ b/src/types/response/v5-user.ts @@ -0,0 +1,58 @@ +import { PermissionsV5 } from '../v5-shared'; + +export interface CreateSubMemberResultV5 { + uid: string; + username: string; + memberType: number; + status: number; + remark: string; +} + +export interface CreateSubApiKeyResultV5 { + id: string; + note: string; + apiKey: string; + readOnly: number; + secret: string; + permissions: PermissionsV5; +} + +export interface SubMemberV5 { + uid: string; + username: string; + memberType: number; + status: number; + remark: string; +} +export type ApiKeyType = 1 | 2; + +export interface ApiKeyInfoV5 { + id: string; + note: string; + apiKey: string; + readOnly: 0 | 1; + secret: string; + permissions: PermissionsV5; + ips?: string[]; + type: 1 | 2; + deadlineDay?: number; + expiredAt?: string; + createdAt: string; + unified: 0 | 1; + uta: 0 | 1; + userID: number; + inviterID: number; + vipLevel?: string; + mktMakerLevel?: string; + affiliateID?: number; +} + +export interface UpdateApiKeyResultV5 { + id: string; + note: string; + apiKey: string; + readOnly: 0 | 1; + secret: string; + permissions: PermissionsV5; + ips: string[]; +} diff --git a/src/types/v5-shared.ts b/src/types/v5-shared.ts index 99c23ee..f2b18d2 100644 --- a/src/types/v5-shared.ts +++ b/src/types/v5-shared.ts @@ -34,6 +34,25 @@ export type TransactionTypeV5 = | 'CURRENCY_BUY' | 'CURRENCY_SELL'; +export type PermissionTypeV5 = + | 'ContractTrade' + | 'Spot' + | 'Wallet' + | 'Options' + | 'Derivatives' + | 'Exchange' + | 'NFT'; + +export interface PermissionsV5 { + ContractTrade?: string[]; + Spot?: string[]; + Wallet?: string[]; + Options?: string[]; + Derivatives?: string[]; + Exchange?: string[]; + NFT?: string[]; +} + export interface CategoryCursorListV5 { category: CategoryV5; list: T;