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)

session = as_client.kyc.start()          # access_token для WebSDK или redirect_url
print(as_client.kyc.status().status)     # pending → submitted → approved

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")

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.2.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.2.0
File Size Uploaded Provenance
pystakan-0.2.0.tar.gz 70.0 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 89.7 kB

Release files / pystakan-0.2.0.tar.gz

Download URL pystakan-0.2.0.tar.gz
Size 70.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9df37817d1698558c4b555120cd7f7b807cb59ac514da4d61fb72a1d17bea2ab
BLAKE2b-256 checksum
How to use checksums
48aaa626b036e7c28e084e66780d5e0b1c64aea0897b101ce9221554b806e4e3
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.2.0-py3-none-any.whl

Download URL pystakan-0.2.0-py3-none-any.whl
Size 19.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d9145ac141307c3dfda07ca7f7d939f9f44be633c3299bb0877be69cab197de
BLAKE2b-256 checksum
How to use checksums
388aef42c3e5e9d66caf4289607071098d69b735498f409edc66ad324baf6047
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.2.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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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