add v5 user rest endpoints

This commit is contained in:
tiagosiebler
2023-02-16 15:30:01 +00:00
parent e312491968
commit d4add6d964
7 changed files with 231 additions and 0 deletions

View File

@@ -107,6 +107,14 @@ import {
GetWithdrawalRecordsParamsV5, GetWithdrawalRecordsParamsV5,
WithdrawalRecordV5, WithdrawalRecordV5,
WithdrawParamsV5, WithdrawParamsV5,
CreateSubMemberParamsV5,
CreateSubMemberResultV5,
CreateSubApiKeyParamsV5,
CreateSubApiKeyResultV5,
SubMemberV5,
ApiKeyInfoV5,
UpdateApiKeyResultV5,
UpdateApiKeyParamsV5,
} from './types'; } from './types';
import { REST_CLIENT_TYPE_ENUM } from './util'; import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient'; import BaseRestClient from './util/BaseRestClient';
@@ -1016,6 +1024,122 @@ export class RestClientV5 extends BaseRestClient {
): Promise<APIResponseV3WithTime<{ status: 0 | 1 }>> { ): Promise<APIResponseV3WithTime<{ status: 0 | 1 }>> {
return this.postPrivate('/v5/asset/withdraw/cancel', { id }); 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<APIResponseV3WithTime<CreateSubMemberResultV5>> {
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<APIResponseV3WithTime<CreateSubApiKeyResultV5>> {
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<APIResponseV3WithTime<{}>> {
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<APIResponseV3WithTime<ApiKeyInfoV5>> {
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<APIResponseV3WithTime<UpdateApiKeyResultV5>> {
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<APIResponseV3<UpdateApiKeyResultV5>> {
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<APIResponseV3WithTime<{}>> {
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<APIResponseV3WithTime<{}>> {
return this.postPrivate('/v5/user/delete-sub-api');
}
// //
// //
// //

View File

@@ -13,3 +13,4 @@ export * from './v5-asset';
export * from './v5-market'; export * from './v5-market';
export * from './v5-position'; export * from './v5-position';
export * from './v5-trade'; export * from './v5-trade';
export * from './v5-user';

View File

@@ -127,3 +127,10 @@ export interface WithdrawParamsV5 {
forceChain?: number; forceChain?: number;
accountType?: string; accountType?: string;
} }
export interface CreateSubMemberParamsV5 {
username: string;
memberType: 1 | 6;
switch?: 0 | 1;
note?: string;
}

View File

@@ -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;
}

View File

@@ -9,3 +9,4 @@ export * from './v5-asset';
export * from './v5-market'; export * from './v5-market';
export * from './v5-position'; export * from './v5-position';
export * from './v5-trade'; export * from './v5-trade';
export * from './v5-user';

View File

@@ -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[];
}

View File

@@ -34,6 +34,25 @@ export type TransactionTypeV5 =
| 'CURRENCY_BUY' | 'CURRENCY_BUY'
| 'CURRENCY_SELL'; | '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<T extends unknown[]> { export interface CategoryCursorListV5<T extends unknown[]> {
category: CategoryV5; category: CategoryV5;
list: T; list: T;