Skip to main content

pystakan

Python-клиент Stakanex API: обмен RUB ↔ USDT, пополнения, выводы, KYC и всё для партнёров — клиенты, работа от их имени и наценка.

pip install pystakan

Python 3.10+. Синхронный Stakan и асинхронный AsyncStakan с одинаковыми методами.

Начало

from stakan import Stakan

stakan = Stakan("stx_ab12cd34_…")  # или переменная окружения STAKAN_API_KEY
print(stakan.account.balances())

quote = stakan.exchange.quote("9000")  # рубли → USDT
deal = stakan.exchange.create("9000", quote.rate_version)
print(deal.reference, deal.status)

Ключ выпускается в кабинете: Настройки → API (нужна 2FA). Права: read, trade (обмен, пополнение, KYC, клиенты, наценка), withdraw (адреса и вывод).

Партнёрам

Ключ партнёра открывает аккаунты клиентов и работает от их имени — for_client(id) добавляет к каждому запросу X-Client-Id:

client = stakan.partner.clients.create("client@example.com", external_id="u-1842")
as_client = stakan.for_client(client.id)

# access_token для WebSDK или redirect_url; return_url — куда провайдер вернёт клиента
session = as_client.kyc.start(return_url="https://shop.example/orders/7")
print(as_client.kyc.status().status)  # pending → submitted → approved
as_client.kyc.reset("Сменился паспорт")  # пройти заново: операции закрыты до новой проверки

quote = as_client.exchange.quote("1020")  # курс уже с вашей наценкой
as_client.exchange.create("1020", quote.rate_version)

entry = as_client.address_book.add("trc20", "TUEZ…", code="123456")  # ваш код 2FA
as_client.withdrawals.create(entry.id, "30")

link = as_client.payment_links.create("1500", description="Заказ 7")  # KYC без входа и оплата по СБП
print(link.url, as_client.payment_links.get(link.id).status)

stakan.partner.set_markup("2")  # наценка для клиентов, до потолка
print(stakan.partner.get().summary.earned)

Своя 2FA клиента

Пока её нет, адреса клиента подтверждает ваш код, а вывод идёт без кода. Включите — и вывод и новые адреса клиента пойдут только с его кодом:

setup = as_client.totp.setup()  # покажите клиенту QR из setup.otpauth_url
enabled = as_client.totp.confirm("123456")  # первый код из его приложения
print(enabled.backup_codes)  # резервные коды — показать клиенту один раз

as_client.address_book.add("trc20", "TUEZ…", code="654321")  # код клиента
as_client.withdrawals.create(entry.id, "30", code="112233")  # код клиента
as_client.totp.disable("ab12-cd34")  # его код или резервный

Потерял телефон и резервные коды — сброс у поддержки Stakanex.

Найти клиента по своему id — stakan.partner.clients.find("u-1842"), обойти всех — for c in stakan.partner.clients.iter().

Деньги и повторы

  • Суммы — str, int или Decimal. float не принимается: в нём теряются копейки.
  • Обмен, пополнение и вывод получают Idempotency-Key сами (или ваш — idempotency_key=). При сетевом сбое, 429 и 5xx запрос повторяется с тем же ключом — вторая операция не создастся. max_retries=2 по умолчанию.

Ошибки

Каждый отказ API — исключение с code (стабильный код API), message, status и reference (номер операции, если она осталась в истории):

from stakan import RateChanged, Refused, StakanError

try:
    as_client.exchange.create("1020", quote.rate_version)
except RateChanged:
    ...  # курс или наценка сменились — возьмите новую котировку
except Refused as refusal:
    print(refusal.code, refusal.message)  # insufficient_funds, bad_amount, …

AuthError (401), PermissionDenied (403), NotFound (404), Conflict / RateChanged (409), Refused (422), RateLimited (429), ServerError (5xx), ConnectionFailed — ответа не было.

Асинхронно

from stakan import AsyncStakan

async with AsyncStakan() as stakan:
    async for tx in stakan.for_client(client_id).transactions.iter():
        print(tx.reference, tx.kind, tx.status)

Документация API: https://api.stakanex.io/v1/docs. Лицензия MIT.

Metadata

Release files for pystakan 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pystakan 0.3.0
File Size Uploaded Provenance Actions
pystakan-0.3.0.tar.gz 75.1 kB Without provenance Details for pystakan-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pystakan 0.3.0
File Interpreter ABI Platform Actions
pystakan-0.3.0-py3-none-any.whl Python 3 none any Details for pystakan-0.3.0-py3-none-any.whl

Total release size: 98.4 kB

Release files / pystakan-0.3.0.tar.gz

Download URL pystakan-0.3.0.tar.gz
Size 75.1 kB
Tags Source
SHA-256 checksum
How to use checksums
cf93562f8200e4db58fccb1754195785f3a38de581896b350b41e845bf36d995
BLAKE2b-256 checksum
How to use checksums
7b5c18331b8ac19f6d3e1f513be68ec59500fba6d11a104ef22d26426b2e885f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.11

Release files / pystakan-0.3.0-py3-none-any.whl

Download URL pystakan-0.3.0-py3-none-any.whl
Size 23.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8389faff44556558794e0477f56b0c3d665949c989be2133903c210c8dbd766d
BLAKE2b-256 checksum
How to use checksums
4fa30c93dd7f9c0b22f44a78cca9c461281209ce11571138769e1cd419bd663f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.11

Security for pystakan 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page