Polling configuration¶
You can configure your own polling configuration.
- class aiosend.polling.PollingConfig(timeout=300, delay=2)¶
Polling configuration.
- delay: int¶
Time to wait between the requests in seconds.
- timeout: int¶
Timeout in seconds.
import asyncio
from aiosend import CryptoPay
from aiosend.polling import PollingConfig
from aiosend.types import Invoice
cp = CryptoPay(
"TOKEN",
polling_config=PollingConfig(
timeout=600, # 10 minutes
delay=3, # request every 3 seconds
),
)
@cp.invoice_paid()
async def handler(invoice: Invoice) -> None:
print("Received", invoice.amount, invoice.asset)
# called after timeout (600s) or when invoice status is "expired"
@cp.invoice_expired()
async def expired_invoice_handler(invoice: Invoice, payload: str) -> None:
print("Expired invoice", invoice.invoice_id, payload)
async def main() -> None:
invoice = await cp.create_invoice(1, "USDT")
print("invoice link:", invoice.bot_invoice_url)
invoice.poll()
await cp.start_polling()
if __name__ == "__main__":
asyncio.run(main())
- class aiosend.polling.PollingManager(config)¶
Polling manager class.
This class is used to handle payments and check activation via polling method.
- abstractmethod get_checks(asset=None, check_ids=None, status=None, offset=None, count=None)¶
getchecks method.
- Return type:
list[Check]
- abstractmethod get_invoices(asset=None, fiat=None, invoice_ids=None, status=None, offset=None, count=None)¶
getinvoices method.
- Return type:
list[Invoice]
- start_polling(parallel=None)¶
Run polling.
- Parameters:
parallel (
Callable[[],Any] |None) – function to run in background.- Return type:
None