bybit-api
Version:
Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.
1,360 lines • 81.2 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RestClientV5 = void 0;
const util_1 = require("./util");
const BaseRestClient_1 = __importDefault(require("./util/BaseRestClient"));
/**
* REST API client for V5 REST APIs
*
* https://bybit-exchange.github.io/docs/v5/intro
*/
class RestClientV5 extends BaseRestClient_1.default {
/**
*
****** Custom SDK APIs
*
*/
/**
* This method is used to get the latency and time sync between the client and the server.
* This is not official API endpoint and is only used for internal testing purposes.
* Use this method to check the latency and time sync between the client and the server.
* Final values might vary slightly, but it should be within few ms difference.
* If you have any suggestions or improvements to this measurement, please create an issue or pull request on GitHub.
*/
fetchLatencySummary() {
return __awaiter(this, void 0, void 0, function* () {
const clientTimeReqStart = Date.now();
const serverTime = yield this.getServerTime();
const clientTimeReqEnd = Date.now();
const serverTimeMs = serverTime.time;
const roundTripTime = clientTimeReqEnd - clientTimeReqStart;
const estimatedOneWayLatency = Math.floor(roundTripTime / 2);
// Adjust server time by adding estimated one-way latency
const adjustedServerTime = serverTimeMs + estimatedOneWayLatency;
// Calculate time difference between adjusted server time and local time
const timeDifference = adjustedServerTime - clientTimeReqEnd;
const result = {
localTime: clientTimeReqEnd,
serverTime: serverTimeMs,
roundTripTime,
estimatedOneWayLatency,
adjustedServerTime,
timeDifference,
};
console.log('Time synchronization results:');
console.log(result);
console.log(`Your approximate latency to exchange server:
One way: ${estimatedOneWayLatency}ms.
Round trip: ${roundTripTime}ms.
`);
if (Math.abs(timeDifference) > 500) {
console.warn(`WARNING! Time difference between server and client clock is greater than 500ms. It is currently ${timeDifference}ms.
Consider adjusting your system clock to avoid unwanted clock sync errors!
Visit https://github.com/tiagosiebler/awesome-crypto-examples/wiki/Timestamp-for-this-request-is-outside-of-the-recvWindow for more information`);
}
else {
console.log(`Time difference between server and client clock is within acceptable range of 500ms. It is currently ${timeDifference}ms.`);
}
return result;
});
}
/**
*
****** Misc Bybit APIs
*
*/
getSystemStatus(params) {
return this.getPrivate('/v5/system/status', params);
}
getClientType() {
return util_1.REST_CLIENT_TYPE_ENUM.v5;
}
fetchServerTime() {
return __awaiter(this, void 0, void 0, function* () {
const res = yield this.getServerTime();
return Number(res.time) / 1000;
});
}
getServerTime() {
return this.get('/v5/market/time');
}
/**
*
****** Demo Account APIs
*
*/
requestDemoTradingFunds(params) {
return this.postPrivate('/v5/account/demo-apply-money', params);
}
/**
* Create a demo trading account.
*/
createDemoAccount() {
return this.postPrivate('/v5/user/create-demo-member');
}
/**
*
****** Spread Trading APIs
*
*/
/**
* Get Spread Instruments Info
*/
getSpreadInstrumentsInfo(params) {
return this.get('/v5/spread/instrument', params);
}
/**
* Get Spread Orderbook
*/
getSpreadOrderbook(params) {
return this.get('/v5/spread/orderbook', params);
}
/**
* Get Spread Tickers
*/
getSpreadTickers(params) {
return this.get('/v5/spread/tickers', params);
}
/**
* Get Spread Public Recent Trades
*/
getSpreadRecentTrades(params) {
return this.get('/v5/spread/recent-trade', params);
}
/**
* Create Spread Order
*/
submitSpreadOrder(params) {
return this.postPrivate('/v5/spread/order/create', params);
}
/**
* Amend Spread Order
* You can only modify unfilled or partially filled orders.
*/
amendSpreadOrder(params) {
return this.postPrivate('/v5/spread/order/amend', params);
}
/**
* Cancel Spread Order
*/
cancelSpreadOrder(params) {
return this.postPrivate('/v5/spread/order/cancel', params);
}
/**
* Cancel All Spread Orders
*
* When a symbol is specified, all orders for that symbol will be canceled regardless of the cancelAll field.
* When symbol is not specified and cancelAll=true, all orders, regardless of the symbol, will be canceled.
*/
cancelAllSpreadOrders(params) {
return this.postPrivate('/v5/spread/order/cancel-all', params);
}
/**
* Get Spread Open Orders
* Query unfilled or partially filled orders in real-time.
*/
getSpreadOpenOrders(params) {
return this.getPrivate('/v5/spread/order/realtime', params);
}
/**
* Get Spread Order History
*
* Note:
* - orderId & orderLinkId has a higher priority than startTime & endTime
* - Fully canceled orders are stored for up to 24 hours
* - Single leg orders can also be found with "createType"=CreateByFutureSpread via Get Order History
*/
getSpreadOrderHistory(params) {
return this.getPrivate('/v5/spread/order/history', params);
}
/**
* Get Spread Trade History
*
* Note:
* - In self-trade cases, both the maker and taker single-leg trades will be returned in the same request
* - Single leg executions can also be found with "execType"=FutureSpread via Get Trade History
*/
getSpreadTradeHistory(params) {
return this.getPrivate('/v5/spread/execution/list', params);
}
/**
*
****** Market APIs
*
*/
/**
* Query the kline data. Charts are returned in groups based on the requested interval.
*
* Covers: Spot / Linear contract / Inverse contract
*/
getKline(params) {
return this.get('/v5/market/kline', params);
}
/**
* Query the mark price kline data. Charts are returned in groups based on the requested interval.
*
* Covers: Linear contract / Inverse contract
*/
getMarkPriceKline(params) {
return this.get('/v5/market/mark-price-kline', params);
}
/**
* Query the index price kline data. Charts are returned in groups based on the requested interval.
*
* Covers: Linear contract / Inverse contract
*/
getIndexPriceKline(params) {
return this.get('/v5/market/index-price-kline', params);
}
/**
* Retrieve the premium index price kline data. Charts are returned in groups based on the requested interval.
*
* Covers: Linear contract
*/
getPremiumIndexPriceKline(params) {
return this.get('/v5/market/premium-index-price-kline', params);
}
/**
* Query a list of instruments of online trading pair.
*
* Covers: Spot / Linear contract / Inverse contract / Option
*
* Note: Spot does not support pagination, so limit & cursor are invalid.
*/
getInstrumentsInfo(params) {
return this.get('/v5/market/instruments-info', params);
}
/**
* Query orderbook data
*
* Covers: Spot / Linear contract / Inverse contract / Option
*/
getOrderbook(params) {
return this.get('/v5/market/orderbook', params);
}
/**
* Get RPI Orderbook
* Query for orderbook depth data with RPI (Retail Price Improvement) information.
*
* Covers: Spot / USDT contract / USDC contract / Inverse contract
* Contract: 50-level of RPI orderbook data
* Spot: 50-level of RPI orderbook data
*/
getRPIOrderbook(params) {
return this.get('/v5/market/rpi_orderbook', params);
}
/**
* Query the latest price snapshot, best bid/ask price, and trading volume in the last 24 hours.
*
* Covers: Spot / Linear contract / Inverse contract / Option
*/
getTickers(params) {
return this.get('/v5/market/tickers', params);
}
/**
* Query historical funding rate. Each symbol has a different funding interval.
*
* Covers: Linear contract / Inverse perpetual
*/
getFundingRateHistory(params) {
return this.get('/v5/market/funding/history', params);
}
/**
* Query recent public trading data in Bybit.
*
* Covers: Spot / Linear contract / Inverse contract / Option
*/
getPublicTradingHistory(params) {
return this.get('/v5/market/recent-trade', params);
}
/**
* Get open interest of each symbol.
*
* Covers: Linear contract / Inverse contract
*/
getOpenInterest(params) {
return this.get('/v5/market/open-interest', params);
}
/**
* Query option historical volatility
* Covers: Option
*/
getHistoricalVolatility(params) {
return this.get('/v5/market/historical-volatility', params);
}
/**
* Query Bybit insurance pool data (BTC/USDT/USDC etc). The data is updated every 24 hours.
*/
getInsurance(params) {
return this.get('/v5/market/insurance', params);
}
/**
* Query risk limit of futures
*
* Covers: Linear contract / Inverse contract
*/
getRiskLimit(params) {
return this.get('/v5/market/risk-limit', params);
}
/**
* Get the delivery price for option
*
* Covers: Option
*
* @deprecated use getDeliveryPrice() instead
*/
getOptionDeliveryPrice(params) {
return this.get('/v5/market/delivery-price', params);
}
/**
* Get the delivery price of Inverse futures, USDC futures and Options
*
* Covers: USDC futures / Inverse futures / Option
*/
getDeliveryPrice(params) {
return this.get('/v5/market/delivery-price', params);
}
/**
* Get New Delivery Price
* Get historical option delivery prices.
*
* Covers: Option
*
* INFO
* - It is recommended to query this endpoint 1 minute after settlement is completed, because the data returned by this endpoint may be delayed by 1 minute.
* - By default, the most recent 50 records are returned in reverse order of "deliveryTime".
*/
getNewDeliveryPrice(params) {
return this.get('/v5/market/new-delivery-price', params);
}
getLongShortRatio(params) {
return this.get('/v5/market/account-ratio', params);
}
/**
* Get Index Price Components
* Query for index price components that contribute to the calculation of an index price.
*/
getIndexPriceComponents(params) {
return this.get('/v5/market/index-price-components', params);
}
getOrderPriceLimit(params) {
return this.get('/v5/market/price-limit', params);
}
/**
* Get ADL Alert
* Query for ADL (auto-deleveraging mechanism) alerts and insurance pool information.
*
* Covers: USDT Perpetual / USDT Delivery / USDC Perpetual / USDC Delivery / Inverse Contracts
* Data update frequency: every 1 minute
*/
getADLAlert(params) {
return this.get('/v5/market/adlAlert', params);
}
/**
* Get Fee Group Structure
* Query for the group fee structure and fee rates.
*
* The new grouped fee structure only applies to Pro-level and Market Maker clients.
* Covers: USDT Perpetual / USDT Delivery / USDC Perpetual / USDC Delivery / Inverse Contracts
*/
getFeeGroupStructure(params) {
return this.get('/v5/market/fee-group-info', params);
}
/**
*
****** Trade APIs
*
*/
submitOrder(params) {
return this.postPrivate('/v5/order/create', params);
}
amendOrder(params) {
return this.postPrivate('/v5/order/amend', params);
}
cancelOrder(params) {
return this.postPrivate('/v5/order/cancel', params);
}
/**
* Query unfilled or partially filled orders in real-time. To query older order records, please use the order history interface.
*/
getActiveOrders(params) {
return this.getPrivate('/v5/order/realtime', params);
}
cancelAllOrders(params) {
return this.postPrivate('/v5/order/cancel-all', params);
}
/**
* Query order history. As order creation/cancellation is asynchronous, the data returned from this endpoint may delay.
*
* If you want to get real-time order information, you could query this endpoint or rely on the websocket stream (recommended).
*/
getHistoricOrders(params) {
return this.getPrivate('/v5/order/history', params);
}
/**
* Query users' execution records, sorted by execTime in descending order
*
* Unified account covers: Spot / Linear contract / Options
* Normal account covers: USDT perpetual / Inverse perpetual / Inverse futures
*/
getExecutionList(params) {
return this.getPrivate('/v5/execution/list', params);
}
/**
* This endpoint allows you to place more than one order in a single request.
* Covers: Option (UTA, UTA Pro) / USDT Perpetual, UDSC Perpetual, USDC Futures (UTA Pro)
*
* Make sure you have sufficient funds in your account when placing an order.
* Once an order is placed, according to the funds required by the order,
* the funds in your account will be frozen by the corresponding amount during the life cycle of the order.
*
* A maximum of 20 orders can be placed per request. The returned data list is divided into two lists.
* The first list indicates whether or not the order creation was successful and the second list details the created order information.
* The structure of the two lists are completely consistent.
*/
batchSubmitOrders(category, orders) {
return this.postPrivate('/v5/order/create-batch', {
category,
request: orders,
});
}
/**
* This endpoint allows you to amend more than one open order in a single request.
* Covers: Option (UTA, UTA Pro) / USDT Perpetual, UDSC Perpetual, USDC Futures (UTA Pro)
*
* You can modify unfilled or partially filled orders. Conditional orders are not supported.
*
* A maximum of 20 orders can be amended per request.
*/
batchAmendOrders(category, orders) {
return this.postPrivate('/v5/order/amend-batch', {
category,
request: orders,
});
}
/**
* This endpoint allows you to cancel more than one open order in a single request.
* Covers: Option (UTA, UTA Pro) / USDT Perpetual, UDSC Perpetual, USDC Futures (UTA Pro)
*
* You must specify orderId or orderLinkId. If orderId and orderLinkId is not matched, the system will process orderId first.
*
* You can cancel unfilled or partially filled orders. A maximum of 20 orders can be cancelled per request.
*/
batchCancelOrders(category, orders) {
return this.postPrivate('/v5/order/cancel-batch', {
category,
request: orders,
});
}
/**
* Query the qty and amount of borrowable coins in spot account.
*
* Covers: Spot (Unified Account)
*/
getSpotBorrowCheck(symbol, side) {
return this.getPrivate('/v5/order/spot-borrow-check', {
category: 'spot',
symbol,
side,
});
}
/**
* 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!
*
* If it doesn't work, use v2!
*/
setDisconnectCancelAllWindow(category, timeWindow) {
return this.postPrivate('/v5/order/disconnected-cancel-all', {
category,
timeWindow,
});
}
/**
* 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(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) {
return this.postPrivate('/v5/order/pre-check', params);
}
/**
*
****** Position APIs
*
*/
/**
* Query real-time position data, such as position size, cumulative realizedPNL.
*
* 0: cross margin. 1: isolated margin
*
* Unified account covers: Linear contract / Options
*
* Normal account covers: USDT perpetual / Inverse perpetual / Inverse futures
*
* Note: this will give a 404 error if you query the `option` category if your account is not unified
*/
getPositionInfo(params) {
return this.getPrivate('/v5/position/list', params);
}
/**
* Set the leverage
*
* Unified account covers: Linear contract
*
* Normal account covers: USDT perpetual / Inverse perpetual / Inverse futures
*
* Note: Under one-way mode, buyLeverage must be the same as sellLeverage
*/
setLeverage(params) {
return this.postPrivate('/v5/position/set-leverage', params);
}
/**
* Select cross margin mode or isolated margin mode.
* 0: cross margin. 1: isolated margin
*
* Covers: USDT perpetual (Normal account) / Inverse contract (Normal account).
*
* Switching margin modes will cause orders in progress to be cancelled.
* Please make sure that there are no open orders before you switch margin modes.
*/
switchIsolatedMargin(params) {
return this.postPrivate('/v5/position/switch-isolated', params);
}
/**
* @deprecated
* This endpoint sets the take profit/stop loss (TP/SL) mode to full or partial.
*
* Unified account covers: Linear contract; normal account covers: USDT perpetual, inverse perpetual, inverse futures.
*
* For partial TP/SL mode, you can set the TP/SL size smaller than position size.
*/
setTPSLMode(params) {
return this.postPrivate('/v5/position/set-tpsl-mode', params);
}
/**
* Switches the position mode for USDT perpetual and Inverse futures.
*
* If you are in one-way Mode, you can only open one position on Buy or Sell side.
*
* If you are in hedge mode, you can open both Buy and Sell side positions simultaneously.
*
* Position mode. 0: Merged Single. 3: Both Sides.
*/
switchPositionMode(params) {
return this.postPrivate('/v5/position/switch-mode', params);
}
/**
* @deprecated
* The risk limit will limit the maximum position value you can hold under different margin requirements.
* If you want to hold a bigger position size, you need more margin.
*
* This interface can set the risk limit of a single position.
* If the order exceeds the current risk limit when placing an order, it will be rejected.
*/
setRiskLimit(params) {
return this.postPrivate('/v5/position/set-risk-limit', params);
}
/**
* This endpoint allows you to set the take profit, stop loss or trailing stop for a position.
* Passing these parameters will create conditional orders by the system internally.
*
* The system will cancel these orders if the position is closed, and adjust the qty according to the size of the open position.
*
* Unified account covers: Linear contract.
* Normal account covers: USDT perpetual / Inverse perpetual / Inverse futures.
*/
setTradingStop(params) {
return this.postPrivate('/v5/position/trading-stop', params);
}
/**
* This endpoint allows you to turn on/off auto-add-margin for an isolated margin position.
*
* Covers: USDT perpetual (Normal Account).
*/
setAutoAddMargin(params) {
return this.postPrivate('/v5/position/set-auto-add-margin', params);
}
/**
* Manually add or reduce margin for isolated margin position
*
* Unified account covers: USDT perpetual / USDC perpetual / USDC futures / Inverse contract
* Normal account covers: USDT perpetual / Inverse contract
*/
addOrReduceMargin(params) {
return this.postPrivate('/v5/position/add-margin', params);
}
/**
* Query user's closed profit and loss records. The results are sorted by createdTime in descending order.
*
* Unified account covers: Linear contract
* Normal account covers: USDT perpetual / Inverse perpetual / Inverse futures
*/
getClosedPnL(params) {
return this.getPrivate('/v5/position/closed-pnl', params);
}
/**
* Get Closed Options Positions
* Query user's closed options positions, sorted by closeTime in descending order
*
* INFO
* Only supports users to query closed options positions in recently 6 months
* Fee and price retain 8 decimal places and do not omit the last 0
*/
getClosedOptionsPositions(params) {
return this.getPrivate('/v5/position/get-closed-positions', params);
}
/**
* Move positions between sub-master, master-sub, or sub-sub UIDs.
*
* Unified account covers: USDT perpetual / USDC contract / Spot / Option
*
* INFO
* The endpoint can only be called by master UID api key
* UIDs must be the same master-sub account relationship
* The trades generated from move-position endpoint will not be displayed in the Recent Trade (Rest API & Websocket)
* There is no trading fee
* fromUid and toUid both should be Unified trading accounts, and they need to be one-way mode when moving the positions
* Please note that once executed, you will get execType=MovePosition entry from Get Trade History, Get Closed Pnl, and stream from Execution.
*/
movePosition(params) {
return this.postPrivate('/v5/position/move-positions', params);
}
/**
* Query moved position data by master UID api key.
*
* Unified account covers: USDT perpetual / USDC contract / Spot / Option
*/
getMovePositionHistory(params) {
return this.getPrivate('/v5/position/move-history', params);
}
/**
* Confirm new risk limit.
*
* It is only applicable when the user is marked as only reducing positions (please see the isReduceOnly field in the Get Position Info interface).
* After the user actively adjusts the risk level, this interface is called to try to calculate the adjusted risk level, and if it passes (retCode=0),
* the system will remove the position reduceOnly mark. You are recommended to call Get Position Info to check isReduceOnly field.
*
* Unified account covers: USDT perpetual / USDC contract / Inverse contract
* Classic account covers: USDT perpetual / Inverse contract
*/
confirmNewRiskLimit(params) {
return this.postPrivate('/v5/position/confirm-pending-mmr', params);
}
/**
*
****** Pre-upgrade APIs
*
*/
/**
* Get those orders which occurred before you upgrade the account to Unified account.
*
* For now, it only supports to query USDT perpetual, USDC perpetual, Inverse perpetual and futures.
*
* - can get all status in 7 days
* - can only get filled orders beyond 7 days
*/
getPreUpgradeOrderHistory(params) {
return this.getPrivate('/v5/pre-upgrade/order/history', params);
}
/**
* Get users' execution records which occurred before you upgrade the account to Unified account, sorted by execTime in descending order
*
* For now, it only supports to query USDT perpetual, Inverse perpetual and futures.
*
* - You may have multiple executions in a single order.
* - You can query by symbol, baseCoin, orderId and orderLinkId, and if you pass multiple params,
* the system will process them according to this priority: orderId > orderLinkId > symbol > baseCoin.
*/
getPreUpgradeTradeHistory(params) {
return this.getPrivate('/v5/pre-upgrade/execution/list', params);
}
/**
* Query user's closed profit and loss records. The results are sorted by createdTime in descending order.
*
* For now, it only supports to query USDT perpetual, Inverse perpetual and futures.
*/
getPreUpgradeClosedPnl(params) {
return this.getPrivate('/v5/pre-upgrade/position/closed-pnl', params);
}
/**
* Query transaction logs which occurred in the USDC Derivatives wallet before the account was upgraded to a Unified account.
*
* You can get USDC Perpetual, Option records.
*
* INFO
* USDC Perpeual & Option support the recent 6 months data. Please download older data via GUI
*/
getPreUpgradeTransactions(params) {
return this.getPrivate('/v5/pre-upgrade/account/transaction-log', params);
}
/**
* Query delivery records of Option before you upgraded the account to a Unified account, sorted by deliveryTime in descending order.
*
* INFO
* Supports the recent 6 months data. Please download older data via GUI
*/
getPreUpgradeOptionDeliveryRecord(params) {
return this.getPrivate('/v5/pre-upgrade/asset/delivery-record', params);
}
/**
* Query session settlement records of USDC perpetual before you upgrade the account to Unified account.
*
* INFO
* USDC Perpetual support the recent 6 months data. Please download older data via GUI
*/
getPreUpgradeUSDCSessionSettlements(params) {
return this.getPrivate('/v5/pre-upgrade/asset/settlement-record', params);
}
/**
*
****** Account APIs
*
*/
/**
* Obtain wallet balance, query asset information of each currency, and account risk rate information under unified margin mode.
*
* By default, currency information with assets or liabilities of 0 is not returned.
*/
getWalletBalance(params) {
return this.getPrivate('/v5/account/wallet-balance', params);
}
/**
* Query the available amount to transfer of a specific coin in the Unified wallet.
*
* @param coinName Coin name, uppercase only
*/
getTransferableAmount(params) {
return this.getPrivate('/v5/account/withdrawal', params);
}
/**
* Get Account Instruments Info
* Query for the instrument specification of online trading pairs that available to users.
*
* Covers: SPOT / USDT contract / USDC contract / Inverse contract
*
* Includes RPI permission information (isPublicRpi, myRpiPermission)
*/
getAccountInstrumentsInfo(params) {
return this.getPrivate('/v5/account/instruments-info', params);
}
/**
* Upgrade to unified account.
*
* Banned/OTC loan/Net asset unsatisfying/Express path users cannot upgrade the account to Unified Account for now.
*/
upgradeToUnifiedAccount() {
return this.postPrivate('/v5/account/upgrade-to-uta');
}
/**
* Get interest records, sorted in reverse order of creation time.
*
* Unified account
*/
getBorrowHistory(params) {
return this.getPrivate('/v5/account/borrow-history', params);
}
/**
* You can manually repay the liabilities of Unified account
* Applicable: Unified Account
* Permission: USDC Contracts
*
* - Input the specific coin: repay the liability of this coin in particular
* - No coin specified: repay the liability of all coins
*/
repayLiability(params) {
return this.postPrivate('/v5/account/quick-repayment', params);
}
/**
* Manual Repay
*
* If neither coin nor amount is passed, then repay all the liabilities.
* If coin is passed and amount is not, the coin will be repaid in full.
*
* When repaying, the system will first use the spot available balance of the debt currency.
* If that's not enough, the remaining amount will be repaid by converting other assets.
*
* Repayment is prohibited between 04:00 and 05:30 per hour.
*/
manualRepay(params) {
return this.postPrivate('/v5/account/repay', params);
}
/**
* You can decide whether the assets in the Unified account needs to be collateral coins.
*/
setCollateralCoin(params) {
return this.postPrivate('/v5/account/set-collateral-switch', params);
}
batchSetCollateralCoin(params) {
return this.postPrivate('/v5/account/set-collateral-switch-batch', params);
}
/**
* Get the collateral information of the current unified margin account, including loan interest rate,
* loanable amount, collateral conversion rate, whether it can be mortgaged as margin, etc.
*/
getCollateralInfo(currency) {
return this.getPrivate('/v5/account/collateral-info', { currency });
}
/**
* Get current account Greeks information
*/
getCoinGreeks(baseCoin) {
return this.getPrivate('/v5/asset/coin-greeks', baseCoin ? { baseCoin } : undefined);
}
/**
* Get the trading fee rate.
* Covers: Spot / USDT perpetual / Inverse perpetual / Inverse futures / Options
*/
getFeeRate(params) {
return this.getPrivate('/v5/account/fee-rate', params);
}
/**
* Query the margin mode and the upgraded status of account
*/
getAccountInfo() {
return this.getPrivate('/v5/account/info');
}
/**
* Query the DCP configuration of the account's contracts (USDT perpetual, USDC perpetual and USDC Futures) / spot / options.
*
* Only the configured main / sub account can query information from this API. Calling this API by an account always returns empty.
*
* INFO
* support linear contract (USDT, USDC Perp & USDC Futures) / Spot / Options only
* Unified account only
*/
getDCPInfo() {
return this.getPrivate('/v5/account/query-dcp-info');
}
/**
* Query transaction logs in Unified account.
*/
getTransactionLog(params) {
return this.getPrivate('/v5/account/transaction-log', params);
}
/**
* Query transaction logs in the derivatives wallet (classic account), and inverse derivatives wallet (upgraded to UTA).
*
* API key permission: "Contract - Position"
*/
getClassicTransactionLogs(params) {
return this.getPrivate('/v5/account/contract-transaction-log', params);
}
/**
* Query the SMP group ID of self match prevention.
*/
getSMPGroup() {
return this.getPrivate('/v5/account/smp-group');
}
/**
* Default is regular margin mode.
*
* This mode is valid for USDT Perp, USDC Perp and USDC Option.
*/
setMarginMode(marginMode) {
return this.postPrivate('/v5/account/set-margin-mode', {
setMarginMode: marginMode,
});
}
/**
* Turn on/off Spot hedging feature in Portfolio margin for Unified account.
*
* INFO
* Only unified account is applicable
* Only portfolio margin mode is applicable
*/
setSpotHedging(params) {
return this.postPrivate('/v5/account/set-hedging-mode', params);
}
/**
* Set Limit Price Behaviour
* You can configure how the system behaves when your limit order price exceeds the highest bid or lowest ask price.
*
* Spot: If the order price exceeds the boundary, the system rejects the request.
* Futures: If the order price exceeds the boundary, the system will automatically adjust the price to the nearest allowed boundary.
*/
setLimitPriceAction(params) {
return this.postPrivate('/v5/account/set-limit-px-action', params);
}
/**
* Get Limit Price Behaviour
* You can get configuration how the system behaves when your limit order price exceeds the highest bid or lowest ask price.
*/
getLimitPriceAction() {
return this.getPrivate('/v5/account/user-setting-config');
}
/**
* Configure Market Maker Protection (MMP)
*/
setMMP(params) {
return this.postPrivate('/v5/account/mmp-modify', params);
}
/**
* Once the mmp triggered, you can unfreeze the account via this endpoint
*/
resetMMP(baseCoin) {
return this.postPrivate('/v5/account/mmp-reset', { baseCoin });
}
/**
* Get MMP State
*/
getMMPState(baseCoin) {
return this.getPrivate('/v5/account/mmp-state', { baseCoin });
}
/**
*
****** Asset APIs
*
*/
/**
* Query option delivery records, sorted by deliveryTime in descending order.
*
* Covers: Option
*/
getDeliveryRecord(params) {
return this.getPrivate('/v5/asset/delivery-record', params);
}
/**
* Query session settlement records of USDC perpetual
*
* Covers: Linear contract (USDC Perpetual only, Unified Account)
*/
getSettlementRecords(params) {
return this.getPrivate('/v5/asset/settlement-record', params);
}
/**
* Query the coin exchange records.
*
* CAUTION: You may experience long delays with this endpoint.
*/
getCoinExchangeRecords(params) {
return this.getPrivate('/v5/asset/exchange/order-record', params);
}
/**
* Query coin information, including chain information, withdraw and deposit status.
*/
getCoinInfo(coin) {
return this.getPrivate('/v5/asset/coin/query-info', coin ? { coin } : undefined);
}
/**
* Query the sub UIDs under a main UID
*
* CAUTION: Can query by the master UID's api key only
*/
getSubUID() {
return this.getPrivate('/v5/asset/transfer/query-sub-member-list');
}
/**
* Query asset information.
*
* INFO
* For now, it can query SPOT only.
*/
getAssetInfo(params) {
return this.getPrivate('/v5/asset/transfer/query-asset-info', params);
}
/**
* Query all coin balances of all account types under the master account and sub accounts.
*
* It is not allowed to get the master account coin balance via sub account API key.
*/
getAllCoinsBalance(params) {
return this.getPrivate('/v5/asset/transfer/query-account-coins-balance', params);
}
/**
* Query the balance of a specific coin in a specific account type. Supports querying sub UID's balance.
*
* CAUTION: Can query by the master UID's api key only.
*/
getCoinBalance(params) {
return this.getPrivate('/v5/asset/transfer/query-account-coin-balance', params);
}
/**
* Query withdrawable amount.
*/
getWithdrawableAmount(params) {
return this.getPrivate('/v5/asset/withdraw/withdrawable-amount', params);
}
/**
* Query the transferable coin list between each account type.
*/
getTransferableCoinList(fromAccountType, toAccountType) {
return this.getPrivate('/v5/asset/transfer/query-transfer-coin-list', {
fromAccountType,
toAccountType,
});
}
/**
* Create the internal transfer between different account types under the same UID.
* Each account type has its own acceptable coins, e.g, you cannot transfer USDC from SPOT to CONTRACT.
*
* Please refer to the getTransferableCoinList() API to find out more.
*/
createInternalTransfer(transferId, coin, amount, fromAccountType, toAccountType) {
return this.postPrivate('/v5/asset/transfer/inter-transfer', {
transferId,
coin,
amount,
fromAccountType,
toAccountType,
});
}
/**
* Query the internal transfer records between different account types under the same UID.
*/
getInternalTransferRecords(params) {
return this.getPrivate('/v5/asset/transfer/query-inter-transfer-list', params);
}
/**
* Enable Universal Transfer for Sub UID
*
* Use this endpoint to enable a subaccount to take part in a universal transfer.
* It is a one-time switch which, once thrown, enables a subaccount permanently.
* If not set, your subaccount cannot use universal transfers.
*
* @deprecated - You no longer need to configure transferable sub UIDs.
* Now, all sub UIDs are automatically enabled for universal transfer.
*
*/
enableUniversalTransferForSubUIDs(subMemberIds) {
return this.postPrivate('/v5/asset/transfer/save-transfer-sub-member', {
subMemberIds,
});
}
/**
* Transfer between sub-sub or main-sub. Please make sure you have enabled universal transfer on your sub UID in advance.
*/
createUniversalTransfer(params) {
return this.postPrivate('/v5/asset/transfer/universal-transfer', params);
}
/**
* Query universal transfer records
*
* CAUTION
* Can query by the master UID's API key only
*/
getUniversalTransferRecords(params) {
return this.getPrivate('/v5/asset/transfer/query-universal-transfer-list', params);
}
/**
* Query allowed deposit coin information.
* To find out paired chain of coin, please refer to the coin info api.
*/
getAllowedDepositCoinInfo(params) {
return this.getPrivate('/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) {
return this.postPrivate('/v5/asset/deposit/deposit-to-account', params);
}
/**
* Query deposit records.
*
* TIP
* endTime - startTime should be less than 30 days. Query last 30 days records by default.
*
* Can use main or sub UID api key to query deposit records respectively.
*/
getDepositRecords(params) {
return this.getPrivate('/v5/asset/deposit/query-record', params);
}
/**
* Query subaccount's deposit records by MAIN UID's API key.
*
* TIP: Query deposit records of SPOT only
* endTime - startTime should be less than 30 days.
* Queries for the last 30 days worth of records by default.
*/
getSubAccountDepositRecords(params) {
return this.getPrivate('/v5/asset/deposit/query-sub-member-record', params);
}
/**
* Get Internal Deposit Records (across Bybit)
* Query deposit records through Bybit platform
*
* RULES
* The maximum difference between the start time and the end time is 30 days.
* Support to get deposit records by Master or Sub Member Api Key
*/
getInternalDepositRecords(params) {
return this.getPrivate('/v5/asset/deposit/query-internal-record', params);
}
/**
* Query the deposit address information of MASTER account.
*/
getMasterDepositAddress(coin, chainType) {
return this.getPrivate('/v5/asset/deposit/query-address', {
coin,
chainType,
});
}
/**
* Query the deposit address information of SUB account.
*/
getSubDepositAddress(coin, chainType, subMemberId) {
return this.getPrivate('/v5/asset/deposit/query-sub-member-address', {
coin,
chainType,
subMemberId,
});
}
/**
* @deprecated - duplicate function, use getSubDepositAddress() instead
* Query the deposit address information of SUB account.
* @deprecated Duplicate endpoint - Use getSubDepositAddress() instead
*
* CAUTION
* Can use master UID's api key only
*/
querySubMemberAddress(coin, chainType, subMemberId) {
return this.getPrivate('/v5/asset/deposit/query-sub-member-address', {
coin,
chainType,
subMemberId,
});
}
/**
* Query withdrawal records.
*/
getWithdrawalRecords(params) {
return this.getPrivate('/v5/asset/withdraw/query-record', params);
}
/**
* Get Withdrawal Address List
* Query the withdrawal addresses in the address book.
*
* TIP: The API key for querying this endpoint must have withdrawal permissions.
*/
getWithdrawalAddressList(params) {
return this.getPrivate('/v5/asset/withdraw/query-address', params);
}
/**
* Get Exchange Entity List.
*
* This endpoint is particularly used for kyc=KOR users. When withdraw funds, you need to fill entity id.
*/
getExchangeEntities() {
return this.getPrivate('/v5/asset/withdraw/vasp/list');
}
/**
* Withdraw assets from the SPOT account.
*
* CAUTION: Make sure you have whitelisted your wallet address before calling this endpoint.
*
* You can make an off-chain transfer if the target wallet address is from Bybit. This means that no blockchain fee will be charged.
*/
submitWithdrawal(params) {
return this.postPrivate('/v5/asset/withdraw/create', params);
}
/**
* Cancel the withdrawal
*
* CAUTION: Can query by the master UID's api key only
*/
cancelWithdrawal(id) {
return this.postPrivate('/v5/asset/withdraw/cancel', { id });
}
/**
* Query the coin list of convert from (to).
*/
getConvertCoins(params) {
return this.getPrivate('/v5/asset/exchange/query-coin-list', params);
}
/**
* Request a quote for converting coins.
*/
requestConvertQuote(params) {
return this.postPrivate('/v5/asset/exchange/quote-apply', params);
}
/**
* Confirm a quote for converting coins.
*/
confirmConvertQuote(params) {
return this.postPrivate('/v5/asset/exchange/convert-execute', params);
}
/**
* Query the exchange result by sending quoteTxId.
*/
getConvertStatus(params) {
return this.getPrivate('/v5/asset/exchange/convert-result-query', params);
}
/**
* Query the conversion history.
*/
getConvertHistory(params) {
return this.getPrivate('/v5/asset/exchange/query-convert-history', params);
}
/**
*
****** User APIs
*
*/
/**
* Create a new sub user id. Use master user's api key only.
*
* The API key must have one of the permissions to be allowed to call the following API endpoint.
* - master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
*/
createSubMember(params) {
return this.postPrivate('/v5/user/create-sub-member', params);
}
/**
* To create new API key for those newly created sub UID. Use master user's api key only.
*
* TIP: The API key must have one of the permissions to be allowed to call the following API endpoint.
* - master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
*/
createSubUIDAPIKey(params) {
return this.postPrivate('/v5/user/create-sub-api', params);
}
/**
* This endpoint allows you to get a list of all sub UID of master account. At most 10k subaccounts.
*/
getSubUIDList() {
return this.getPrivate('/v5/user/query-sub-members');
}
/**
* This endpoint allows you to get a list of all sub UID of master account. No limit on the number of subaccounts.
*/
getSubUIDListUnlimited(params) {
return this.getPrivate('/v5/user/submembers', params);
}
/**
* Froze sub uid. Use master user's api key only.
*
* TIP: The API key must have one of the permissions to be allowed to call the following API endpoint.
* - master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
*/
setSubUIDFrozenState(subuid, frozen) {
return this.postPrivate('/v5/user/frozen-sub-member', { subuid, frozen });
}
/**
* Get the information of the api key. Use the api key pending to be checked to call the endpoint.
* Both master and sub user's api key are applicable.
*
* TIP: Any permission can access this endpoint.
*/
getQueryApiKey() {
return this.getPrivate('/v5/user/query-api');
}
/**
* Query all api keys information of a sub UID.
*/
getSubAccountAllApiKeys(params) {
return this.getPrivate('/v5/user/sub-apikeys', params);
}
getUIDWalletType(params) {
return this.getPrivate('/v5/user/get-member-type', params);
}
/**
* Modify the settings of a master API key. Use the API key pending to be modified to call the endpoint. Use master user's API key only.
*
* TIP: The API key must have one of the permissions to be allowed to call the following API endpoint.
* - master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
*/
updateMasterApiKey(params) {
return this.postPrivate('/v5/user/update-api', params);
}
/**
* This endpoint modifies the settings of a sub API key.
* Use the API key pending to be modified to call the endpoint or use master account api key to manage its sub account api key.
* The API key must have one of the below permissions in order to call this endpoint
*
* - sub API key: "Account Transfer", "Sub Member Transfer"
* - master API Key: "Account Transfer", "Sub Member Transfer", "Withdrawal"
*/
updateSubApiKey(params) {
return this.postPrivate('/v5/user/update-sub-api', params);
}
/**
* Delete a sub UID. Before deleting the UID, please make sure there are no assets.
*
* TIP:
* The API key must have one of the permissions to be allowed to call the following API endpoint.
* - master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
*/
deleteSubMember(params) {
return this.postPrivate('/v5/user/del-submember', params);
}
/**
* Delete the api key of master account. Use the api key pending to be delete to call the endpoint. Use master user's api key only.
*
* TIP:
* The API key must have one of the permissions to be allowed to call the following API endpoint.
* - master API key: "Account Transfer", "Subaccount Transfer", "Withdrawal"
*
* DANGER: BE CAREFUL! The API key used to call this interface will be invalid immediately.
*/
deleteMasterApiKey() {
return this.postPrivate('/v5/user/delete-api');
}
/**
* Delete the api key of sub account. Use the api key pending to be delete to call the endpoint. Use sub user's api key only.
*
* TIP:
* The API key must have one of the permissions to be allowed to call the following API endpoint.
* - sub API key: "Account Transfer", "Sub Member Transfer"
* - master API Key: "Account Transfer", "Sub Member Transfer", "Withdrawal"
*
* DANGER: BE CAREFUL! The sub API key used to call this interface will be invalid immediately.
*/
deleteSubApiKey(params) {
return this.postPrivate('/v5/user/delete-sub-api', params);
}
/**
*
****** Affiliate APIs
*
*/
/**
* Get Affiliate User List.
* To use this endpoint, you should have an affiliate account and only tick "affiliate" permission while creating the API key.
*
* TIP:
* - Use master UID only
* - The api key can only have "Affiliate" permission
*/
getAffiliateUserList(params) {
return this.getPrivate('/v5/affiliate/aff-user-list', params);
}
/**
* Get Affiliate User Info.
*
* This API is used for affiliate to get their users information.
*
* TIP
* Use master UID only
* The api key can only have "Affiliate" permission
* The transaction volume and deposit amount are the total amount of the user done on