Skip to main content

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

Project description

bybit_p2p_async

Асинхронная библиотека интеграции с Bybit P2P API, написанная на Python

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 newer versions. The module can be installed manually.

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:

Объявления:

имя метода bybit_p2p имя метода P2P API Путь эндпоинта P2P API
get_online_ads() Get all ads /v5/p2p/item/online
get_ads_list() Get your ads /v5/p2p/item/personal/list

Ордера:

Пользователь:

имя метода bybit_p2p Get current user information Путь эндпоинта P2P API
get_account_information() Получить информацию о текущем пользователе /v5/p2p/user/personal/info

Разное:

имя метода bybit_p2p имя метода P2P API Путь эндпоинта P2P API
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

Лицензия

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.0.tar.gz (15.3 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.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bybit_p2p_async-1.0.0.tar.gz
  • Upload date:
  • Size: 15.3 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.0.tar.gz
Algorithm Hash digest
SHA256 746042828edbb9aa9399521e1ac31effaa8e6d3007ea31f19e2b56fd2bd34959
MD5 a816e7eb99da6fee10538252c8942c01
BLAKE2b-256 6f1749aa30f2aaccfe95eadb7d63ff15daaf176a1f4688b33fc8d3de030fb29a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bybit_p2p_async-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e1760a23abcc3143b9abdf3ed7ba495f2bcc17e33d704c6902f540325892aff
MD5 9ac88343db5a7578371e1270ff81569b
BLAKE2b-256 27cccdb5fa898d17ce8e2db8cf581cce73b5d1f49e921d2428928a71a78e0f45

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