Skip to main content

An asynchronous fork of the official ByBit P2P API integration library written in Python.

Project description

bybit_p2p_async

Asynchronous library for integration with Bybit P2P API, written in Python

pip package

bybit_p2p_async - is an asynchronous fork of the official Python SDK for the Bybit P2P API, enabling seamless integration of your software solutions with the Bybit P2P Platform.

  • No need to manually implement request signing mechanisms (HMAC, RSA)
  • Simple and user-friendly
  • Actively developed and maintained
  • Compatible with asynchronous programming
  • Returns structured data using classes

the original synchronous version was developed by kolya5544

Features

bybit_p2p_async currently does not implement all methods available in the P2P API. The library is under active development, and missing endpoints will be added gradually. Below is a list of currently supported features:

  • Retrieve account information
  • Retrieve account balance
  • Retrieve a list of account orders
  • Retrieve a list of available P2P market orders

All functions are typically accessible via a single method call and do not require deep API knowledge to use.

Technologies

bybit_p2p_async leverages a number of technologies and libraries:

  • aiohttp and aiofiles for creating and processing HTTP requests, including multipart/form-data
  • pycryptodome for HMAC and RSA operations

Installation

bybit_p2p_async was tested on Python 3.11, but should work on all higher versions as well. The module can be installed manually or via PyPI with pip:

pip install bybit-p2p-async

Usage

Once installed, you can import and use bybit_p2p_async in your code:

from bybit_p2p_async import P2P

Here is an example:

import asyncio

from bybit_p2p_async import P2P


async def main():
    api = P2P(
        api_key="x",
        api_secret="x"
    )

    # 1. Get account information.
    status, data = await api.get_account_information()

    if status:
        print(f"Nickname: {data.nickname}")
        print(f"Real Name: {data.real_name}")
        print(f"User ID: {data.user_id}")
        print(f"Orders: {data.order_num}")
        print()

    # 2. Get account balance.
    status, data = await api.get_current_balance(
        account_type="FUND",
        coins=["USDT", "USDC", "BTC"]
    )

    if status:
        account_type, member_id, coins = data
        print(f"User ID: {member_id}")
        print(f"Account: {account_type}")
        print("=" * 10)
        for coin in coins:
            print(f"{coin.name}")
            print(f"Wallet balance: {coin.wallet_balance}")
            print(f"Transfer balance: {coin.transfer_balance}")
            
            if coin.bonus is not None:
                print(f"Bonus: {coin.bonus}")

            print("-" * 8)
            print()


    # 3. Get account ads.
    status, data = await api.get_ads_list(
        available=False,
        side="buy",
        token_id="USDT",
        size=5,
        currency_id="USD"
    )

    if status:
        count, hidden, ads = data
        print(f"Retrieved orders: {count}")
        print(f"Hidden: {'Yes' if hidden else 'No'}")
        print("=" * 10)
        for ad in ads:
            print(f"Pair: {ad.token_name}/{ad.currency_id}")
            print(f"Price: {ad.price}")
            print(f"Quantity: {ad.quantity}")
            print(f"Remark: {ad.remark}")

            print("-" * 8)

        print()

    # 4. Get market ads.
    status, data = await api.get_market_ads(
        amount=5000,
        bulk_maker=True,
        va_maker=True,
        can_trade=True,
        currency_id="USD",
        token_id="USDT",
        side="sell",
        sort_type="TRADE_PRICE"
    )

    if status:
        count, ads = data
        print(f"Total ads: {count}")
        print("=" * 10)

        print("=" * 10)
        for ad in ads:
            print(f"Pair: {ad.token_id}/{ad.currency_id}")
            print(f"Price: {ad.price}")
            print(f"Quantity: {ad.quantity}")
            print(f"Remark: {ad.remark}")

            print("-" * 8)

        print()


    await api.close_session()

if __name__ == "__main__":
    asyncio.run(main())

The P2P() class is used to interact with the P2P API. The testnet parameter indicates the environment. For Mainnet (https://bybit.com/), use testnet=False. For Testnet (https://testnet.bybit.com/), use testnet=True.

RSA users should also set rsa=True in the constructor. Users from regions like TR/KZ/NL/etc. can customize the domain and tld parameters, e.g., tld="kz".

A full working example is available here: bybit_p2p_async quickstart.

Documentation

The bybit_p2p_async library currently consists of a single module used for direct REST requests to the Bybit P2P API.

You can access the P2P API documentation here: P2P API documentation

Below is the mapping between API methods and bybit_p2p methods:

Ads:

bybit_p2p method name P2P API method name P2P API endpoint path
get_online_ads() Get all ads /v5/p2p/item/online
get_ads_list() Get your ads /v5/p2p/item/personal/list

Orders:

User:

bybit_p2p method name P2P API method name P2P API endpoint path
get_account_information() Получить информацию о текущем пользователе /v5/p2p/user/personal/info

Misc:

bybit_p2p method name P2P API method name P2P API endpoint path
get_current_balance() Get coin balances /v5/asset/transfer/query-account-coins-balance
get_market_ads() Get ads list from P2P market /v5/p2p/item/online

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bybit_p2p_async-1.0.1.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bybit_p2p_async-1.0.1-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file bybit_p2p_async-1.0.1.tar.gz.

File metadata

  • Download URL: bybit_p2p_async-1.0.1.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for bybit_p2p_async-1.0.1.tar.gz
Algorithm Hash digest
SHA256 27bd2f72774f42c1e9f3187e44050b18665e5a1214e0e80743217f095ec6105a
MD5 7ad9620d17e425134d71af81cbff74e9
BLAKE2b-256 f523283276ede71188accd8aa1e73c796ff91616d8064adb658aeab6e9ace657

See more details on using hashes here.

File details

Details for the file bybit_p2p_async-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for bybit_p2p_async-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8a9d11c921f300054f549d73a1c1353be78ae0298cf5d8594b62aa88c2fa66aa
MD5 9aa8a7167198aad5b2e23f4c5246365f
BLAKE2b-256 abe083d959065c9803681578cab4850b1120772827c69e4218fb72de9e29aecc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page