From 987b3f81d00bafdc31c4210711b7999b2afc5292 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Fri, 9 Jun 2023 14:21:36 +0100 Subject: [PATCH] feat(): add new v5 user endpoints. add user examples. --- examples/apidoc/V5/User/README.md | 3 ++ .../apidoc/V5/User/create-sub-uid-api-key.js | 23 ++++++++++++ examples/apidoc/V5/User/create-sub-uid.js | 21 +++++++++++ .../apidoc/V5/User/delete-master-api-key.js | 16 +++++++++ examples/apidoc/V5/User/delete-sub-api-key.js | 16 +++++++++ examples/apidoc/V5/User/freeze-sub-uid.js | 16 +++++++++ .../apidoc/V5/User/get-affiliate-user-info.js | 16 +++++++++ examples/apidoc/V5/User/get-api-key-info.js | 16 +++++++++ examples/apidoc/V5/User/get-sub-uid-list.js | 16 +++++++++ .../apidoc/V5/User/modify-master-api-key.js | 29 +++++++++++++++ examples/apidoc/V5/User/modify-sub-api-key.js | 30 ++++++++++++++++ src/rest-client-v5.ts | 35 +++++++++++++++++++ src/types/v5-shared.ts | 2 ++ 13 files changed, 239 insertions(+) create mode 100644 examples/apidoc/V5/User/README.md create mode 100644 examples/apidoc/V5/User/create-sub-uid-api-key.js create mode 100644 examples/apidoc/V5/User/create-sub-uid.js create mode 100644 examples/apidoc/V5/User/delete-master-api-key.js create mode 100644 examples/apidoc/V5/User/delete-sub-api-key.js create mode 100644 examples/apidoc/V5/User/freeze-sub-uid.js create mode 100644 examples/apidoc/V5/User/get-affiliate-user-info.js create mode 100644 examples/apidoc/V5/User/get-api-key-info.js create mode 100644 examples/apidoc/V5/User/get-sub-uid-list.js create mode 100644 examples/apidoc/V5/User/modify-master-api-key.js create mode 100644 examples/apidoc/V5/User/modify-sub-api-key.js diff --git a/examples/apidoc/V5/User/README.md b/examples/apidoc/V5/User/README.md new file mode 100644 index 0000000..b962d6c --- /dev/null +++ b/examples/apidoc/V5/User/README.md @@ -0,0 +1,3 @@ +# V5 - REST - User + +https://bybit-exchange.github.io/docs/v5/user/create-subuid diff --git a/examples/apidoc/V5/User/create-sub-uid-api-key.js b/examples/apidoc/V5/User/create-sub-uid-api-key.js new file mode 100644 index 0000000..5ac4cee --- /dev/null +++ b/examples/apidoc/V5/User/create-sub-uid-api-key.js @@ -0,0 +1,23 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .createSubUIDAPIKey({ + subuid: 53888000, + note: 'testxxx', + readOnly: 0, + permissions: { + Wallet: ['AccountTransfer'], + }, + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/User/create-sub-uid.js b/examples/apidoc/V5/User/create-sub-uid.js new file mode 100644 index 0000000..16de8dc --- /dev/null +++ b/examples/apidoc/V5/User/create-sub-uid.js @@ -0,0 +1,21 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .createSubMember({ + username: 'xxxxx', + memberType: 1, + switch: 1, + note: 'test', + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/User/delete-master-api-key.js b/examples/apidoc/V5/User/delete-master-api-key.js new file mode 100644 index 0000000..f86b15a --- /dev/null +++ b/examples/apidoc/V5/User/delete-master-api-key.js @@ -0,0 +1,16 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .deleteMasterApiKey() + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/User/delete-sub-api-key.js b/examples/apidoc/V5/User/delete-sub-api-key.js new file mode 100644 index 0000000..4dba26d --- /dev/null +++ b/examples/apidoc/V5/User/delete-sub-api-key.js @@ -0,0 +1,16 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .deleteSubApiKey() + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/User/freeze-sub-uid.js b/examples/apidoc/V5/User/freeze-sub-uid.js new file mode 100644 index 0000000..14cd409 --- /dev/null +++ b/examples/apidoc/V5/User/freeze-sub-uid.js @@ -0,0 +1,16 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .setSubUIDFrozenState(53888001, 1) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/User/get-affiliate-user-info.js b/examples/apidoc/V5/User/get-affiliate-user-info.js new file mode 100644 index 0000000..4dba26d --- /dev/null +++ b/examples/apidoc/V5/User/get-affiliate-user-info.js @@ -0,0 +1,16 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .deleteSubApiKey() + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/User/get-api-key-info.js b/examples/apidoc/V5/User/get-api-key-info.js new file mode 100644 index 0000000..4c38870 --- /dev/null +++ b/examples/apidoc/V5/User/get-api-key-info.js @@ -0,0 +1,16 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .getQueryApiKey() + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/User/get-sub-uid-list.js b/examples/apidoc/V5/User/get-sub-uid-list.js new file mode 100644 index 0000000..9deb6b5 --- /dev/null +++ b/examples/apidoc/V5/User/get-sub-uid-list.js @@ -0,0 +1,16 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .getSubUIDList() + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/User/modify-master-api-key.js b/examples/apidoc/V5/User/modify-master-api-key.js new file mode 100644 index 0000000..4d61fe5 --- /dev/null +++ b/examples/apidoc/V5/User/modify-master-api-key.js @@ -0,0 +1,29 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .updateMasterApiKey({ + ips: ['*'], + permissions: { + ContractTrade: ['Order', 'Position'], + Spot: ['SpotTrade'], + Wallet: ['AccountTransfer', 'SubMemberTransfer'], + Options: ['OptionsTrade'], + Derivatives: ['DerivativesTrade'], + CopyTrading: ['CopyTrading'], + BlockTrade: [], + Exchange: ['ExchangeHistory'], + NFT: ['NFTQueryProductList'], + }, + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/User/modify-sub-api-key.js b/examples/apidoc/V5/User/modify-sub-api-key.js new file mode 100644 index 0000000..a52d2a4 --- /dev/null +++ b/examples/apidoc/V5/User/modify-sub-api-key.js @@ -0,0 +1,30 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .updateSubApiKey({ + readOnly: 0, + ips: ['*'], + permissions: { + ContractTrade: [], + Spot: ['SpotTrade'], + Wallet: ['AccountTransfer'], + Options: [], + Derivatives: [], + CopyTrading: [], + BlockTrade: [], + Exchange: [], + NFT: [], + }, + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/src/rest-client-v5.ts b/src/rest-client-v5.ts index 5a87e2a..cf905b9 100644 --- a/src/rest-client-v5.ts +++ b/src/rest-client-v5.ts @@ -1030,6 +1030,17 @@ export class RestClientV5 extends BaseRestClient { return this.get('/v5/asset/deposit/query-allowed-list', params); } + /** + * Set auto transfer account after deposit. The same function as the setting for Deposit on web GUI + */ + setDepositAccount(params: { accountType: AccountTypeV5 }): Promise< + APIResponseV3WithTime<{ + status: 0 | 1; + }> + > { + return this.postPrivate('/v5/asset/deposit/deposit-to-account', params); + } + /** * Query deposit records. * @@ -1091,6 +1102,21 @@ export class RestClientV5 extends BaseRestClient { }); } + /** + * Query the deposit address information of SUB account. + */ + getSubDepositAddress( + coin: string, + chainType: string, + subMemberId: string, + ): Promise> { + return this.getPrivate('/v5/asset/deposit/query-sub-member-address', { + coin, + chainType, + subMemberId, + }); + } + /** * Query the deposit address information of SUB account. * @@ -1130,6 +1156,15 @@ export class RestClientV5 extends BaseRestClient { return this.getPrivate('/v5/asset/withdraw/query-record', params); } + /** + * Query withdrawable amount. + */ + getWithdrawableAmount(params: { + coin: string; + }): Promise> { + return this.getPrivate('/v5/asset/withdraw/withdrawable-amount', params); + } + /** * Withdraw assets from the SPOT account. * diff --git a/src/types/v5-shared.ts b/src/types/v5-shared.ts index 53f3825..c78ff90 100644 --- a/src/types/v5-shared.ts +++ b/src/types/v5-shared.ts @@ -172,6 +172,8 @@ export interface PermissionsV5 { Wallet?: string[]; Options?: string[]; Derivatives?: string[]; + CopyTrading?: string[]; + BlockTrade?: string[]; Exchange?: string[]; NFT?: string[]; }