Bybit API

Build your own trading bots, analyze markets, and manage your account programmatically. Complete REST and WebSocket API documentation.

Create API Key

Security

Authentication using API key and secret. Supports HMAC SHA256 and RSA. Timestamp and parameters are required in every request.

High Performance

Up to 50 requests per second for public endpoints. Rate limits vary for private endpoints based on type.

Global Infrastructure

API accessible worldwide. Servers are located in multiple regions for minimal latency.

Real-Time Data

Access to spot and futures markets, order books, trade history, balances and more.

Base Endpoints

REST API Base URL: https://api.bybit.com

Testnet: https://api-testnet.bybit.com

Public Data (no authentication)

GET /v5/market/tickers?category=spot
GET /v5/market/kline?category=spot&symbol=BTCUSDT&interval=5
GET /v5/market/orderbook?category=spot&symbol=BTCUSDT

Private Endpoints (require authentication)

GET /v5/account/wallet-balance?accountType=UNIFIED
POST /v5/order/create
GET /v5/order/realtime
DELETE /v5/order/cancel

Authentication

# Headers for private requests
X-BAPI-API-KEY: {api_key}
X-BAPI-TIMESTAMP: {timestamp}
X-BAPI-SIGN: {signature}
X-BAPI-RECV-WINDOW: 5000

The signature is HMAC SHA256 of the string: timestamp + api_key + recv_window + params

WebSocket Streams

Public WebSocket: wss://stream.bybit.com/v5/public/spot
Private WebSocket: wss://stream.bybit.com/v5/private/spot

Subscribe to Public Channels

{
  "op": "subscribe",
  "args": ["tickers.BTCUSDT", "orderbook.50.BTCUSDT", "kline.1m.BTCUSDT"]
}

Private Channels (authentication)

{
  "op": "auth",
  "args": [api_key, timestamp, signature]
}

After successful authentication you can subscribe to order, position, wallet and other private channels.

Python: Get BTC Price

import requests

response = requests.get("https://api.bybit.com/v5/market/tickers?category=spot&symbol=BTCUSDT")
data = response.json()
print(data['result']['list'][0]['lastPrice'])

JavaScript: Create Limit Order

const CryptoJS = require('crypto-js');

const apiKey = 'YOUR_API_KEY';
const secret = 'YOUR_API_SECRET';
const timestamp = Date.now();
const params = `&category=spot&symbol=BTCUSDT&side=Buy&orderType=Limit&qty=0.001&price=50000&timeInForce=GTC`;
const signature = CryptoJS.HmacSHA256(timestamp + apiKey + '5000' + params, secret).toString();

fetch('https://api.bybit.com/v5/order/create', {
  method: 'POST',
  headers: {
    'X-BAPI-API-KEY': apiKey,
    'X-BAPI-TIMESTAMP': timestamp,
    'X-BAPI-SIGN': signature,
    'X-BAPI-RECV-WINDOW': '5000',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    category: 'spot',
    symbol: 'BTCUSDT',
    side: 'Buy',
    orderType: 'Limit',
    qty: '0.001',
    price: '50000',
    timeInForce: 'GTC'
  })
});

WebSocket Python Example

import websocket
import json

def on_message(ws, message):
    print(message)

ws = websocket.WebSocketApp("wss://stream.bybit.com/v5/public/spot",
                            on_message=on_message)
ws.run_forever()

Official Libraries

Python: pip install bybit
Node.js: npm install bybit-api
Java: bybit-java
Go: bybit-go

Start Developing with Bybit API

Create API keys in the "API Management" section and get full access to exchange functionality.

Create API Keys