https://t.me/CryptoBot api asynchronous python wrapper
@cryptobot asynchronous api wrapper
Docs: https://help.crypt.bot/crypto-pay-api- MainNet - @CryptoBot - TestNet - @CryptoTestnetBot
Install
bash pip install aiocryptopay poetry add aiocryptopay
Basic methods
python 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.getexchangerates() stats = await crypto.get_stats()
print(profile, currencies, balance, rates, stats, sep='\n')
Create, get and delete invoice methods
python 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.botinvoiceurl)
Create invoice in fiat
fiatinvoice = await crypto.createinvoice(amount=5, fiat='USD', currency_type='fiat')
print(fiat_invoice)
oldinvoice = await crypto.getinvoices(invoiceids=invoice.invoiceid) print(old_invoice.status)
deletedinvoice = await crypto.deleteinvoice(invoiceid=invoice.invoiceid) print(deleted_invoice)
Create, get and delete check methods
python 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)
oldcheck = await crypto.getchecks(checkids=check.checkid) print(old_check)
deletedcheck = await crypto.deletecheck(checkid=check.checkid) print(deleted_check)
WebHook usage
python 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.botinvoiceurl)
async def close_session(app) -> None: await crypto.close()
webapp.addroutes([web.post('/crypto-secret-path', crypto.get_updates)]) webapp.onstartup.append(create_invoice) webapp.onshutdown.append(close_session) web.runapp(app=webapp, host='localhost', port=3001)