pybit Documentation

repository·master·Indexed 20 days ago

https://github.com/bybit-exchange/pybit

The 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.

Tokens
578
Snippets
5
Records
5
Agent score
21%

What's inside pybit

  1. Initialize an HTTP session with pybit

    master

    To 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="...",
    )
  2. Get the orderbook for a market

    master

    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")
  3. Access P2P HTTP methods

    master

    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()
  4. Submit orders in bulk for USDC Options

    master

    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)