Bybit API Guide

Complete developer documentation for Bybit trading API. Authentication, endpoints, and integration examples.

Create Bybit Account →

Bybit API Overview

Bybit provides a comprehensive API for algorithmic trading, market data, and account management. The API supports REST for order management and WebSocket for real-time data.

API Base URL: https://api.bybit.com
WebSocket: wss://stream.bybit.com

Authentication

Bybit API uses HMAC SHA256 signature authentication. Here's how to authenticate:

import hmac
import hashlib
import time

def generate_signature(secret, payload, timestamp):
    message = timestamp + payload
    signature = hmac.new(
        secret.encode('utf-8'),
        message.encode('utf-8'),
        hashlib.sha256
    ).hexdigest()
    return signature

# Example request
timestamp = str(int(time.time() * 1000))
params = {"symbol": "BTCUSDT", "limit": 10}
payload = "&".join([f"{k}={v}" for k, v in params.items()])
signature = generate_signature(YOUR_API_SECRET, payload, timestamp)

Core Endpoints

EndpointMethodDescription
/v5/market/tickersGETGet market tickers
/v5/order/createPOSTPlace order
/v5/position/closed-pnlGETGet position PnL
/v5/account/wallet-balanceGETGet wallet balance

Code Examples

Python - Get Market Data

import requests

url = "https://api.bybit.com/v5/market/tickers"
params = {"category": "linear", "symbol": "BTCUSDT"}

response = requests.get(url, params=params)
data = response.json()
print(data)

Python - Place Order

import requests
import hmac
import hashlib
import time

api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"
url = "https://api.bybit.com/v5/order/create"

timestamp = str(int(time.time() * 1000))
params = {
    "category": "linear",
    "symbol": "BTCUSDT",
    "side": "Buy",
    "orderType": "Market",
    "qty": "0.001"
}
params["recvWindow"] = "5000"

payload = "&".join([f"{k}={v}" for k,v in params.items()])
signature = hmac.new(
    api_secret.encode(),
    (timestamp + payload).encode(),
    hashlib.sha256
).hexdigest()

headers = {
    "X-BAPI-API-KEY": api_key,
    "X-BAPI-SIGN": signature,
    "X-BAPI-TIMESTAMP": timestamp
}

response = requests.post(url, json=params, headers=headers)

Rate Limits

Best Practices

Start Trading on Bybit →