Skip to content

Commit

Permalink
Merge pull request #314 from ThijmenMaus/feature/subuser-methods
Browse files Browse the repository at this point in the history
feat(user): add methods to delete submember
  • Loading branch information
tiagosiebler authored Feb 13, 2024
2 parents 2498c5e + 158e582 commit bfaec5e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bybit-api",
"version": "3.9.0",
"version": "3.9.1",
"description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
45 changes: 28 additions & 17 deletions src/rest-client-v5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
CreateSubMemberParamsV5,
CreateSubMemberResultV5,
CursorListV5,
DeleteSubMemberParamsV5,
DeliveryPriceV5,
DeliveryRecordV5,
DepositAddressResultV5,
Expand Down Expand Up @@ -1251,9 +1252,8 @@ export class RestClientV5 extends BaseRestClient {
/**
* 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"
* 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"
*/
createSubMember(
params: CreateSubMemberParamsV5,
Expand All @@ -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.
*
* 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"
* 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"
*/
createSubUIDAPIKey(
params: CreateSubApiKeyParamsV5,
Expand All @@ -1286,9 +1285,8 @@ export class RestClientV5 extends BaseRestClient {
/**
* 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"
* 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"
*/
setSubUIDFrozenState(
subuid: number,
Expand All @@ -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.
*
* TIP: The API key must own one of the permissions to call the following API endpoint.
*
* Master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
* 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"
*/
updateMasterApiKey(
params: UpdateApiKeyParamsV5,
Expand All @@ -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.
*
* 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"
* 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"
*
* DANGER: BE CAREFUL! The API key used to call this interface will be invalid immediately.
*/
Expand All @@ -1348,16 +1346,29 @@ 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.
*
* TIP
* The API key must own one of permissions will be allowed to call the following API endpoint.
* sub API key: "Account Transfer"
* TIP:
* The API key must have one of the permissions to 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');
}

/**
* 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
Expand Down
15 changes: 0 additions & 15 deletions src/types/request/v5-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,3 @@ export interface WithdrawParamsV5 {
forceChain?: number;
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;
}
20 changes: 20 additions & 0 deletions src/types/request/v5-user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
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 {
subuid: number;
note?: string;
Expand All @@ -19,3 +35,7 @@ export interface UpdateSubApiKeyUpdateParamsV5 {
ips?: string[];
permissions: PermissionsV5;
}

export interface DeleteSubMemberParamsV5 {
subMemberId: string;
}
12 changes: 12 additions & 0 deletions test/v5/private.write.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
expect(await api.setSubUIDFrozenState(0, 1)).toMatchObject({
// ...successResponseObjectV3(),
Expand Down

0 comments on commit bfaec5e

Please sign in to comment.