Install pybit via pip
masterInstall the pybit module using pip. This requires Python 3.10 or higher.
pip install pybitrepository·master·Indexed 20 days ago
https://github.com/bybit-exchange/pybitThe official Python 3 lightweight connector for Bybit's HTTP and WebSocket APIs. It provides tools for traders and developers to interact with Bybit, including unified trading sessions for market data, order placement, bulk order submission for USDC Options, and P2P HTTP methods.
Install the pybit module using pip. This requires Python 3.10 or higher.
pip install pybitTo interact with Bybit's APIs, import the HTTP class from pybit.unified_trading and instantiate it with your credentials. Set testnet=False for mainnet access.
from pybit.unified_trading import HTTP
session = HTTP(
testnet=False,
api_key="...",
api_secret="...",
)Use the get_orderbook method on your HTTP session to retrieve market data. You must specify the category (e.g., linear) and the symbol (e.g., BTCUSDT).
# Get the orderbook of the USDT Perpetual, BTCUSDT
session.get_orderbook(category="linear", symbol="BTCUSDT")P2P (Peer-to-Peer) methods are available through the same unified trading HTTP session. Examples include retrieving account information or advertisement lists.
session.get_account_information()
session.get_ads_list()Currently, only USDC Options support bulk order submission. To use place_batch_order, construct a payload with category set to option and a request key containing a list of order objects.
# Create five long USDC Options orders.
# (Currently, only USDC Options support sending orders in bulk.)
payload = {"category": "option"}
orders = [{
"symbol": "BTC-30JUN23-20000-C",
"side": "Buy",
"orderType": "Limit",
"qty": "0.1",
"price": i,
} for i in [15000, 15500, 16000, 16500, 16600]]
payload["request"] = orders
# Submit the orders in bulk.
session.place_batch_order(payload)