Complete developer documentation for Bybit trading API. Authentication, endpoints, and integration examples.
Create Bybit Account →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.
https://api.bybit.comwss://stream.bybit.com
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)
| Endpoint | Method | Description |
|---|---|---|
| /v5/market/tickers | GET | Get market tickers |
| /v5/order/create | POST | Place order |
| /v5/position/closed-pnl | GET | Get position PnL |
| /v5/account/wallet-balance | GET | Get wallet balance |
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)
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)
https://api-testnet.bybit.com