Skip to main content

@cryptobot api asynchronous python wrapper

Project description

@cryptobot asynchronous api wrapper

Docs: https://help.crypt.bot/crypto-pay-api

Install

pip install aiocryptopay
poetry add aiocryptopay

Basic methods

from aiocryptopay import AioCryptoPay, Networks

crypto = AioCryptoPay(token='1337:JHigdsaASq', network=Networks.MAIN_NET)

profile = await crypto.get_me()
currencies = await crypto.get_currencies()
balance = await crypto.get_balance()
rates = await crypto.get_exchange_rates()

print(profile, currencies, balance, rates, sep='\n')

Create, get and delete invoice methods

from aiocryptopay import AioCryptoPay, Networks

crypto = AioCryptoPay(token='1337:JHigdsaASq', network=Networks.MAIN_NET)

invoice = await crypto.create_invoice(asset='TON', amount=1.5)
print(invoice.bot_invoice_url)

# Create invoice in fiat
fiat_invoice = await crypto.create_invoice(amount=5, fiat='USD', currency_type='fiat')
print(fiat_invoice)

old_invoice = await crypto.get_invoices(invoice_ids=invoice.invoice_id)
print(old_invoice.status)

deleted_invoice = await crypto.delete_invoice(invoice_id=invoice.invoice_id)
print(deleted_invoice)

# Get amount in crypto by fiat summ
amount = await crypto.get_amount_by_fiat(summ=100, asset='TON', target='USD')
invoice = await crypto.create_invoice(asset='TON', amount=amount)
print(invoice.bot_invoice_url)

Create, get and delete check methods

# The check creation method works when enabled in the application settings

from aiocryptopay import AioCryptoPay, Networks

crypto = AioCryptoPay(token='1337:JHigdsaASq', network=Networks.MAIN_NET)

check = await crypto.create_check(asset='USDT', amount=1)
print(check)

old_check = await crypto.get_checks(check_ids=check.check_id)
print(old_check)

deleted_check = await crypto.delete_check(check_id=check.check_id)
print(deleted_check)

WebHook usage

from aiohttp import web

from aiocryptopay import AioCryptoPay, Networks
from aiocryptopay.models.update import Update


web_app = web.Application()
crypto = AioCryptoPay(token='1337:JHigdsaASq', network=Networks.MAIN_NET)


@crypto.pay_handler()
async def invoice_paid(update: Update, app) -> None:
    print(update)

async def create_invoice(app) -> None:
    invoice = await crypto.create_invoice(asset='TON', amount=1.5)
    print(invoice.bot_invoice_url)

async def close_session(app) -> None:
    await crypto.close()


web_app.add_routes([web.post('/crypto-secret-path', crypto.get_updates)])
web_app.on_startup.append(create_invoice)
web_app.on_shutdown.append(close_session)
web.run_app(app=web_app, host='localhost', port=3001)

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

aiocryptopay-0.3.5.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

aiocryptopay-0.3.5-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file aiocryptopay-0.3.5.tar.gz.

File metadata

  • Download URL: aiocryptopay-0.3.5.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.0 Linux/4.4.0-19041-Microsoft

File hashes

Hashes for aiocryptopay-0.3.5.tar.gz
Algorithm Hash digest
SHA256 c1b218c195a0c235536c11e02b904dc7a3620faf98ec3e6343e9472eecd4c933
MD5 2b1714d03e8b19d6a7176105fbc4b570
BLAKE2b-256 e19cc4ab606c30ada4cab3f448eb7b36a51b9618604bbcd8f43a6073ee60ccfe

See more details on using hashes here.

File details

Details for the file aiocryptopay-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: aiocryptopay-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.0 Linux/4.4.0-19041-Microsoft

File hashes

Hashes for aiocryptopay-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 cfee232fb6977c309ec8d036f0e9bc906a758172ffb02e464f2999555b7e6e4d
MD5 dccfdd85adaa9431a69dacd44b213d06
BLAKE2b-256 3e4a6e6163ed5ecc78862c011ffa787d11e07b702a78d1989d387d01d0650bfa

See more details on using hashes here.

Supported by

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