Skip to main content
πŸ“– Tronsell Wiki

Bybit API Guide: Complete Guide to Bybit API Integration

Complete guide to integrating with Bybit's REST and WebSocket APIs for spot and futures trading. Learn authentication, key endpoints, rate limits, and best practices for building production-ready applications.

🟣 Bybit API at a Glance
API Version v5 (REST) Β· WebSocket Streams
Rate Limit 50 req/sec per API key
Products Spot, Futures (USDT-M/COIN-M), Options
Testnet testnet.bybit.com
Auth Method API Key + HMAC SHA256 Signature
Best For Trading bots, data analysis

🟣 Bybit API Overview

The Bybit API is a robust and well-documented API that provides programmatic access to Bybit's spot, futures, and options trading platforms. Bybit uses a unified v5 API structure, making it easier for developers to integrate with different product types.

Bybit's API is known for its:

  • Unified v5 API: Consistent endpoints across spot, futures, and options.
  • High performance: Low latency and high throughput.
  • Comprehensive WebSocket: Real-time data with low latency.
  • Developer-friendly: Clear documentation and SDKs.
πŸ’‘ Bybit API Key Features
  • Unified v5 API: One API for all products.
  • WebSocket streams: Real-time data with low latency.
  • Testnet support: Safe testing with free test funds.
  • Sub-account support: Manage multiple accounts via API.

πŸš€ Getting Started with Bybit API

Before you can use the Bybit API, you need to set up your credentials and understand the authentication process.

1. Get Your API Keys

  • 1
    Log in to your Bybit account

    Go to the Bybit website and log in.

  • 2
    Navigate to API Management

    Go to Account & Security β†’ API Management.

  • 3
    Create a new API key

    Click "Create New API Key," enter a name, and set permissions (Read, Trade, Withdraw).

  • 4
    Set IP whitelist (recommended)

    Add the IP address of your server for enhanced security.

  • 5
    Save your API key and secret

    Copy the API key and secret. The secret is shown only once β€” store it securely.

2. Authentication

Bybit API uses HMAC SHA256 signature authentication. Here's how it works:

signature = HMAC_SHA256(timestamp + apiKey + recvWindow + requestPath, apiSecret)
Headers: X-BAPI-API-KEY, X-BAPI-SIGN, X-BAPI-TIMESTAMP, X-BAPI-RECV-WINDOW

3. Use the Testnet

Always test on the Bybit testnet before deploying with real funds.

πŸ’‘ Testnet URL

Bybit Testnet: testnet.bybit.com β€” Create testnet API keys and get free test funds.

πŸ“‹ Key Bybit API Endpoints

Bybit's v5 API uses a unified structure with different endpoint categories.

Category Endpoint Description Method
Market Data /v5/market/tickers Get ticker prices GET
Market Data /v5/market/kline Get candlestick data GET
Market Data /v5/market/orderbook Get order book depth GET
Account /v5/account/wallet-balance Get account balances GET
Orders /v5/order/create Place a new order POST
Orders /v5/order/cancel Cancel an order POST
Orders /v5/order/realtime Get open orders GET
Orders /v5/order/history Get order history GET
Orders /v5/order/trade-history Get trade history GET
Futures /v5/position/list Get futures positions GET
πŸ’‘ Product-Specific Endpoints

Bybit v5 API uses different endpoint categories: /v5/market/* for public data, /v5/account/* for account, /v5/order/* for orders, and /v5/position/* for positions.

πŸ”„ Bybit WebSocket Streams

Bybit WebSocket streams provide real-time data for all product types.

Public WebSocket Streams

  • Price Ticker: wss://stream.bybit.com/v5/public/spot
  • Order Book: wss://stream.bybit.com/v5/public/spot
  • Trade Stream: wss://stream.bybit.com/v5/public/spot
  • Candlestick: wss://stream.bybit.com/v5/public/spot

Private WebSocket Streams

  • Account updates: Balance and position changes
  • Order updates: Order status changes
  • Trade updates: Trade execution
πŸ“Œ WebSocket Best Practices
  • Use multiple topics in a single connection.
  • Implement auto-reconnection with exponential backoff.
  • Use ping/pong keepalive messages.
  • Authenticate for private streams using the login message.

🚦 Bybit API Rate Limits

Bybit has a rate limit of 50 requests per second per API key for most endpoints. WebSocket connections have separate limits.

Endpoint Rate Limit Notes
/v5/market/* 50 req/sec Market data endpoints
/v5/order/* 50 req/sec Order placement and management
/v5/account/* 50 req/sec Account information
/v5/position/* 50 req/sec Position management
πŸ’‘ Rate Limit Headers

Monitor these headers in responses: x-ratelimit-limit, x-ratelimit-remaining, x-ratelimit-reset. Always check remaining limit before sending requests.

⚠️ Common Bybit API Errors

Here are the most common Bybit API errors and how to fix them.

Error Code Message Cause Solution
10001 Invalid request Malformed request Check request format and parameters
10002 Invalid API key API key doesn't exist or is disabled Verify API key is active and correct
10003 Invalid signature Incorrect signature generation Check signature algorithm and order
10004 Timestamp out of sync System time is off Synchronize system time via NTP
10005 IP not whitelisted IP not in whitelist Add IP to whitelist in API settings
11001 Insufficient balance Not enough funds Check balance before placing orders
11002 Invalid symbol Symbol doesn't exist Verify symbol is correct
11003 Invalid quantity Quantity below min or not step-sized Check exchange filters for the symbol
11004 Invalid price Price below min or not tick-sized Check exchange filters for the symbol
11005 Order not found Order ID not found Verify order ID before querying

πŸ† Bybit API Best Practices

Follow these best practices for reliable Bybit API integration.

  • Always use the testnet first: Test all code on testnet before deploying with real funds.
  • Secure your API keys: Use environment variables, IP whitelisting, and least privilege permissions.
  • Monitor rate limit headers: Track your request count to avoid hitting limits.
  • Use WebSocket for real-time data: Avoid polling REST endpoints for price updates.
  • Implement error handling: Handle common errors like 11001 (insufficient balance) and 10004 (timestamp).
  • Use client order IDs: Assign unique IDs to orders for better tracking.
  • Stay updated: Bybit API changes frequently β€” keep your libraries updated.
  • Use the correct product type: Specify category correctly for spot, futures, or options.
πŸ’‘ Pro Tip

Use the CCXT library for a unified interface to Bybit and other exchanges. It handles authentication, rate limiting, and error handling automatically.

❓ Frequently Asked Questions About Bybit API

How do I get a Bybit API key?

To get a Bybit API key: 1) Log in to your Bybit account. 2) Go to Account & Security β†’ API Management. 3) Click 'Create New API Key.' 4) Enter a name and set permissions (Read, Trade, Withdraw). 5) Set IP whitelist (recommended). 6) Complete 2FA verification. 7) Copy and save your API key and secret. The secret is shown only once.

What is the difference between Bybit Spot API and Futures API?

Bybit uses separate API endpoints for spot and futures trading. Spot uses /v5/spot/ endpoints, while futures use /v5/linear/ (USDT-M) or /v5/inverse/ (COIN-M). Both are part of the unified v5 API but have different endpoint paths.

What are Bybit API rate limits?

Bybit has a rate limit of 50 requests per second per API key for most endpoints. Some endpoints have different limits. WebSocket connections have separate limits. Always check the response headers for rate limit information.

How do I fix Bybit API error 10001?

Error 10001 means 'Invalid request.' This usually indicates malformed parameters, missing required fields, or incorrect parameter types. Check your request against the API documentation.

Does Bybit have a testnet for API testing?

Yes, Bybit offers a testnet environment at testnet.bybit.com. It provides free test funds for safe API testing of spot and futures trading. You can create testnet API keys and test your integration without risking real money.

What permissions should I set for my Bybit API key?

For most trading bots, enable Read (to view balances and market data) and Trade (to place orders). Never enable Withdraw unless absolutely necessary. Use IP whitelisting for additional security.

Can I use WebSocket for Bybit API?

Yes, Bybit provides WebSocket streams for real-time data. Public streams include price tickers, order books, and trade streams. Private streams (authenticated) provide account and order updates. WebSocket is recommended for real-time applications.

What are the best libraries for Bybit API?

The most popular libraries are CCXT (unified API for multiple exchanges) and bybit-api (Node.js). CCXT is recommended for multi-exchange support, while bybit-api is a dedicated library for Bybit.

🟣 Start Building with Bybit API

Integrate with Bybit's powerful API for spot and futures trading. Start with the testnet, secure your keys, and build reliable trading applications.