From 4cd58406c600c3efbcda84f0dbe3db0153897dd6 Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:34:36 +0200 Subject: [PATCH 1/3] feat(): added new endpoints --- examples/apidoc/V5/Broker/issue-voucher.js | 22 +++++++++++ .../apidoc/V5/Broker/query-issued-voucher.js | 21 +++++++++++ .../apidoc/V5/Broker/query-voucher-spec.js | 18 +++++++++ package-lock.json | 4 +- package.json | 2 +- src/rest-client-v5.ts | 37 +++++++++++++++++++ src/types/request/v5-broker.ts | 15 ++++++++ src/types/response/v5-broker.ts | 25 +++++++++++++ 8 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 examples/apidoc/V5/Broker/issue-voucher.js create mode 100644 examples/apidoc/V5/Broker/query-issued-voucher.js create mode 100644 examples/apidoc/V5/Broker/query-voucher-spec.js diff --git a/examples/apidoc/V5/Broker/issue-voucher.js b/examples/apidoc/V5/Broker/issue-voucher.js new file mode 100644 index 0000000..1140f0d --- /dev/null +++ b/examples/apidoc/V5/Broker/issue-voucher.js @@ -0,0 +1,22 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .issueBrokerVoucher({ + accountId: '2846381', + awardId: '123456', + specCode: 'award-001', + amount: '100', + brokerId: 'v-28478', + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Broker/query-issued-voucher.js b/examples/apidoc/V5/Broker/query-issued-voucher.js new file mode 100644 index 0000000..df5e1c6 --- /dev/null +++ b/examples/apidoc/V5/Broker/query-issued-voucher.js @@ -0,0 +1,21 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .getBrokerVoucherSpec({ + accountId: '5714139', + awardId: '189528', + specCode: 'demo000', + withUsedAmount: false, +}) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Broker/query-voucher-spec.js b/examples/apidoc/V5/Broker/query-voucher-spec.js new file mode 100644 index 0000000..b6e74e2 --- /dev/null +++ b/examples/apidoc/V5/Broker/query-voucher-spec.js @@ -0,0 +1,18 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .getBrokerIssuedVoucher({ + id: '80209', + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/package-lock.json b/package-lock.json index 3cc5b80..1559d69 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bybit-api", - "version": "3.10.18", + "version": "3.10.19", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "bybit-api", - "version": "3.10.18", + "version": "3.10.19", "license": "MIT", "dependencies": { "axios": "^1.6.6", diff --git a/package.json b/package.json index 7d307a0..64e244b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bybit-api", - "version": "3.10.18", + "version": "3.10.19", "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", diff --git a/src/rest-client-v5.ts b/src/rest-client-v5.ts index f722d31..53f7075 100644 --- a/src/rest-client-v5.ts +++ b/src/rest-client-v5.ts @@ -23,6 +23,8 @@ import { BatchOrderParamsV5, BatchOrdersResponseV5, BorrowHistoryRecordV5, + BrokerIssuedVoucherV5, + BrokerVoucherSpec, CancelAllOrdersParamsV5, CancelOrderParamsV5, CategoryCursorListV5, @@ -65,6 +67,7 @@ import { GetAllowedDepositCoinInfoParamsV5, GetAssetInfoParamsV5, GetBorrowHistoryParamsV5, + GetBrokerIssuedVoucherParamsV5, GetBrokerSubAccountDepositsV5, GetClassicTransactionLogsParamsV5, GetClosedPnLParamsV5, @@ -114,6 +117,7 @@ import { InsuranceResponseV5, InternalDepositRecordV5, InternalTransferRecordV5, + IssueVoucherParamsV5, LeverageTokenInfoV5, LeveragedTokenMarketResultV5, LongShortRatioV5, @@ -2167,4 +2171,37 @@ export class RestClientV5 extends BaseRestClient { params, ); } + + /** + * Query Voucher Spec + */ + getBrokerVoucherSpec(params: { + id: string; + }): Promise> { + return this.postPrivate('/v5/broker/award/info', params); + } + + /** + * Issue a voucher to a user + * + * INFO + * Use exchange broker master account to issue + */ + issueBrokerVoucher( + params: IssueVoucherParamsV5, + ): Promise> { + return this.postPrivate('/v5/broker/award/distribute-award', params); + } + + /** + * Query an issued voucher + * + * INFO + * Use exchange broker master account to query + */ + getBrokerIssuedVoucher( + params: GetBrokerIssuedVoucherParamsV5, + ): Promise> { + return this.postPrivate('/v5/broker/award/distribution-record', params); + } } diff --git a/src/types/request/v5-broker.ts b/src/types/request/v5-broker.ts index a815dc7..b604655 100644 --- a/src/types/request/v5-broker.ts +++ b/src/types/request/v5-broker.ts @@ -15,3 +15,18 @@ export interface GetBrokerSubAccountDepositsV5 { limit?: number; cursor?: string; } + +export interface IssueVoucherParamsV5 { + accountId: string; + awardId: string; + specCode: string; + amount: string; + brokerId: string; +} + +export interface GetBrokerIssuedVoucherParamsV5 { + accountId: string; + awardId: string; + specCode: string; + withUsedAmount?: boolean; +} diff --git a/src/types/response/v5-broker.ts b/src/types/response/v5-broker.ts index 6464fae..c7e8aa7 100644 --- a/src/types/response/v5-broker.ts +++ b/src/types/response/v5-broker.ts @@ -59,3 +59,28 @@ export interface ExchangeBrokerSubAccountDepositRecordV5 { batchReleaseLimit: string; depositType: string; } + +export interface BrokerVoucherSpec { + id: string; + coin: string; + amountUnit: 'AWARD_AMOUNT_UNIT_USD' | 'AWARD_AMOUNT_UNIT_COIN'; + productLine: string; + subProductLine: string; + totalAmount: { + [key: string]: string; + }; + usedAmount: string; +} + +export interface BrokerIssuedVoucherV5 { + accountId: string; + awardId: string; + specCode: string; + amount: string; + isClaimed: boolean; + startAt: string; + endAt: string; + effectiveAt: string; + ineffectiveAt: string; + usedAmount: string; +} From dedf37ceb7dffc7b33ca06826c6d41c598db92d7 Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:51:09 +0200 Subject: [PATCH 2/3] chore(): updated type name --- src/rest-client-v5.ts | 4 ++-- src/types/response/v5-broker.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rest-client-v5.ts b/src/rest-client-v5.ts index 53f7075..31605c1 100644 --- a/src/rest-client-v5.ts +++ b/src/rest-client-v5.ts @@ -24,7 +24,7 @@ import { BatchOrdersResponseV5, BorrowHistoryRecordV5, BrokerIssuedVoucherV5, - BrokerVoucherSpec, + BrokerVoucherSpecV5, CancelAllOrdersParamsV5, CancelOrderParamsV5, CategoryCursorListV5, @@ -2177,7 +2177,7 @@ export class RestClientV5 extends BaseRestClient { */ getBrokerVoucherSpec(params: { id: string; - }): Promise> { + }): Promise> { return this.postPrivate('/v5/broker/award/info', params); } diff --git a/src/types/response/v5-broker.ts b/src/types/response/v5-broker.ts index c7e8aa7..488ba4c 100644 --- a/src/types/response/v5-broker.ts +++ b/src/types/response/v5-broker.ts @@ -60,7 +60,7 @@ export interface ExchangeBrokerSubAccountDepositRecordV5 { depositType: string; } -export interface BrokerVoucherSpec { +export interface BrokerVoucherSpecV5 { id: string; coin: string; amountUnit: 'AWARD_AMOUNT_UNIT_USD' | 'AWARD_AMOUNT_UNIT_COIN'; From 7567af4a6735d51cdf81b4fc62283be11182afb9 Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:55:45 +0200 Subject: [PATCH 3/3] chore(): fixed type --- src/rest-client-v5.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rest-client-v5.ts b/src/rest-client-v5.ts index 31605c1..9a30bf4 100644 --- a/src/rest-client-v5.ts +++ b/src/rest-client-v5.ts @@ -2189,7 +2189,7 @@ export class RestClientV5 extends BaseRestClient { */ issueBrokerVoucher( params: IssueVoucherParamsV5, - ): Promise> { + ): Promise> { return this.postPrivate('/v5/broker/award/distribute-award', params); }