Registry / payments / pybit
library5.16.0pypypi✓ verified 85d ago

Pybit is the official Python3 connector for Bybit's HTTP and WebSocket APIs, offering a lightweight and efficient way to interact with the Bybit exchange. The library is actively developed, ensuring new Bybit API changes arrive quickly, and is currently at version 5.15.0.

pip install pybit
INSTALL
IMPORT
SIG · PYBIT
P
pybit
paymentspythonv5.16.0
Install
2.9s avg
Import
753ms
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.778s · 31.1MB
glibc
py 3.103.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.")
Debug
Known issues
breakingThe `set_limit_price_action()` HTTP endpoint no longer accepts any arguments as of `v5.14.0`.
fix
Remove all arguments when calling `session.set_limit_price_action()`.
affects: >=5.14.0
deprecatedOlder Crypto Loan HTTP endpoints were deprecated in `v5.14.0rc0`.
fix
Refer to the Bybit API documentation for the new Crypto Loan (New) endpoints and update your code accordingly.
affects: >=5.14.0
gotchaAPI keys generated for Bybit's testnet are incompatible with the mainnet endpoint, and vice-versa. Using mismatched keys will result in an 'Invalid API Key' error (`retCode: 10003`).
fix
Ensure the `testnet` parameter in the `HTTP` or `WebSocket` client initialization matches the environment (testnet or mainnet) for which your API keys were generated. Always start with `testnet=True` for development.
affects: All versions
gotchaBybit API enforces strict precision and step sizes for order quantities and prices. Incorrect values will result in a 'Parameter Error' (`retCode: 10001`).
fix
Before placing orders, fetch instrument information using `get_instruments_info()` and round your quantity and price to the allowed `qtyStep` and `priceStep` using `Decimal.quantize()`.
affects: All versions
gotchaExceeding Bybit's API rate limits will lead to 'Too many visits!' (`retCode: 10006`).
fix
Implement exponential backoff with jitter for retries. Monitor the `X-Bapi-Limit-Status` response header to track your remaining quota.
affects: All versions
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).
fix
Verify 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.
fix
Implement 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.
fix
Query `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.
fix
Double-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.
fix
This 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.
Agent activity
60 hits · last 30 days
node
56
Resources
pybit — pip install pybit · libregistry