From e302c9b94f9fddf1e87aa55ae1af834621df2c71 Mon Sep 17 00:00:00 2001 From: JJ-Cro Date: Thu, 12 Jun 2025 18:04:15 +0200 Subject: [PATCH 1/2] feat(): add preCheckOrder method with corresponding types and example usage, add txId and Id to deposit records --- examples/apidoc/V5/Trade/pre-check-order.js | 24 +++++++++++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- src/rest-client-v5.ts | 15 +++++++++++++ src/types/request/v5-asset.ts | 4 ++++ src/types/request/v5-broker.ts | 2 ++ src/types/response/v5-asset.ts | 2 ++ src/types/response/v5-broker.ts | 1 + src/types/response/v5-trade.ts | 9 ++++++++ 9 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 examples/apidoc/V5/Trade/pre-check-order.js diff --git a/examples/apidoc/V5/Trade/pre-check-order.js b/examples/apidoc/V5/Trade/pre-check-order.js new file mode 100644 index 0000000..4bd1147 --- /dev/null +++ b/examples/apidoc/V5/Trade/pre-check-order.js @@ -0,0 +1,24 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +// Submit a market order +client + .preCheckOrder({ + category: 'spot', + symbol: 'BTCUSDT', + side: 'Buy', + orderType: 'Limit', + qty: '0.01', + price: '28000', + }) + .then((response) => { + console.log('Market order result', response); + }) + .catch((error) => { + console.error('Market order error', error); + }); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ded9e86..fe35dc9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bybit-api", - "version": "4.1.10", + "version": "4.1.11", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "bybit-api", - "version": "4.1.10", + "version": "4.1.11", "license": "MIT", "dependencies": { "axios": "^1.7.9", diff --git a/package.json b/package.json index e31ecf0..e2923e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bybit-api", - "version": "4.1.10", + "version": "4.1.11", "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 84503e7..7930bf6 100644 --- a/src/rest-client-v5.ts +++ b/src/rest-client-v5.ts @@ -176,6 +176,7 @@ import { P2PUserPaymentV5, PositionInfoParamsV5, PositionV5, + PreCheckOrderResultV5, PreUpgradeOptionsDelivery, PreUpgradeTransaction, PreUpgradeUSDCSessionSettlement, @@ -926,6 +927,20 @@ export class RestClientV5 extends BaseRestClient { return this.postPrivate('/v5/order/disconnected-cancel-all', params); } + /** + * Pre-check order to calculate changes in IMR and MMR before placing an order + * + * This endpoint supports orders with category = inverse, linear, option. + * Only Cross Margin mode and Portfolio Margin mode are supported, isolated margin mode is not supported. + * category = inverse is not supported in Cross Margin mode. + * Conditional order is not supported. + */ + preCheckOrder( + params: OrderParamsV5, + ): Promise> { + return this.postPrivate('/v5/order/pre-check', params); + } + /** * ****** Position APIs diff --git a/src/types/request/v5-asset.ts b/src/types/request/v5-asset.ts index 7a0475c..e561ecd 100644 --- a/src/types/request/v5-asset.ts +++ b/src/types/request/v5-asset.ts @@ -87,6 +87,8 @@ export interface GetAllowedDepositCoinInfoParamsV5 { } export interface GetDepositRecordParamsV5 { + id?: string; + txID?: string; coin?: string; startTime?: number; endTime?: number; @@ -95,6 +97,8 @@ export interface GetDepositRecordParamsV5 { } export interface GetSubAccountDepositRecordParamsV5 { + id?: string; + txID?: string; subMemberId: string; coin?: string; startTime?: number; diff --git a/src/types/request/v5-broker.ts b/src/types/request/v5-broker.ts index b604655..2ad6ead 100644 --- a/src/types/request/v5-broker.ts +++ b/src/types/request/v5-broker.ts @@ -8,6 +8,8 @@ export interface GetExchangeBrokerEarningsParamsV5 { } export interface GetBrokerSubAccountDepositsV5 { + id?: string; + txID?: string; subMemberId?: string; coin?: string; startTime?: number; diff --git a/src/types/response/v5-asset.ts b/src/types/response/v5-asset.ts index e5aa629..3d0dafc 100644 --- a/src/types/response/v5-asset.ts +++ b/src/types/response/v5-asset.ts @@ -103,6 +103,7 @@ export interface AllowedDepositCoinInfoV5 { } export interface DepositRecordV5 { + id: string; coin: string; chain: string; amount: string; @@ -161,6 +162,7 @@ export interface CoinInfoV5 { chainWithdraw: string; withdrawPercentageFee: string; contractAddress: string; + safeConfirmNumber: string; }[]; } diff --git a/src/types/response/v5-broker.ts b/src/types/response/v5-broker.ts index 488ba4c..d0480ca 100644 --- a/src/types/response/v5-broker.ts +++ b/src/types/response/v5-broker.ts @@ -43,6 +43,7 @@ export interface ExchangeBrokerAccountInfoV5 { } export interface ExchangeBrokerSubAccountDepositRecordV5 { + id: string; subMemberId: string; coin: string; chain: string; diff --git a/src/types/response/v5-trade.ts b/src/types/response/v5-trade.ts index 08c4c92..e6b04c0 100644 --- a/src/types/response/v5-trade.ts +++ b/src/types/response/v5-trade.ts @@ -109,3 +109,12 @@ export interface SpotBorrowCheckResultV5 { spotMaxTradeAmount: string; borrowCoin: string; } + +export interface PreCheckOrderResultV5 { + orderId: string; + orderLinkId: string; + preImrE4: number; // Initial margin rate before checking (in basis points) + preMmrE4: number; // Maintenance margin rate before checking (in basis points) + postImrE4: number; // Initial margin rate after checking (in basis points) + postMmrE4: number; // Maintenance margin rate after checking (in basis points) +} From e5949d1537db0ccd39850e1125b211f093429820 Mon Sep 17 00:00:00 2001 From: JJ-Cro Date: Tue, 17 Jun 2025 13:05:28 +0200 Subject: [PATCH 2/2] feat(): expand category options in batch order methods to include 'spot' and 'inverse' --- src/rest-client-v5.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rest-client-v5.ts b/src/rest-client-v5.ts index 7930bf6..0652f85 100644 --- a/src/rest-client-v5.ts +++ b/src/rest-client-v5.ts @@ -810,7 +810,7 @@ export class RestClientV5 extends BaseRestClient { * The structure of the two lists are completely consistent. */ batchSubmitOrders( - category: 'option' | 'linear', + category: 'spot' | 'option' | 'linear' | 'inverse', orders: BatchOrderParamsV5[], ): Promise< APIResponseV3WithTime< @@ -835,7 +835,7 @@ export class RestClientV5 extends BaseRestClient { * A maximum of 20 orders can be amended per request. */ batchAmendOrders( - category: 'option' | 'linear', + category: 'spot' | 'option' | 'linear' | 'inverse', orders: BatchAmendOrderParamsV5[], ): Promise< APIResponseV3WithTime< @@ -860,7 +860,7 @@ export class RestClientV5 extends BaseRestClient { * You can cancel unfilled or partially filled orders. A maximum of 20 orders can be cancelled per request. */ batchCancelOrders( - category: 'option' | 'linear', + category: 'spot' | 'option' | 'linear' | 'inverse', orders: BatchCancelOrderParamsV5[], ): Promise< APIResponseV3WithTime<