{"id":8469,"library":"pybit","title":"Pybit","description":"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.","status":"active","version":"5.15.0","language":"en","source_language":"en","source_url":"https://github.com/bybit-exchange/pybit","tags":["bybit","exchange","crypto","trading","api","websocket"],"install":[{"cmd":"pip install pybit","lang":"bash","label":"Install Pybit"}],"dependencies":[{"reason":"Used for HTTP API requests.","package":"requests","optional":false},{"reason":"Used for WebSocket API connections.","package":"websocket-client","optional":false}],"imports":[{"note":"For Bybit V5 unified endpoint, use `unified_trading`. Older versions used `usdt_perpetual` or `inverse_perpetual` modules.","wrong":"from pybit import usdt_perpetual","symbol":"HTTP","correct":"from pybit.unified_trading import HTTP"},{"note":"For Bybit V5 unified endpoint, use `unified_trading`. Older versions used `usdt_perpetual` or `inverse_perpetual` modules.","wrong":"from pybit import usdt_perpetual","symbol":"WebSocket","correct":"from pybit.unified_trading import WebSocket"},{"note":"Use `AsyncHTTP` for asynchronous HTTP API interactions.","symbol":"AsyncHTTP","correct":"from pybit.unified_trading import AsyncHTTP"},{"note":"Use `AsyncWebSocket` for asynchronous WebSocket API interactions.","symbol":"AsyncWebSocket","correct":"from pybit.unified_trading import AsyncWebSocket"}],"quickstart":{"code":"import os\nfrom pybit.unified_trading import HTTP\n\n# It's recommended to store API keys in environment variables\napi_key = os.environ.get('BYBIT_API_KEY', 'YOUR_API_KEY')\napi_secret = os.environ.get('BYBIT_API_SECRET', 'YOUR_API_SECRET')\n\n# Initialize an authenticated HTTP session for the unified trading API\n# Set testnet=True for testing on Bybit's testnet\nsession = HTTP(\n    testnet=True,  # Change to False for mainnet\n    api_key=api_key,\n    api_secret=api_secret,\n)\n\ntry:\n    # Example: Get wallet balance (requires authentication)\n    response = session.get_wallet_balance(accountType=\"UNIFIED\")\n    print(\"Authentication successful. Total Equity:\", response[\"result\"][\"list\"][0][\"totalEquity\"])\n\n    # Example: Get market tickers (does not require authentication)\n    tickers = session.get_tickers(category=\"linear\", symbol=\"BTCUSDT\")\n    print(\"BTCUSDT Mark Price:\", tickers[\"result\"][\"list\"][0][\"markPrice\"])\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure your API keys are correct and match the testnet/mainnet setting.\")","lang":"python","description":"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."},"warnings":[{"fix":"Remove all arguments when calling `session.set_limit_price_action()`.","message":"The `set_limit_price_action()` HTTP endpoint no longer accepts any arguments as of `v5.14.0`.","severity":"breaking","affected_versions":">=5.14.0"},{"fix":"Refer to the Bybit API documentation for the new Crypto Loan (New) endpoints and update your code accordingly.","message":"Older Crypto Loan HTTP endpoints were deprecated in `v5.14.0rc0`.","severity":"deprecated","affected_versions":">=5.14.0"},{"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.","message":"API 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`).","severity":"gotcha","affected_versions":"All versions"},{"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()`.","message":"Bybit API enforces strict precision and step sizes for order quantities and prices. Incorrect values will result in a 'Parameter Error' (`retCode: 10001`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement exponential backoff with jitter for retries. Monitor the `X-Bapi-Limit-Status` response header to track your remaining quota.","message":"Exceeding Bybit's API rate limits will lead to 'Too many visits!' (`retCode: 10006`).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"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.","cause":"The API key used is either incorrect, expired, or generated for the wrong environment (testnet key used on mainnet or vice-versa).","error":"{\"retCode\": 10003, \"retMsg\": \"API key is invalid.\", \"result\": {}}"},{"fix":"Implement an exponential backoff strategy with random jitter to space out your API calls, or reduce the frequency of your requests.","cause":"Your application is sending requests to the Bybit API faster than the allowed rate limit for that endpoint.","error":"{\"retCode\": 10006, \"retMsg\": \"Too many visits!\", \"result\": {}}"},{"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.","cause":"The quantity or price specified in your order does not conform to the instrument's required precision or step size.","error":"{\"retCode\": 10001, \"retMsg\": \"Parameter Error: qty precision is 0.001.\", \"result\": {}}"},{"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.","cause":"The requested API endpoint was not found, often due to an incorrect `category` parameter, or an invalid endpoint path if manually specifying.","error":"pybit.exceptions.FailedRequestError: Http status code is not 200. (ErrCode: 404)"},{"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.","cause":"Your external IP address has exceeded a platform-wide rate limit, possibly in shared hosting environments like PythonAnywhere.","error":"You have breached the ip rate limit. (ErrCode: 403)"}]}