Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/bybit-api/llms.txt

Use this file to discover all available pages before exploring further.

The bybit-api SDK exports a set of constant objects, enums, and arrays that map human-readable identifiers to the values expected by the Bybit API. Using these avoids hard-coding magic strings or numbers throughout your codebase.

Import

import {
  API_ERROR_CODE,
  WS_KEY_MAP,
  linearPositionModeEnum,
  positionTpSlModeEnum,
  LinearPositionIdx,
  WS_API_Operations,
} from 'bybit-api';

API_ERROR_CODE

A constant object mapping named error codes to their numeric Bybit equivalents. Use these in catch blocks to handle specific error conditions.
import { API_ERROR_CODE } from 'bybit-api';

try {
  await client.setLeverage({ category: 'linear', symbol: 'BTCUSDT', buyLeverage: '10', sellLeverage: '10' });
} catch (err) {
  if (err.retCode === API_ERROR_CODE.V5_LEVERAGE_NOT_CHANGED) {
    console.log('Leverage was already set to that value.');
  }
}

Error Code Table

Constant NameCodeWhen It Occurs
BALANCE_INSUFFICIENT_SPOT-1131Insufficient balance on spot (legacy).
ORDER_NOT_FOUND_OR_TOO_LATE_SPOT-2013Order not found or too late to act (spot legacy).
SUCCESS0Request succeeded.
PARAMS_MISSING_OR_WRONG10001Bad request — missing or incorrectly typed parameter. Also used for some “already set” responses.
INVALID_API_KEY_OR_PERMISSIONS10003Invalid API key or insufficient key permissions.
SIGNATURE_NOT_VALID10004Request signature is invalid.
INCORRECT_API_KEY_PERMISSIONS10005API key lacks the required permission for this action.
V5_API_KEY_PERMISSION_DENIED10005Alias for INCORRECT_API_KEY_PERMISSIONS — V5-specific naming.
INCORRECT_API_REQUEST_IP10010Request IP is not on the API key’s IP whitelist.
DB_ERROR_WRONG_CURSOR10016Invalid or stale pagination cursor.
ACCOUNT_NOT_UNIFIED10020Account is not a unified margin account.
COMPLIANCE_RULES_TRIGGERED10024Compliance or KYC rules triggered.
UNKNOWN_ERROR12000Generic unknown error.
BALANCE_INSUFFICIENT_SPOT_V312131Insufficient balance (spot V3).
ORDER_NOT_FOUND_SPOT_V312213Order not found (spot V3).
ORDER_NOT_FOUND_LEVERAGED_TOKEN12407Leveraged token order not found.
EXCEEDED_UPPER_LIMIT_LEVERAGED_TOKEN12409Leveraged token order exceeds upper limit.
QUERY_ACCOUNT_INFO_ERROR12602Error querying account info.
CROSS_MARGIN_USER_NOT_FOUND12607Cross margin user not found.
CROSS_MARGIN_REPAYMENT_NOT_REQUIRED12616Repayment is not required.
CROSS_MARGIN_NOT_ENABLED12640Cross margin is not enabled.
ORDER_NOT_FOUND_OR_TOO_LATE20001Order not found or too late to cancel/amend.
POSITION_STATUS_NOT_NORMAL30013Position is not in normal status.
CANNOT_SET_TRADING_STOP_FOR_ZERO_POS30024Cannot set TP/SL when position size is zero.
INSUFFICIENT_BALANCE_FOR_ORDER_COST30031Insufficient balance for order cost.
POSITION_IDX_NOT_MATCH_POSITION_MODE30041Position index does not match the current position mode.
INSUFFICIENT_BALANCE30042Insufficient balance (e.g. conditional order too large).
POSITION_IS_CROSS_MARGIN30056Cannot change margin on a cross-margin position.
POSITION_MODE_NOT_MODIFIED30083Position mode is already set to the requested value.
ISOLATED_NOT_MODIFIED30084Isolated margin setting unchanged.
RISK_LIMIT_NOT_EXISTS30090Risk limit tier does not exist.
SUB_USER_ALREADY_EXISTS31005Sub-user already exists.
LEVERAGE_NOT_MODIFIED34036Leverage already set to requested value.
SAME_SLTP_MODE37002TP/SL mode already set to this value.
COPY_TRADE_NOT_OPEN_ORDER39426Copy trade order is not open.
V5_ORDER_NOT_FOUND110001Order not found (V5).
V5_INSUFFICIENT_BALANCE110007Insufficient balance (V5).
V5_CROSS_ISOLATED_MARGIN_NOT_CHANGED110026Cross/isolated margin setting unchanged.
V5_LEVERAGE_NOT_CHANGED110043Leverage already at requested value (V5).
V5_MARGIN_MODE_NOT_CHANGED110073Margin mode already set to this value.
V5_TPSL_NOT_CHANGED10001TP/SL mode or values not changed (V5 alias of PARAMS_MISSING_OR_WRONG).
V5_RISK_ID_NOT_CHANGED10001Risk ID not changed (V5 alias of PARAMS_MISSING_OR_WRONG).
V5_AUTO_ADD_MARGIN_NOT_CHANGED10001Auto-add margin setting not changed (V5 alias of PARAMS_MISSING_OR_WRONG).
V5_TPSL_ERROR_NO_POSITION10001TP/SL error: no open position exists (V5 alias of PARAMS_MISSING_OR_WRONG).
V5_RISK_ID_NOT_MODIFIED110075Risk ID not modified.
QTY_EXCEEDS_MAX_LIMIT130006Order quantity exceeds maximum allowed.
ORDER_NOT_FOUND_OR_TOO_LATE_LINEAR130010Order not found or too late (linear).
ORDER_COST_NOT_AVAILABLE130021Order cost is not available.
CANNOT_SET_LINEAR_TRADING_STOP_FOR_ZERO_POS130024Cannot set trading stop when linear position is zero.
ISOLATED_NOT_MODIFIED_LINEAR130056Isolated margin setting unchanged (linear).
POSITION_SIZE_IS_ZERO130057Position size is zero.
AUTO_ADD_MARGIN_NOT_MODIFIED130060Auto-add margin setting unchanged.
INSUFFICIENT_BALANCE_FOR_ORDER_COST_LINEAR130080Insufficient balance for order cost (linear).
SAME_SLTP_MODE_LINEAR130150TP/SL mode already set (linear).
NOT_SUPPORTED_FOR_SUBACCOUNTS131003This operation is not supported for sub-accounts.
TRANSFER_ID_EXISTS131214Transfer ID already exists.
RISK_ID_NOT_MODIFIED134026Risk ID not modified.
CONTRACT_ORDER_NOT_EXISTS140001Contract order does not exist.
CONTRACT_INSUFFICIENT_BALANCE140007Insufficient balance for contract.
CONTRACT_POSITION_MODE_NOT_MODIFIED140025Contract position mode unchanged.
CONTRACT_MARGIN_MODE_NOT_MODIFIED140026Contract margin mode unchanged.
CONTRACT_RISK_LIMIT_INFO_NOT_EXISTS140031Contract risk limit info not found.
CONTRACT_SET_LEVERAGE_NOT_MODIFIED140043Contract leverage unchanged.
SUB_USER_NOT_FOUND141009Sub-user not found.
SPOT_LEVERAGE_TOKEN_INSUFFICIENT_BALANCE175006Insufficient balance for leveraged token.
SPOT_LEVERAGE_TOKEN_ORDER_NOT_FOUND175007Leveraged token order not found.
SPOT_LEVERAGE_QUIZ_REQUIRED175010Must complete leveraged token quiz first.
SPOT_MARGIN_NOT_ENABLED176008Spot margin is not enabled.
SPOT_MARGIN_QUESTIONNAIRE_NOT_SUBMIT176037Must submit spot margin questionnaire.
CONTRACT_NAME_NOT_EXIST3100111Contract name does not exist (e.g. inactive options symbol).
ORDER_NOT_EXIST3100136Order does not exist.
NO_ACTIVE_ORDER3100205No active order found.
ACCOUNT_NOT_EXIST3200200Account not opened for this product (e.g. USDC options).
INCORRECT_PRIVATE_OPERATIONS3303001Incorrect private operation.
SET_MARGIN_MODE_FAILED_USDC3400045Failed to set margin mode for USDC.
INCORRECT_MMP_PARAMETERS3500712Incorrect market maker protection parameters.
INSTITION_MMP_PROFILE_NOT_FOUND3500713Institutional MMP profile not found.

WS_KEY_MAP

Maps connection names to the string keys used by WebsocketClient to identify each WebSocket connection. Import and use these when calling sendWSAPIRequest() or when handling wsKey values in event listeners.
import { WS_KEY_MAP } from 'bybit-api';

console.log(WS_KEY_MAP.v5PrivateTrade); // 'v5PrivateTrade'
export const WS_KEY_MAP = {
  v5SpotPublic: 'v5SpotPublic',
  v5LinearPublic: 'v5LinearPublic',
  v5InversePublic: 'v5InversePublic',
  v5OptionPublic: 'v5OptionPublic',
  v5Private: 'v5Private',
  /**
   * The V5 WebSocket API connection — used for order.create / amend / cancel
   */
  v5PrivateTrade: 'v5PrivateTrade',
} as const;
KeyValuePurpose
v5SpotPublic'v5SpotPublic'Spot market data (order book, tickers, trades).
v5LinearPublic'v5LinearPublic'Linear perp/futures market data.
v5InversePublic'v5InversePublic'Inverse perp/futures market data.
v5OptionPublic'v5OptionPublic'Options market data.
v5Private'v5Private'Private stream: orders, positions, wallet, executions.
v5PrivateTrade'v5PrivateTrade'WS API connection for order management.

linearPositionModeEnum

Maps position mode names to the string values accepted by Bybit’s position mode API.
export const linearPositionModeEnum = {
  OneWayMode: 'MergedSingle',
  HedgeMode: 'BothSide',
} as const;
import { linearPositionModeEnum } from 'bybit-api';

await client.switchPositionMode({
  category: 'linear',
  symbol: 'BTCUSDT',
  mode: linearPositionModeEnum.HedgeMode, // 'BothSide'
});
KeyValueDescription
OneWayMode'MergedSingle'One-way position mode (net position).
HedgeMode'BothSide'Hedge mode — separate long and short positions.

positionTpSlModeEnum

Maps TP/SL mode names to the string values used by Bybit.
export const positionTpSlModeEnum = {
  /**
   * Full take profit/stop loss mode.
   * A single TP order and a single SL order can be placed,
   * covering the entire position.
   */
  Full: 'Full',
  /**
   * Partial take profit/stop loss mode.
   * Multiple TP and SL orders can be placed,
   * covering portions of the position.
   */
  Partial: 'Partial',
} as const;
import { positionTpSlModeEnum } from 'bybit-api';

await client.setTPSLMode({
  category: 'linear',
  symbol: 'BTCUSDT',
  tpSlMode: positionTpSlModeEnum.Partial, // 'Partial'
});
KeyValueDescription
Full'Full'One TP + one SL covering the full position.
Partial'Partial'Multiple TP/SL orders covering partial position sizes.

LinearPositionIdx (TypeScript enum)

Numeric position index used when placing orders in hedge mode to specify which side the order is for.
export enum LinearPositionIdx {
  OneWayMode = 0,
  BuySide = 1,
  SellSide = 2,
}
import { LinearPositionIdx } from 'bybit-api';

// Place a limit buy in hedge mode on the buy-side position
await client.submitOrder({
  category: 'linear',
  symbol: 'BTCUSDT',
  side: 'Buy',
  orderType: 'Limit',
  qty: '0.01',
  price: '30000',
  timeInForce: 'GTC',
  positionIdx: LinearPositionIdx.BuySide, // 1
});
MemberValueDescription
OneWayMode0One-way position mode.
BuySide1Long side position in hedge mode.
SellSide2Short side position in hedge mode.

WS_API_Operations

A runtime array of all supported WebSocket API operation strings. Useful for validating operations or building dynamic dispatch tables.
export const WS_API_Operations: WSAPIOperation[] = [
  'order.create',
  'order.amend',
  'order.cancel',
  'order.create-batch',
  'order.amend-batch',
  'order.cancel-batch',
];
import { WS_API_Operations } from 'bybit-api';

// Check if an operation is valid before sending
function isValidWSAPIOperation(op: string): op is WSAPIOperation {
  return (WS_API_Operations as string[]).includes(op);
}
OperationDescription
'order.create'Submit a new order.
'order.amend'Amend an existing open order.
'order.cancel'Cancel an existing open order.
'order.create-batch'Batch submit multiple orders.
'order.amend-batch'Batch amend multiple orders.
'order.cancel-batch'Batch cancel multiple orders.

CategoryV5 (type, for reference)

type CategoryV5 = 'spot' | 'linear' | 'inverse' | 'option';
While CategoryV5 is a type rather than a runtime constant, it appears in virtually every API call. You can build your own constant map for it:
const CATEGORY = {
  spot: 'spot',
  linear: 'linear',
  inverse: 'inverse',
  option: 'option',
} as const satisfies Record<string, CategoryV5>;

Types Reference

Full TypeScript type definitions for all SDK interfaces.

WebsocketClient

Using WS_KEY_MAP in subscriptions and event handling.

WebsocketAPIClient

Using WSAPIOperation and WS_API_Operations in order management.

RestClientV5

Using API_ERROR_CODE in REST error handling.

Build docs developers (and LLMs) love