From 06476e6dd61a8ce426ee4eded94990bc7e6731b0 Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Wed, 17 Jul 2024 14:16:40 +0200 Subject: [PATCH 1/3] feat(): Update per release notes as of 17th July, 2024 - added convert endpoints - added examples for those endpoints - minor param/response changes based on release notes --- .gitignore | 1 + .../apidoc/V5/Asset/confirm-convert-quote.js | 18 +++++ examples/apidoc/V5/Asset/get-convert-coins.js | 16 ++++ .../apidoc/V5/Asset/get-convert-history.js | 16 ++++ .../apidoc/V5/Asset/get-convert-status.js | 19 +++++ .../apidoc/V5/Asset/request-convert-quote.js | 23 ++++++ package-lock.json | 4 +- package.json | 4 +- src/rest-client-v5.ts | 80 +++++++++++++++++++ src/types/request/v5-asset.ts | 28 +++++++ src/types/request/v5-broker.ts | 2 +- src/types/response/v5-account.ts | 4 +- src/types/response/v5-asset.ts | 70 +++++++++++++++- src/types/response/v5-broker.ts | 4 +- src/types/response/v5-market.ts | 17 ++++ src/types/v5-shared.ts | 1 + 16 files changed, 297 insertions(+), 10 deletions(-) create mode 100644 examples/apidoc/V5/Asset/confirm-convert-quote.js create mode 100644 examples/apidoc/V5/Asset/get-convert-coins.js create mode 100644 examples/apidoc/V5/Asset/get-convert-history.js create mode 100644 examples/apidoc/V5/Asset/get-convert-status.js create mode 100644 examples/apidoc/V5/Asset/request-convert-quote.js diff --git a/.gitignore b/.gitignore index c982deec..bc317efd 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,5 @@ bundleReport.html .history/ rawReq.ts localtest.sh +localtest.ts diff --git a/examples/apidoc/V5/Asset/confirm-convert-quote.js b/examples/apidoc/V5/Asset/confirm-convert-quote.js new file mode 100644 index 00000000..fb24d302 --- /dev/null +++ b/examples/apidoc/V5/Asset/confirm-convert-quote.js @@ -0,0 +1,18 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .confirmConvertQuote({ + quoteTxId: '10100108106409343501030232064', + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Asset/get-convert-coins.js b/examples/apidoc/V5/Asset/get-convert-coins.js new file mode 100644 index 00000000..f3c65a57 --- /dev/null +++ b/examples/apidoc/V5/Asset/get-convert-coins.js @@ -0,0 +1,16 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .getConvertCoins({ accountType: 'eb_convert_spot' }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Asset/get-convert-history.js b/examples/apidoc/V5/Asset/get-convert-history.js new file mode 100644 index 00000000..9b6811fe --- /dev/null +++ b/examples/apidoc/V5/Asset/get-convert-history.js @@ -0,0 +1,16 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .getConvertHistory() + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Asset/get-convert-status.js b/examples/apidoc/V5/Asset/get-convert-status.js new file mode 100644 index 00000000..7a5a7bfb --- /dev/null +++ b/examples/apidoc/V5/Asset/get-convert-status.js @@ -0,0 +1,19 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .getConvertStatus({ + quoteTxId: 'quoteTransactionId', + accountType: 'eb_convert_funding', + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Asset/request-convert-quote.js b/examples/apidoc/V5/Asset/request-convert-quote.js new file mode 100644 index 00000000..0fe1e74c --- /dev/null +++ b/examples/apidoc/V5/Asset/request-convert-quote.js @@ -0,0 +1,23 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .requestConvertQuote({ + requestId: 'test-00002', + fromCoin: 'ETH', + toCoin: 'BTC', + accountType: 'eb_convert_funding', + requestCoin: 'ETH', + requestAmount: '0.1', + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/package-lock.json b/package-lock.json index 8b545e62..ead78f03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bybit-api", - "version": "3.10.10", + "version": "3.10.11", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "bybit-api", - "version": "3.10.10", + "version": "3.10.11", "license": "MIT", "dependencies": { "axios": "^1.6.6", diff --git a/package.json b/package.json index 3c09a708..e538743e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bybit-api", - "version": "3.10.11", + "version": "3.10.12", "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", @@ -38,8 +38,8 @@ "eslint-plugin-prettier": "^5.1.3", "eslint-plugin-simple-import-sort": "^12.0.0", "jest": "^29.7.0", - "ts-node": "^10.9.2", "ts-jest": "^29.1.2", + "ts-node": "^10.9.2", "typescript": "^5.3.3" }, "optionalDependencies": { diff --git a/src/rest-client-v5.ts b/src/rest-client-v5.ts index 1082f47c..7ca5c459 100644 --- a/src/rest-client-v5.ts +++ b/src/rest-client-v5.ts @@ -35,6 +35,11 @@ import { CoinInfoV5, CollateralInfoV5, ConfirmNewRiskLimitParamsV5, + ConvertCoinSpecV5, + ConvertCoinsParamsV5, + ConvertHistoryRecordV5, + ConvertQuoteV5, + ConvertStatusV5, CreateSubApiKeyParamsV5, CreateSubApiKeyResultV5, CreateSubMemberParamsV5, @@ -64,6 +69,7 @@ import { GetClassicTransactionLogsParamsV5, GetClosedPnLParamsV5, GetCoinExchangeRecordParamsV5, + GetConvertHistoryParamsV5, GetDeliveryPriceParamsV5, GetDeliveryRecordParamsV5, GetDepositRecordParamsV5, @@ -130,6 +136,7 @@ import { RedeemSpotLeveragedTokenResultV5, RepayLiabilityParamsV5, RepayLiabilityResultV5, + RequestConvertQuoteParamsV5, RiskLimitV5, SetAutoAddMarginParamsV5, SetCollateralCoinParamsV5, @@ -563,6 +570,17 @@ export class RestClientV5 extends BaseRestClient { }); } + // TO CHECK! + /* setDisconnectCancelAllWindow( + product: 'OPTION' | 'SPOT' | 'DERIVATIVES', + timeWindow: number, + ): Promise> { + return this.postPrivate('/v5/order/disconnected-cancel-all', { + product, + timeWindow, + }); + } */ + /** * ****** Position APIs @@ -1385,6 +1403,68 @@ export class RestClientV5 extends BaseRestClient { return this.postPrivate('/v5/asset/withdraw/cancel', { id }); } + /** + * Query the coin list of convert from (to). + */ + getConvertCoins(params: ConvertCoinsParamsV5): Promise< + APIResponseV3WithTime<{ + coins: ConvertCoinSpecV5[]; + }> + > { + return this.getPrivate('/v5/asset/exchange/query-coin-list', params); + } + + /** + * Request a quote for converting coins. + */ + requestConvertQuote( + params: RequestConvertQuoteParamsV5, + ): Promise> { + return this.postPrivate('/v5/asset/exchange/quote-apply', params); + } + + /** + * Confirm a quote for converting coins. + */ + confirmConvertQuote(params: { quoteTxId: string }): Promise< + APIResponseV3WithTime<{ + quoteTxId: string; + exchangeStatus: 'init' | 'processing' | 'success' | 'failure'; + }> + > { + return this.postPrivate('/v5/asset/exchange/convert-execute', params); + } + + /** + * Query the exchange result by sending quoteTxId. + */ + getConvertStatus(params: { + quoteTxId?: string; + accountType: + | 'eb_convert_funding' + | 'eb_convert_uta' + | 'eb_convert_spot' + | 'eb_convert_contract' + | 'eb_convert_inverse'; + }): Promise< + APIResponseV3WithTime<{ + result: ConvertStatusV5; + }> + > { + return this.getPrivate('/v5/asset/exchange/convert-result-query', params); + } + + /** + * Query the conversion history. + */ + getConvertHistory(params?: GetConvertHistoryParamsV5): Promise< + APIResponseV3WithTime<{ + list: ConvertHistoryRecordV5[]; + }> + > { + return this.getPrivate('/v5/asset/exchange/query-convert-history', params); + } + /** * ****** User APIs diff --git a/src/types/request/v5-asset.ts b/src/types/request/v5-asset.ts index 9da70da0..c9a5bfae 100644 --- a/src/types/request/v5-asset.ts +++ b/src/types/request/v5-asset.ts @@ -124,3 +124,31 @@ export interface WithdrawParamsV5 { forceChain?: number; accountType?: 'SPOT' | 'FUND'; } + +export interface ConvertCoinsParamsV5 { + coin?: string; + side?: number; + accountType: + | 'eb_convert_funding' + | 'eb_convert_uta' + | 'eb_convert_spot' + | 'eb_convert_contract' + | 'eb_convert_inverse'; +} + +export interface RequestConvertQuoteParamsV5 { + fromCoin: string; + toCoin: string; + fromCoinType?: string; + toCoinType?: string; + requestCoin: string; + requestAmount: string; + accountType: 'eb_convert_funding' | 'eb_convert_uta' | 'eb_convert_spot' | 'eb_convert_contract' | 'eb_convert_inverse'; + requestId?: string; +} + +export interface GetConvertHistoryParamsV5 { + accountType?: string; + index?: number; + limit?: number; +} diff --git a/src/types/request/v5-broker.ts b/src/types/request/v5-broker.ts index adcd2b81..a815dc72 100644 --- a/src/types/request/v5-broker.ts +++ b/src/types/request/v5-broker.ts @@ -1,5 +1,5 @@ export interface GetExchangeBrokerEarningsParamsV5 { - bizType?: 'SPOT' | 'DERIVATIVES' | 'OPTIONS'; + bizType?: 'SPOT' | 'DERIVATIVES' | 'OPTIONS' | 'CONVERT'; begin?: string; end?: string; uid?: string; diff --git a/src/types/response/v5-account.ts b/src/types/response/v5-account.ts index e38e159e..002fe2b0 100644 --- a/src/types/response/v5-account.ts +++ b/src/types/response/v5-account.ts @@ -89,6 +89,8 @@ export interface FeeRateV5 { export interface AccountInfoV5 { unifiedMarginStatus: number; marginMode: AccountMarginModeV5; + isMasterTrader: boolean; + spotHedgingStatus: string; updatedTime: string; } @@ -134,5 +136,3 @@ export interface DCPInfoV5 { dcpStatus: 'ON'; timeWindow: string; } - - diff --git a/src/types/response/v5-asset.ts b/src/types/response/v5-asset.ts index fe578b48..9e580652 100644 --- a/src/types/response/v5-asset.ts +++ b/src/types/response/v5-asset.ts @@ -169,8 +169,74 @@ export interface WithdrawalRecordV5 { updateTime: string; } - export interface VaspEntityV5 { vaspEntityId: string; vaspName: string; -} \ No newline at end of file +} + +export interface ConvertCoinSpecV5 { + coin: string; + fullName: string; + icon: string; + iconNight: string; + accuracyLength: number; + coinType: string; + balance: string; + uBalance: string; + singleFromMinLimit: string; + singleFromMaxLimit: string; + disableFrom: boolean; + disableTo: boolean; + timePeriod: number; + singleToMinLimit: string; + singleToMaxLimit: string; + dailyFromMinLimit: string; + dailyFromMaxLimit: string; + dailyToMinLimit: string; + dailyToMaxLimit: string; +} + +export interface ConvertQuoteV5 { + quoteTxId: string; + exchangeRate: string; + fromCoin: string; + fromCoinType: string; + toCoin: string; + toCoinType: string; + fromAmount: string; + toAmount: string; + expiredTime: string; + requestId: string; +} + +export interface ConvertStatusV5 { + accountType: string; + exchangeTxId: string; + userId: string; + fromCoin: string; + fromCoinType: string; + toCoin: string; + toCoinType: string; + fromAmount: string; + toAmount: string; + exchangeStatus: 'init' | 'processing' | 'success' | 'failure'; + extInfo: object; + convertRate: string; + createdAt: string; +} + +export interface ConvertHistoryRecordV5 { + accountType: string; + exchangeTxId: string; + userId: string; + fromCoin: string; + fromCoinType: string; + toCoin: string; + toCoinType: string; + fromAmount: string; + toAmount: string; + exchangeStatus: 'init' | 'processing' | 'success' | 'failure'; + extInfo: object; + convertRate: string; + createdAt: string; +} diff --git a/src/types/response/v5-broker.ts b/src/types/response/v5-broker.ts index 176895cc..6464faee 100644 --- a/src/types/response/v5-broker.ts +++ b/src/types/response/v5-broker.ts @@ -1,6 +1,6 @@ interface EarningDetailV5 { userId: string; - bizType: 'SPOT' | 'DERIVATIVES' | 'OPTIONS'; + bizType: 'SPOT' | 'DERIVATIVES' | 'OPTIONS' | 'CONVERT'; symbol: string; coin: string; earning: string; @@ -20,6 +20,7 @@ export interface ExchangeBrokerEarningResultV5 { spot: TotalEarningCategoryV5[]; derivatives: TotalEarningCategoryV5[]; options: TotalEarningCategoryV5[]; + convert: TotalEarningCategoryV5[]; total: TotalEarningCategoryV5[]; }; details: EarningDetailV5[]; @@ -36,6 +37,7 @@ export interface ExchangeBrokerAccountInfoV5 { markupFeeRebateRate: { spot: string; derivatives: string; + convert: string; }; ts: string; } diff --git a/src/types/response/v5-market.ts b/src/types/response/v5-market.ts index 4a40982a..29ac3ff7 100644 --- a/src/types/response/v5-market.ts +++ b/src/types/response/v5-market.ts @@ -75,6 +75,20 @@ export interface LinearInverseInstrumentInfoV5 { copyTrading: CopyTradingV5; upperFundingRate: string; lowerFundingRate: string; + isPreListing: boolean; + preListingInfo: { + curAuctionPhase: string; + phases: { + phase: string; + startTime: string; + endTime: string; + }[]; + auctionFeeInfo: { + auctionFeeRate: string; + takerFeeRate: string; + makerFeeRate: string; + }; + } | null; } export interface OptionInstrumentInfoV5 { @@ -170,6 +184,9 @@ export interface TickerLinearInverseV5 { bid1Price: string; ask1Price: string; bid1Size: string; + preOpenPrice: string; + preQty: string; + curPreListingPhase: string; } export interface TickerOptionV5 { diff --git a/src/types/v5-shared.ts b/src/types/v5-shared.ts index cdc977d2..1cc8f95a 100644 --- a/src/types/v5-shared.ts +++ b/src/types/v5-shared.ts @@ -11,6 +11,7 @@ export type InstrumentStatusV5 = | 'Settling' | 'Delivering' | 'Closed'; + export type MarginTradingV5 = 'none' | 'both' | 'utaOnly' | 'normalSpotOnly'; From 0ed98f478d3c1e658e1a00e9a807d4bd25bbbb2f Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Wed, 17 Jul 2024 14:28:50 +0200 Subject: [PATCH 2/3] chore: DCP function update --- src/rest-client-v5.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/rest-client-v5.ts b/src/rest-client-v5.ts index 7ca5c459..52ff883c 100644 --- a/src/rest-client-v5.ts +++ b/src/rest-client-v5.ts @@ -559,6 +559,10 @@ export class RestClientV5 extends BaseRestClient { * * If you need to turn it on/off, you can contact your client manager for consultation and application. * The default time window is 10 seconds. + * + * Only for institutional clients! + * + * If it doesn't work, use v2! */ setDisconnectCancelAllWindow( category: 'option', @@ -570,8 +574,15 @@ export class RestClientV5 extends BaseRestClient { }); } - // TO CHECK! - /* setDisconnectCancelAllWindow( + /** + * This endpoint allows you to set the disconnection protect time window. Covers: option (unified account). + * + * If you need to turn it on/off, you can contact your client manager for consultation and application. + * The default time window is 10 seconds. + * + * Only for institutional clients! + */ + setDisconnectCancelAllWindowV2( product: 'OPTION' | 'SPOT' | 'DERIVATIVES', timeWindow: number, ): Promise> { @@ -579,7 +590,7 @@ export class RestClientV5 extends BaseRestClient { product, timeWindow, }); - } */ + } /** * From 351300ddcad3b6959f148725c3c13a6005ad8a08 Mon Sep 17 00:00:00 2001 From: Jerko J <83344666+JJ-Cro@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:55:44 +0200 Subject: [PATCH 3/3] chore(): Bumped version --- package-lock.json | 4 ++-- src/rest-client-v5.ts | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index ead78f03..4dbc2448 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bybit-api", - "version": "3.10.11", + "version": "3.10.12", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "bybit-api", - "version": "3.10.11", + "version": "3.10.12", "license": "MIT", "dependencies": { "axios": "^1.6.6", diff --git a/src/rest-client-v5.ts b/src/rest-client-v5.ts index 52ff883c..3140f6da 100644 --- a/src/rest-client-v5.ts +++ b/src/rest-client-v5.ts @@ -582,14 +582,11 @@ export class RestClientV5 extends BaseRestClient { * * Only for institutional clients! */ - setDisconnectCancelAllWindowV2( + setDisconnectCancelAllWindowV2(params: { product: 'OPTION' | 'SPOT' | 'DERIVATIVES', timeWindow: number, - ): Promise> { - return this.postPrivate('/v5/order/disconnected-cancel-all', { - product, - timeWindow, - }); + }): Promise> { + return this.postPrivate('/v5/order/disconnected-cancel-all', params); } /**