feat(): add preCheckOrder method with corresponding types and example usage, add txId and Id to deposit records

This commit is contained in:
JJ-Cro
2025-06-12 18:04:15 +02:00
parent fb41a3bb44
commit e302c9b94f
9 changed files with 60 additions and 3 deletions

View File

@@ -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);
});

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "4.1.10", "version": "4.1.11",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "bybit-api", "name": "bybit-api",
"version": "4.1.10", "version": "4.1.11",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^1.7.9", "axios": "^1.7.9",

View File

@@ -1,6 +1,6 @@
{ {
"name": "bybit-api", "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.", "description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@@ -176,6 +176,7 @@ import {
P2PUserPaymentV5, P2PUserPaymentV5,
PositionInfoParamsV5, PositionInfoParamsV5,
PositionV5, PositionV5,
PreCheckOrderResultV5,
PreUpgradeOptionsDelivery, PreUpgradeOptionsDelivery,
PreUpgradeTransaction, PreUpgradeTransaction,
PreUpgradeUSDCSessionSettlement, PreUpgradeUSDCSessionSettlement,
@@ -926,6 +927,20 @@ export class RestClientV5 extends BaseRestClient {
return this.postPrivate('/v5/order/disconnected-cancel-all', params); 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<APIResponseV3WithTime<PreCheckOrderResultV5>> {
return this.postPrivate('/v5/order/pre-check', params);
}
/** /**
* *
****** Position APIs ****** Position APIs

View File

@@ -87,6 +87,8 @@ export interface GetAllowedDepositCoinInfoParamsV5 {
} }
export interface GetDepositRecordParamsV5 { export interface GetDepositRecordParamsV5 {
id?: string;
txID?: string;
coin?: string; coin?: string;
startTime?: number; startTime?: number;
endTime?: number; endTime?: number;
@@ -95,6 +97,8 @@ export interface GetDepositRecordParamsV5 {
} }
export interface GetSubAccountDepositRecordParamsV5 { export interface GetSubAccountDepositRecordParamsV5 {
id?: string;
txID?: string;
subMemberId: string; subMemberId: string;
coin?: string; coin?: string;
startTime?: number; startTime?: number;

View File

@@ -8,6 +8,8 @@ export interface GetExchangeBrokerEarningsParamsV5 {
} }
export interface GetBrokerSubAccountDepositsV5 { export interface GetBrokerSubAccountDepositsV5 {
id?: string;
txID?: string;
subMemberId?: string; subMemberId?: string;
coin?: string; coin?: string;
startTime?: number; startTime?: number;

View File

@@ -103,6 +103,7 @@ export interface AllowedDepositCoinInfoV5 {
} }
export interface DepositRecordV5 { export interface DepositRecordV5 {
id: string;
coin: string; coin: string;
chain: string; chain: string;
amount: string; amount: string;
@@ -161,6 +162,7 @@ export interface CoinInfoV5 {
chainWithdraw: string; chainWithdraw: string;
withdrawPercentageFee: string; withdrawPercentageFee: string;
contractAddress: string; contractAddress: string;
safeConfirmNumber: string;
}[]; }[];
} }

View File

@@ -43,6 +43,7 @@ export interface ExchangeBrokerAccountInfoV5 {
} }
export interface ExchangeBrokerSubAccountDepositRecordV5 { export interface ExchangeBrokerSubAccountDepositRecordV5 {
id: string;
subMemberId: string; subMemberId: string;
coin: string; coin: string;
chain: string; chain: string;

View File

@@ -109,3 +109,12 @@ export interface SpotBorrowCheckResultV5 {
spotMaxTradeAmount: string; spotMaxTradeAmount: string;
borrowCoin: 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)
}