Skip to content

Commit 61ed0d3

Browse files
committed
docs: expand coverage for checks, transfers, and stats
1 parent bfeea04 commit 61ed0d3

5 files changed

Lines changed: 187 additions & 10 deletions

File tree

docs/examples.md

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import os
99

1010
from cryptobot import CryptoBotClient
1111
from cryptobot.errors import CryptoBotError
12-
from cryptobot.models import Asset, ButtonName, Status
12+
from cryptobot.models import Asset, ButtonName, CheckStatus, Status
1313

1414
client = CryptoBotClient(api_token=os.environ["CRYPTOBOT_API_TOKEN"])
1515
```
@@ -218,6 +218,97 @@ listener = Listener(
218218
listener.listen()
219219
```
220220

221+
## Airdrop with Crypto Checks
222+
223+
Create checks for a batch of users and track activations.
224+
225+
```python
226+
from cryptobot.models import Asset
227+
228+
229+
def airdrop_checks(client: CryptoBotClient, user_ids: list, amount: float, asset: Asset = Asset.USDT):
230+
"""Create pinned checks for a list of users."""
231+
results = []
232+
for user_id in user_ids:
233+
try:
234+
check = client.create_check(
235+
asset=asset,
236+
amount=amount,
237+
pin_to_user_id=user_id,
238+
)
239+
results.append({"user_id": user_id, "check_id": check.check_id, "url": check.bot_check_url})
240+
except CryptoBotError as exc:
241+
results.append({"user_id": user_id, "error": f"{exc.code}: {exc.name}"})
242+
return results
243+
244+
245+
def check_activations(client: CryptoBotClient, asset: Asset = Asset.USDT):
246+
"""Report activated vs active checks."""
247+
checks = client.get_checks(asset=asset)
248+
activated = [c for c in checks if c.activated_at is not None]
249+
pending = [c for c in checks if c.activated_at is None]
250+
return {"activated": len(activated), "pending": len(pending), "total": len(checks)}
251+
252+
253+
# Usage
254+
recipients = [111111, 222222, 333333]
255+
drops = airdrop_checks(client, recipients, amount=0.5, asset=Asset.TON)
256+
for drop in drops:
257+
print(drop)
258+
259+
print("Status:", check_activations(client, Asset.TON))
260+
```
261+
262+
## App Stats Dashboard
263+
264+
Pull statistics and display a summary report.
265+
266+
```python
267+
def stats_report(client: CryptoBotClient, start_at: str = None, end_at: str = None):
268+
"""Print a summary of app statistics."""
269+
stats = client.get_stats(start_at=start_at, end_at=end_at)
270+
print(f"Volume: {stats.volume}")
271+
print(f"Conversion: {stats.conversion}")
272+
print(f"Unique users: {stats.unique_users_count}")
273+
print(f"Invoices created: {stats.created_invoice_count}")
274+
print(f"Invoices paid: {stats.paid_invoice_count}")
275+
print(f"Period: {stats.start_at} to {stats.end_at}")
276+
277+
278+
# Last 7 days
279+
stats_report(client, start_at="2026-03-11T00:00:00Z", end_at="2026-03-18T00:00:00Z")
280+
```
281+
282+
## Transfer Ledger
283+
284+
Scan outgoing transfers and build a local ledger.
285+
286+
```python
287+
from decimal import Decimal
288+
289+
290+
def transfer_ledger(client: CryptoBotClient, asset: Asset = None):
291+
"""Build a ledger of all outgoing transfers."""
292+
ledger = []
293+
for transfer in client.iter_transfers(asset=asset, page_size=200):
294+
ledger.append({
295+
"id": transfer.transfer_id,
296+
"user_id": transfer.user_id,
297+
"asset": transfer.asset.name,
298+
"amount": transfer.amount,
299+
"status": transfer.status.name,
300+
"spend_id": transfer.spend_id,
301+
"completed_at": transfer.completed_at,
302+
})
303+
304+
total = sum(Decimal(str(t["amount"])) for t in ledger)
305+
return {"entries": ledger, "total": str(total), "count": len(ledger)}
306+
307+
308+
result = transfer_ledger(client, asset=Asset.TON)
309+
print(f"Total transferred: {result['total']} ({result['count']} transfers)")
310+
```
311+
221312
## Testnet Smoke Check
222313

223314
Quick validation script for non-production environments.

docs/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Welcome to CryptoBot Python
22

33
CryptoBot Python is an unofficial, friendly client library for the [Crypto Bot](https://pay.crypt.bot/) API.
4-
It provides typed models and synchronous/async clients for invoices, transfers, balances, exchange rates, and webhook handling.
4+
It provides typed models and synchronous/async clients for invoices, transfers, checks, balances, exchange rates, statistics, and webhook handling.
55

66
## Highlights
77

88
- Synchronous API client built on `httpx`
99
- Async API client built on `httpx`
10-
- Dataclass response models (`Invoice`, `Transfer`, `Balance`, `ExchangeRate`, `Currency`)
11-
- Enum safety for assets, statuses, and paid button names
10+
- Dataclass response models (`Invoice`, `Transfer`, `Check`, `Balance`, `ExchangeRate`, `Currency`, `AppStats`)
11+
- Enum safety for assets, statuses, check statuses, and paid button names
1212
- Mainnet/testnet support with configurable timeout and retries
13-
- Built-in invoice pagination helpers (`iter_invoice_pages`, `iter_invoices`)
13+
- Pagination iterators for invoices, transfers, and checks
1414
- FastAPI webhook listener with signature verification and optional replay protection
1515
- Structured API errors via `CryptoBotError` (`code`, `name`)
1616

docs/troubleshooting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def smoke_test() -> bool:
276276

277277
## Getting Help
278278

279-
1. [Crypto Bot API docs](https://help.crypt.bot/crypto-pay-api)
279+
1. [Crypto Pay API docs](https://help.send.tg/en/articles/10279948-crypto-pay-api)
280280
2. [Examples](examples)
281281
3. [Advanced Topics](advanced)
282282
4. [GitHub issues](https://github.com/ragnarok22/cryptobot_python/issues)

docs/usage.md

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,76 @@ async with AsyncCryptoBotClient(api_token=os.environ["CRYPTOBOT_API_TOKEN"]) as
193193
)
194194
```
195195

196+
### Deleting an Invoice
197+
198+
Delete an active invoice that is no longer needed:
199+
200+
```python
201+
deleted = client.delete_invoice(invoice_id=12345)
202+
print("Deleted:", deleted)
203+
```
204+
205+
### Retrieving Transfers
206+
207+
List outgoing transfers with optional filters:
208+
209+
```python
210+
# Get all transfers
211+
transfers = client.get_transfers()
212+
213+
# Filter by asset or specific IDs
214+
transfers = client.get_transfers(asset=Asset.TON, count=50)
215+
transfers = client.get_transfers(transfer_ids=[100, 101, 102])
216+
217+
# Look up by spend_id
218+
transfers = client.get_transfers(spend_id="reward_2026_02_10_user_123456789")
219+
```
220+
221+
### Crypto Checks
222+
223+
Create a check that any Telegram user (or a pinned user) can activate:
224+
225+
```python
226+
from cryptobot.models import Asset
227+
228+
# Create an open check
229+
check = client.create_check(asset=Asset.USDT, amount=1.0)
230+
print(check.check_id, check.bot_check_url)
231+
232+
# Pin a check to a specific user
233+
check = client.create_check(asset=Asset.TON, amount=0.25, pin_to_user_id=123456789)
234+
```
235+
236+
Retrieve and manage checks:
237+
238+
```python
239+
# List active checks
240+
checks = client.get_checks(asset=Asset.USDT, status="active")
241+
242+
# Get specific checks by ID
243+
checks = client.get_checks(check_ids=[10, 11, 12])
244+
245+
# Delete a check
246+
client.delete_check(check_id=checks[0].check_id)
247+
```
248+
249+
### App Statistics
250+
251+
Get aggregated statistics for your app:
252+
253+
```python
254+
stats = client.get_stats(
255+
start_at="2026-01-01T00:00:00Z",
256+
end_at="2026-03-01T00:00:00Z",
257+
)
258+
print(f"Volume: {stats.volume}")
259+
print(f"Unique users: {stats.unique_users_count}")
260+
print(f"Paid invoices: {stats.paid_invoice_count}")
261+
print(f"Conversion: {stats.conversion}")
262+
```
263+
264+
Both `start_at` and `end_at` are optional ISO 8601 strings. When omitted, `start_at` defaults to 24 hours ago and `end_at` defaults to now.
265+
196266
## Environment Configuration
197267

198268
### Testnet vs Mainnet
@@ -352,7 +422,9 @@ Asset.TRX # TRON
352422

353423
### Pagination with iterators
354424

355-
When dealing with many invoices, prefer the built-in paginated iterator helpers:
425+
When dealing with many records, prefer the built-in paginated iterator helpers. They are available for invoices, transfers, and checks.
426+
427+
**Invoices:**
356428

357429
```python
358430
# Iterate by page
@@ -364,7 +436,21 @@ for invoice in client.iter_invoices(asset=Asset.USDT, status=Status.paid, page_s
364436
print(invoice.invoice_id, invoice.status)
365437
```
366438

367-
Async pagination with equivalent helpers:
439+
**Transfers:**
440+
441+
```python
442+
for transfer in client.iter_transfers(asset=Asset.TON, page_size=100):
443+
print(transfer.transfer_id, transfer.amount)
444+
```
445+
446+
**Checks:**
447+
448+
```python
449+
for check in client.iter_checks(asset=Asset.USDT, status="active", page_size=100):
450+
print(check.check_id, check.bot_check_url)
451+
```
452+
453+
Async pagination works with `async for`:
368454

369455
```python
370456
import os
@@ -390,7 +476,7 @@ async with AsyncCryptoBotClient(api_token=os.environ["CRYPTOBOT_API_TOKEN"]) as
390476
print(invoice.invoice_id, invoice.status)
391477
```
392478

393-
Both iterator variants support `start_offset` and validate `page_size` in the same `1..1000` range.
479+
All iterator variants support `start_offset` and validate `page_size` in the `1..1000` range.
394480

395481
### Invoice Status Checking
396482

docs/webhook_security.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,6 @@ def test_valid_signature():
255255

256256
## References
257257

258-
- [Crypto Bot API docs](https://help.crypt.bot/crypto-pay-api)
258+
- [Crypto Pay API docs](https://help.send.tg/en/articles/10279948-crypto-pay-api)
259259
- [OWASP Webhook Security Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Webhook_Security_Cheat_Sheet.html)
260260
- [FastAPI security docs](https://fastapi.tiangolo.com/tutorial/security/)

0 commit comments

Comments
 (0)