Install & Compatibility
Where this runs
tested against v5.16.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.778s · 31.1MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.9s · import 0.727s · 32MB
30MB installed
● package 30MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
HTTP
✓ from pybit.unified_trading import HTTP
✗ from pybit import usdt_perpetual
For Bybit V5 unified endpoint, use `unified_trading`. Older versions used `usdt_perpetual` or `inverse_perpetual` modules.
WebSocket
✓ from pybit.unified_trading import WebSocket
✗ from pybit import usdt_perpetual
For Bybit V5 unified endpoint, use `unified_trading`. Older versions used `usdt_perpetual` or `inverse_perpetual` modules.
AsyncHTTP
✓ from pybit.unified_trading import AsyncHTTP
Use `AsyncHTTP` for asynchronous HTTP API interactions.
AsyncWebSocket
✓ from pybit.unified_trading import AsyncWebSocket
Use `AsyncWebSocket` for asynchronous WebSocket API interactions.
This quickstart demonstrates how to initialize the `pybit` HTTP client for Bybit's unified trading API, authenticate using environment variables, and perform basic authenticated (get wallet balance) and unauthenticated (get tickers) requests. Remember to replace placeholder API keys or set them as environment variables.
import os
from pybit.unified_trading import HTTP
# It's recommended to store API keys in environment variables
api_key = os.environ.get('BYBIT_API_KEY', 'YOUR_API_KEY')
api_secret = os.environ.get('BYBIT_API_SECRET', 'YOUR_API_SECRET')
# Initialize an authenticated HTTP session for the unified trading API
# Set testnet=True for testing on Bybit's testnet
session = HTTP(
testnet=True, # Change to False for mainnet
api_key=api_key,
api_secret=api_secret,
)
try:
# Example: Get wallet balance (requires authentication)
response = session.get_wallet_balance(accountType="UNIFIED")
print("Authentication successful. Total Equity:", response["result"]["list"][0]["totalEquity"])
# Example: Get market tickers (does not require authentication)
tickers = session.get_tickers(category="linear", symbol="BTCUSDT")
print("BTCUSDT Mark Price:", tickers["result"]["list"][0]["markPrice"])
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure your API keys are correct and match the testnet/mainnet setting.")
Errors
Common errors & fixes
{"retCode": 10003, "retMsg": "API key is invalid.", "result": {}}
The API key used is either incorrect, expired, or generated for the wrong environment (testnet key used on mainnet or vice-versa).
fixVerify your `api_key` and `api_secret`. Ensure the `testnet` parameter in your `HTTP` or `WebSocket` client matches the environment your keys are from.
{"retCode": 10006, "retMsg": "Too many visits!", "result": {}}
Your application is sending requests to the Bybit API faster than the allowed rate limit for that endpoint.
fixImplement an exponential backoff strategy with random jitter to space out your API calls, or reduce the frequency of your requests.
{"retCode": 10001, "retMsg": "Parameter Error: qty precision is 0.001.", "result": {}}
The quantity or price specified in your order does not conform to the instrument's required precision or step size.
fixQuery `get_instruments_info()` for the specific symbol to get `qtyStep` and `minOrderQty`. Always round your order quantities and prices to these exact specifications.
pybit.exceptions.FailedRequestError: Http status code is not 200. (ErrCode: 404)
The requested API endpoint was not found, often due to an incorrect `category` parameter, or an invalid endpoint path if manually specifying.
fixDouble-check the `category` parameter (e.g., 'linear', 'spot', 'inverse') and ensure all required parameters for the specific method are correct according to Bybit's V5 API documentation.
You have breached the ip rate limit. (ErrCode: 403)
Your external IP address has exceeded a platform-wide rate limit, possibly in shared hosting environments like PythonAnywhere.
fixThis is typically an infrastructure issue. If on shared hosting, contact your provider or consider a dedicated IP/server. If self-hosting, ensure your application adheres to IP-based rate limits.
Upgrade
Version history
5.16.0latest on PyPI · released Apr 18, 2026
Audit
Dependencies
requestsrequiredUsed for HTTP API requests.
websocket-clientrequiredUsed for WebSocket API connections.