### Quickstart: Create a Payment Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Initialize the client and create a payment using the `PaymentCreateRequest` model. This example demonstrates creating a standard payment. ```python from kryptoexpress import KryptoExpressClient from kryptoexpress.models.common import CryptoCurrency, FiatCurrency from kryptoexpress.models.payments import PaymentCreateRequest client = KryptoExpressClient(api_key="your-api-key") payment = client.payments.create( PaymentCreateRequest.for_payment( crypto_currency=CryptoCurrency.BTC, fiat_currency=FiatCurrency.USD, fiat_amount=12.34, callback_url="https://example.com/callback", ) ) ``` -------------------------------- ### Quickstart: Get Currency Prices Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Fetch real-time prices for specified cryptocurrencies against a fiat currency using `client.currencies.get_prices()`. ```python prices = client.currencies.get_prices( crypto_currencies=[CryptoCurrency.BTC, CryptoCurrency.ETH], fiat_currency=FiatCurrency.USD, ) ``` -------------------------------- ### Quickstart: Get Wallet Balance Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Retrieve the current wallet balance using the `client.wallet.get()` method. ```python wallet = client.wallet.get() ``` -------------------------------- ### Install kryptoexpress-sdk Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Install the SDK using pip. Ensure you are using Python 3.10 or higher. ```bash pip install kryptoexpress-sdk ``` -------------------------------- ### Quickstart: Create Payment Shortcut Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Use the `create_payment` shortcut method for a more concise way to create a payment. This is equivalent to using `PaymentCreateRequest.for_payment`. ```python payment_shortcut = client.payments.create_payment( crypto_currency=CryptoCurrency.BTC, fiat_currency=FiatCurrency.USD, fiat_amount=12.34, callback_url="https://example.com/callback", ) ``` -------------------------------- ### Quickstart: List Fiat Currencies Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Obtain a list of supported fiat currencies using the `client.fiat.list()` method. ```python fiat = client.fiat.list() ``` -------------------------------- ### Create Payment with Custom Fiat Converter Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Example of creating a payment using a non-USD currency after setting up a custom fiat converter. The SDK's default behavior does not enforce a client-side minimum check for non-USD currencies. ```python payment = client.payments.create( PaymentCreateRequest.for_payment( crypto_currency=CryptoCurrency.BTC, fiat_currency=FiatCurrency.EUR, fiat_amount=0.91, callback_url="https://example.com/callback", ) ) ``` -------------------------------- ### Get Wallet Balances Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Retrieves the current balances of all supported cryptocurrencies in the user's wallet. ```APIDOC ## GET /api/v1/wallet/balance ### Description Retrieves current wallet balances for all supported cryptocurrencies. ### Method GET ### Endpoint /api/v1/wallet/balance ### Response #### Success Response (200) - **BTC** (float) - Balance of Bitcoin. - **ETH** (float) - Balance of Ethereum. - **LTC** (float) - Balance of Litecoin. - **SOL** (float) - Balance of Solana. - **BNB** (float) - Balance of Binance Coin. - **TRX** (float) - Balance of Tron. - **DOGE** (float) - Balance of Dogecoin. - **USDT_ERC20** (float) - Balance of USDT on Ethereum. - **USDC_ERC20** (float) - Balance of USDC on Ethereum. - **USDT_BEP20** (float) - Balance of USDT on BNB Chain. - **USDC_BEP20** (float) - Balance of USDC on BNB Chain. - **USDT_SOL** (float) - Balance of USDT on Solana. - **USDC_SOL** (float) - Balance of USDC on Solana. ### Request Example ```python from kryptoexpress import KryptoExpressClient client = KryptoExpressClient(api_key="your-api-key") wallet = client.wallet.get() print(f"BTC: {wallet.BTC}") print(f"ETH: {wallet.ETH}") print(f"USDT_ERC20: {wallet.USDT_ERC20}") ``` #### Response Example ```json { "BTC": 1.5, "ETH": 10.2, "LTC": 50.0, "SOL": 200.0, "BNB": 75.5, "TRX": 10000.0, "DOGE": 50000.0, "USDT_ERC20": 5000.0, "USDC_ERC20": 4500.0, "USDT_BEP20": 3000.0, "USDC_BEP20": 3200.0, "USDT_SOL": 2000.0, "USDC_SOL": 2100.0 } ``` ``` -------------------------------- ### Get Cryptocurrency Prices Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Retrieve current prices for multiple cryptocurrencies in a specified fiat currency. ```APIDOC ## GET /currencies/prices ### Description Retrieve current prices for multiple cryptocurrencies in a specified fiat currency. ### Method GET ### Endpoint /currencies/prices ### Query Parameters - **crypto_currencies** (array) - Required - A list of cryptocurrency symbols (e.g., ['BTC', 'ETH']). - **fiat_currency** (string) - Required - The fiat currency to get prices in (e.g., 'USD', 'EUR'). ### Response #### Success Response (200) - **prices** (array) - A list of price objects, each containing: - **crypto_currency** (string) - The cryptocurrency symbol. - **fiat_currency** (string) - The fiat currency symbol. - **price** (number) - The current price. ### Response Example ```json { "prices": [ { "crypto_currency": "BTC", "fiat_currency": "USD", "price": 50000.50 }, { "crypto_currency": "ETH", "fiat_currency": "USD", "price": 3000.75 } ] } ``` ``` -------------------------------- ### Get Wallet Balances Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Retrieve current wallet balances for all supported cryptocurrencies. The wallet model includes additional currency keys for forward compatibility. An asynchronous version is also available. ```python from kryptoexpress import KryptoExpressClient client = KryptoExpressClient(api_key="your-api-key") wallet = client.wallet.get() print(f"BTC: {wallet.BTC}") print(f"ETH: {wallet.ETH}") print(f"LTC: {wallet.LTC}") print(f"SOL: {wallet.SOL}") print(f"BNB: {wallet.BNB}") print(f"TRX: {wallet.TRX}") print(f"DOGE: {wallet.DOGE}") print(f"USDT_ERC20: {wallet.USDT_ERC20}") print(f"USDC_ERC20: {wallet.USDC_ERC20}") print(f"USDT_BEP20: {wallet.USDT_BEP20}") print(f"USDC_BEP20: {wallet.USDC_BEP20}") print(f"USDT_SOL: {wallet.USDT_SOL}") print(f"USDC_SOL: {wallet.USDC_SOL}") # Async version async def get_wallet_async(): async with AsyncKryptoExpressClient(api_key="your-api-key") as client: return await client.wallet.get() ``` -------------------------------- ### Get Payment by Hash Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Retrieve payment details using the unique payment hash. This is a public endpoint and does not require authentication. An asynchronous version is also available. ```python from kryptoexpress import KryptoExpressClient client = KryptoExpressClient(api_key="your-api-key") payment = client.payments.get_by_hash("abc123def456...") print(f"Payment ID: {payment.id}") print(f"Payment Type: {payment.payment_type.value}") print(f"Is Paid: {payment.is_paid}") print(f"Is Withdrawn: {payment.is_withdrawn}") print(f"Fiat Amount: {payment.fiat_amount} {payment.fiat_currency.value}") print(f"Crypto Amount: {payment.crypto_amount} {payment.crypto_currency.value}") print(f"Created: {payment.create_datetime}") print(f"Paid At: {payment.paid_at}") # Async version async def get_payment_async(payment_hash: str): async with AsyncKryptoExpressClient(api_key="your-api-key") as client: return await client.payments.get_by_hash(payment_hash) ``` -------------------------------- ### Get Payment by Hash Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Retrieves the details of a specific payment using its unique transaction hash. This is a public endpoint. ```APIDOC ## GET /api/v1/payments/{payment_hash} ### Description Retrieves payment details using the unique payment hash. This is a public endpoint. ### Method GET ### Endpoint /api/v1/payments/{payment_hash} ### Parameters #### Path Parameters - **payment_hash** (string) - Required - The unique hash of the payment to retrieve. ### Request Example ```python from kryptoexpress import KryptoExpressClient client = KryptoExpressClient(api_key="your-api-key") payment = client.payments.get_by_hash("abc123def456...") print(f"Payment ID: {payment.id}") print(f"Payment Type: {payment.payment_type.value}") print(f"Is Paid: {payment.is_paid}") print(f"Is Withdrawn: {payment.is_withdrawn}") print(f"Fiat Amount: {payment.fiat_amount} {payment.fiat_currency.value}") print(f"Crypto Amount: {payment.crypto_amount} {payment.crypto_currency.value}") print(f"Created: {payment.create_datetime}") print(f"Paid At: {payment.paid_at}") ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the payment. - **payment_type** (string) - Type of payment. - **is_paid** (boolean) - Indicates if the payment has been paid. - **is_withdrawn** (boolean) - Indicates if the payment has been withdrawn. - **fiat_amount** (float) - The amount in fiat currency. - **fiat_currency** (FiatCurrency) - The fiat currency of the payment. - **crypto_amount** (float) - The amount in cryptocurrency. - **crypto_currency** (CryptoCurrency) - The cryptocurrency used for the payment. - **create_datetime** (string) - The date and time the payment was created. - **paid_at** (string) - The date and time the payment was paid. #### Response Example ```json { "id": "pay_abc123", "payment_type": "PAYMENT", "is_paid": true, "is_withdrawn": false, "fiat_amount": 100.00, "fiat_currency": "USD", "crypto_amount": 0.003, "crypto_currency": "USDT_ERC20", "create_datetime": "2023-10-27T10:00:00Z", "paid_at": "2023-10-27T10:05:00Z" } ``` ``` -------------------------------- ### Get Cryptocurrency Prices Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Retrieve current prices for multiple cryptocurrencies in a specified fiat currency. Supports fetching prices for various crypto and fiat currency combinations. An async version is also available. ```python from kryptoexpress import KryptoExpressClient from kryptoexpress.models.common import CryptoCurrency, FiatCurrency client = KryptoExpressClient(api_key="your-api-key") # Get prices for multiple cryptocurrencies prices = client.currencies.get_prices( crypto_currencies=[ CryptoCurrency.BTC, CryptoCurrency.ETH, CryptoCurrency.LTC, CryptoCurrency.SOL, ], fiat_currency=FiatCurrency.USD, ) for price in prices.prices: print(f"{price.crypto_currency.value}: ${price.price:.2f} {price.fiat_currency.value}") # Get prices in EUR eur_prices = client.currencies.get_prices( crypto_currencies=[CryptoCurrency.BTC, CryptoCurrency.ETH], fiat_currency=FiatCurrency.EUR, ) for price in eur_prices.prices: print(f"{price.crypto_currency.value}: €{price.price:.2f}") # Async version async def get_prices_async(): async with AsyncKryptoExpressClient(api_key="your-api-key") as client: return await client.currencies.get_prices( crypto_currencies=[CryptoCurrency.BTC], fiat_currency=FiatCurrency.USD, ) ``` -------------------------------- ### Client Initialization Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Import and initialize both synchronous (`KryptoExpressClient`) and asynchronous (`AsyncKryptoExpressClient`) clients. Authentication is handled via the `X-Api-Key` header. ```python from kryptoexpress import AsyncKryptoExpressClient, KryptoExpressClient ``` -------------------------------- ### Create a Deposit Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Use the shortcut method to create a new deposit. Fiat and crypto amounts are initially None until funds are received. ```python deposit = client.payments.create_deposit( crypto_currency=CryptoCurrency.ETH, fiat_currency=FiatCurrency.USD, callback_url="https://example.com/webhook/deposit", ) print(f"Deposit ID: {deposit.id}") print(f"Deposit Address: {deposit.address}") print(f"Hash: {deposit.hash}") # fiat_amount and crypto_amount are None until funds arrive print(f"Fiat Amount: {deposit.fiat_amount}") # None initially ``` -------------------------------- ### Create Deposit Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Demonstrates how to create a deposit using the shortcut method, specifying crypto and fiat currencies, and a callback URL. ```APIDOC ## POST /api/v1/payments/deposit ### Description Creates a new deposit request. This method is a shortcut for initiating a deposit. ### Method POST ### Endpoint /api/v1/payments/deposit ### Parameters #### Query Parameters - **crypto_currency** (CryptoCurrency) - Required - The cryptocurrency for the deposit. - **fiat_currency** (FiatCurrency) - Required - The fiat currency for the deposit. - **callback_url** (string) - Required - The URL to receive deposit notifications. ### Request Example ```python from kryptoexpress import KryptoExpressClient from kryptoexpress.models.common import CryptoCurrency, FiatCurrency client = KryptoExpressClient(api_key="your-api-key") deposit = client.payments.create_deposit( crypto_currency=CryptoCurrency.ETH, fiat_currency=FiatCurrency.USD, callback_url="https://example.com/webhook/deposit", ) print(f"Deposit ID: {deposit.id}") print(f"Deposit Address: {deposit.address}") print(f"Hash: {deposit.hash}") print(f"Fiat Amount: {deposit.fiat_amount}") ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the deposit. - **address** (string) - The deposit address. - **hash** (string) - The transaction hash (if available). - **fiat_amount** (float) - The fiat amount of the deposit (initially None). - **crypto_amount** (float) - The crypto amount of the deposit (initially None). #### Response Example ```json { "id": "dep_12345abc", "address": "0x123...", "hash": null, "fiat_amount": null, "crypto_amount": null } ``` ``` -------------------------------- ### Create a Deposit Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Create a deposit using `PaymentCreateRequest.for_deposit`. For deposits, `fiatAmount` and `cryptoAmount` can be `None` initially. ```python deposit = client.payments.create( PaymentCreateRequest.for_deposit( crypto_currency=CryptoCurrency.BTC, fiat_currency=FiatCurrency.USD, callback_url="https://example.com/callback", ) ) ``` -------------------------------- ### Create Deposit Shortcut Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Use the `create_deposit` shortcut for creating deposits. This method simplifies the process of initiating a deposit transaction. ```python deposit_shortcut = client.payments.create_deposit( crypto_currency=CryptoCurrency.BTC, fiat_currency=FiatCurrency.USD, callback_url="https://example.com/callback", ) ``` -------------------------------- ### Create Stablecoin Payment Shortcut Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Use the `create_payment` shortcut for stablecoin payments. This provides a streamlined way to initiate stablecoin transactions. ```python stablecoin_shortcut = client.payments.create_payment( crypto_currency=CryptoCurrency.USDT_ERC20, fiat_currency=FiatCurrency.USD, fiat_amount=15.0, callback_url="https://example.com/callback", ) ``` -------------------------------- ### Create KryptoExpress Payment (Shortcut Method) Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Use the shortcut method `client.payments.create_payment` for a more direct way to create a payment request. This method simplifies the creation process by directly accepting payment parameters. ```python # Using the shortcut method payment = client.payments.create_payment( crypto_currency=CryptoCurrency.ETH, fiat_currency=FiatCurrency.EUR, fiat_amount=100.00, callback_url="https://example.com/webhook/payment", payment_behavior=PaymentBehavior.OVERPAYMENT, ) print(f"Payment ID: {payment.id}") print(f"Address: {payment.address}") print(f"Crypto Amount: {payment.crypto_amount} {payment.crypto_currency.value}") print(f"Hash: {payment.hash}") print(f"Expires: {payment.expire_datetime}") ``` -------------------------------- ### Initialize KryptoExpress Python Client Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Initialize the synchronous or asynchronous client with your API key. Custom configurations for base URL, timeout, retries, and fiat converters are supported. Use context managers for automatic resource cleanup. ```python from kryptoexpress import KryptoExpressClient, AsyncKryptoExpressClient from kryptoexpress.models.common import FiatCurrency # Synchronous client with default settings client = KryptoExpressClient(api_key="your-api-key") # Synchronous client with custom configuration client = KryptoExpressClient( api_key="your-api-key", base_url="https://kryptoexpress.pro/api", timeout=30.0, max_retries=3, ) # Custom fiat converter for non-USD minimum amount validation def fiat_converter(amount: float, from_currency: FiatCurrency, to_currency: FiatCurrency) -> float: rates = {(FiatCurrency.USD, FiatCurrency.EUR): 0.91} return amount * rates.get((from_currency, to_currency), 1.0) client = KryptoExpressClient( api_key="your-api-key", fiat_converter=fiat_converter, ) # Using context manager for automatic resource cleanup with KryptoExpressClient(api_key="your-api-key") as client: wallet = client.wallet.get() print(f"BTC balance: {wallet.BTC}") # Asynchronous client async_client = AsyncKryptoExpressClient(api_key="your-api-key") # Async context manager usage async with AsyncKryptoExpressClient(api_key="your-api-key") as client: wallet = await client.wallet.get() print(f"ETH balance: {wallet.ETH}") ``` -------------------------------- ### Create KryptoExpress Deposit (Factory Method) Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Use the factory method `PaymentCreateRequest.for_deposit` to create a deposit request when the incoming crypto amount is unknown. This is suitable for receiving variable amounts or donations. ```python from kryptoexpress import KryptoExpressClient from kryptoexpress.models.common import CryptoCurrency, FiatCurrency from kryptoexpress.models.payments import PaymentCreateRequest client = KryptoExpressClient(api_key="your-api-key") # Using the factory method deposit = client.payments.create( PaymentCreateRequest.for_deposit( crypto_currency=CryptoCurrency.BTC, fiat_currency=FiatCurrency.USD, callback_url="https://example.com/webhook/deposit", callback_secret="deposit_secret_456", ) ) ``` -------------------------------- ### Create Custom Minimum Amount Policy with Sync Converter Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Sets up a custom minimum amount policy for payments, including a synchronous converter function to validate non-USD amounts against the 1 USD minimum. Useful for handling different fiat currencies. ```python from kryptoexpress import KryptoExpressClient, MinimumAmountPolicy from kryptoexpress.models.common import CryptoCurrency, FiatCurrency # Simple callable converter def simple_converter(amount: float, from_currency: FiatCurrency, to_currency: FiatCurrency) -> float: rates = { (FiatCurrency.USD, FiatCurrency.EUR): 0.91, (FiatCurrency.USD, FiatCurrency.GBP): 0.79, (FiatCurrency.EUR, FiatCurrency.USD): 1.10, (FiatCurrency.GBP, FiatCurrency.USD): 1.27, } return amount * rates.get((from_currency, to_currency), 1.0) # Create custom policy custom_policy = MinimumAmountPolicy( minimum_amount_usd=1.0, sync_converter=simple_converter, ) client = KryptoExpressClient( api_key="your-api-key", minimum_amount_policy=custom_policy, ) # Now EUR payments will be validated against the 1 USD minimum payment = client.payments.create_payment( crypto_currency=CryptoCurrency.BTC, fiat_currency=FiatCurrency.EUR, fiat_amount=5.00, # Will be validated callback_url="https://example.com/webhook", ) ``` -------------------------------- ### Shortcut for Withdrawal All Dry Run Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md A shortcut method is available for simulating a withdrawal of all funds, simplifying the process. ```python withdraw_all_shortcut = client.wallet.withdraw_all( crypto_currency=CryptoCurrency.BTC, to_address="bc1destination", ) ``` -------------------------------- ### Handle Kryptoexpress SDK Exceptions Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Demonstrates how to catch and handle various exceptions raised by the Kryptoexpress SDK, including validation, API, authentication, and rate limiting errors. Import specific error classes for granular control. ```python from kryptoexpress import KryptoExpressClient from kryptoexpress.models.common import CryptoCurrency, FiatCurrency from kryptoexpress.errors import ( SDKException, APIError, AuthError, NotFoundError, RateLimitError, ValidationError, MinimumAmountError, UnsupportedPaymentModeError, CurrencyConversionError, ) client = KryptoExpressClient(api_key="your-api-key") try: # This will raise MinimumAmountError (amount below 1 USD) payment = client.payments.create_payment( crypto_currency=CryptoCurrency.BTC, fiat_currency=FiatCurrency.USD, fiat_amount=0.50, # Below minimum callback_url="https://example.com/webhook", ) except MinimumAmountError as e: print(f"Minimum amount error: {e.message}") try: # This will raise UnsupportedPaymentModeError (stablecoin deposit not allowed) deposit = client.payments.create_deposit( crypto_currency=CryptoCurrency.USDT_ERC20, fiat_currency=FiatCurrency.USD, callback_url="https://example.com/webhook", ) except UnsupportedPaymentModeError as e: print(f"Unsupported mode: {e.message}") try: payment = client.payments.get_by_hash("invalid-hash") except NotFoundError as e: print(f"Payment not found: {e.message}") except AuthError as e: print(f"Authentication failed: {e.message}, Status: {e.status_code}") except RateLimitError as e: print(f"Rate limited. Retry after: {e.retry_after} seconds") except APIError as e: print(f"API error: {e.message}, Status: {e.status_code}") print(f"Error details: {e.details}") except SDKException as e: print(f"SDK error: {e.message}") ``` -------------------------------- ### Create Asynchronous KryptoExpress Payment Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Create a payment asynchronously using `AsyncKryptoExpressClient`. Ensure the client is used within an async context manager for proper handling. ```python # Async version async def create_async_payment(): async with AsyncKryptoExpressClient(api_key="your-api-key") as client: payment = await client.payments.create_payment( crypto_currency=CryptoCurrency.BTC, fiat_currency=FiatCurrency.USD, fiat_amount=25.00, callback_url="https://example.com/webhook", ) return payment ``` -------------------------------- ### Create Stablecoin Payment Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Create a payment for a stablecoin like USDT_ERC20. The SDK enforces rules such as exact payment semantics for stablecoins. ```python stablecoin_payment = client.payments.create( PaymentCreateRequest.for_payment( crypto_currency=CryptoCurrency.USDT_ERC20, fiat_currency=FiatCurrency.USD, fiat_amount=15.0, callback_url="https://example.com/callback", ) ) ``` -------------------------------- ### Create KryptoExpress Payment (Factory Method) Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Use the factory method `PaymentCreateRequest.for_payment` to create a payment request. This method is recommended for specifying crypto currency, fiat currency, fiat amount, callback URL, and payment behavior. ```python from kryptoexpress import KryptoExpressClient from kryptoexpress.models.common import CryptoCurrency, FiatCurrency, PaymentBehavior from kryptoexpress.models.payments import PaymentCreateRequest client = KryptoExpressClient(api_key="your-api-key") # Using the factory method (recommended) payment = client.payments.create( PaymentCreateRequest.for_payment( crypto_currency=CryptoCurrency.BTC, fiat_currency=FiatCurrency.USD, fiat_amount=50.00, callback_url="https://example.com/webhook/payment", callback_secret="my_webhook_secret_123", payment_behavior=PaymentBehavior.EXACT, ) ) ``` -------------------------------- ### List Supported Cryptocurrencies Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Retrieve lists of supported cryptocurrencies, including all currencies, native coins only, or stablecoins only. An async version is also available. ```python from kryptoexpress import KryptoExpressClient client = KryptoExpressClient(api_key="your-api-key") # Get all supported cryptocurrencies all_currencies = client.currencies.list_all() print("All cryptocurrencies:") for currency in all_currencies: print(f" - {currency.value}") # Get only native cryptocurrencies (BTC, ETH, LTC, etc.) native_currencies = client.currencies.list_native() print("\nNative cryptocurrencies:") for currency in native_currencies: print(f" - {currency.value}") # Get only stablecoins (USDT, USDC variants) stablecoins = client.currencies.list_stable() print("\nStablecoins:") for currency in stablecoins: print(f" - {currency.value}") # Async version async def list_currencies_async(): async with AsyncKryptoExpressClient(api_key="your-api-key") as client: all_currencies = await client.currencies.list_all() native = await client.currencies.list_native() stable = await client.currencies.list_stable() return all_currencies, native, stable ``` -------------------------------- ### Implement Custom Fiat Converter Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Provide a custom callable or adapter to convert fiat amounts if stricter non-USD pre-validation is needed. This converter is passed during client initialization. ```python from kryptoexpress import KryptoExpressClient from kryptoexpress.models.common import FiatCurrency def fiat_converter(amount: float, from_currency: FiatCurrency, to_currency: FiatCurrency) -> float: if from_currency is FiatCurrency.USD and to_currency is FiatCurrency.EUR: return 0.91 raise RuntimeError("unsupported conversion") client = KryptoExpressClient( api_key="your-api-key", fiat_converter=fiat_converter, ) ``` -------------------------------- ### Initiate Withdrawal All Dry Run Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Use typed requests for `WithdrawalAllRequest` to simulate a withdrawal of all available funds. The `only_calculate` parameter can be set to `False` to perform a dry run. ```python withdraw_all = client.wallet.withdraw( WithdrawalAllRequest( crypto_currency=CryptoCurrency.BTC, to_address="bc1destination", only_calculate=False, ) ) ``` -------------------------------- ### Shortcut for Single Withdrawal Dry Run Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md A shortcut method is available for calculating single withdrawals, simulating the transaction without actual execution. ```python dry_run_shortcut = client.wallet.calculate_single( payment_id=123, crypto_currency=CryptoCurrency.BTC, to_address="bc1destination", ) ``` -------------------------------- ### Create Custom Minimum Amount Policy with Protocol-Based Converter Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Defines a custom minimum amount policy using a class-based converter for more complex exchange rate lookups, potentially involving external API calls. The policy is initialized with an instance of the converter. ```python from kryptoexpress import KryptoExpressClient, MinimumAmountPolicy from kryptoexpress.models.common import CryptoCurrency, FiatCurrency # Protocol-based converter for more complex scenarios class ExchangeRateConverter: def __init__(self, api_url: str): self.api_url = api_url def convert(self, amount: float, from_currency: FiatCurrency, to_currency: FiatCurrency) -> float: # Implement actual exchange rate lookup return amount * 0.91 # Placeholder converter = ExchangeRateConverter("https://api.exchangerates.io") policy = MinimumAmountPolicy(sync_converter=converter) client = KryptoExpressClient( api_key="your-api-key", minimum_amount_policy=policy, ) ``` -------------------------------- ### Create Stablecoin Payments Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Create payments using stablecoins like USDT and USDC on various networks. Stablecoins only support the PAYMENT type with exact payment behavior; deposits and overpayment/split semantics are not allowed. ```python from kryptoexpress import KryptoExpressClient from kryptoexpress.models.common import CryptoCurrency, FiatCurrency from kryptoexpress.models.payments import PaymentCreateRequest client = KryptoExpressClient(api_key="your-api-key") # USDT on Ethereum (ERC20) usdt_payment = client.payments.create_payment( crypto_currency=CryptoCurrency.USDT_ERC20, fiat_currency=FiatCurrency.USD, fiat_amount=100.00, callback_url="https://example.com/webhook", ) # USDC on BNB Chain (BEP20) usdc_payment = client.payments.create_payment( crypto_currency=CryptoCurrency.USDC_BEP20, fiat_currency=FiatCurrency.USD, fiat_amount=50.00, callback_url="https://example.com/webhook", ) # USDT on Solana usdt_sol = client.payments.create_payment( crypto_currency=CryptoCurrency.USDT_SOL, fiat_currency=FiatCurrency.USD, fiat_amount=25.00, callback_url="https://example.com/webhook", ) # Available stablecoins: # CryptoCurrency.USDT_ERC20, CryptoCurrency.USDC_ERC20 # CryptoCurrency.USDT_BEP20, CryptoCurrency.USDC_BEP20 # CryptoCurrency.USDT_SOL, CryptoCurrency.USDC_SOL # CryptoCurrency.USDT_TRC20 ``` -------------------------------- ### List Supported Fiat Currencies Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Retrieve the list of all supported fiat currencies for payment processing. The output includes a comprehensive list of currency codes. ```python from kryptoexpress import KryptoExpressClient client = KryptoExpressClient(api_key="your-api-key") fiat_currencies = client.fiat.list() print("Supported fiat currencies:") for currency in fiat_currencies: print(f" - {currency.value}") # Example output includes: USD, EUR, GBP, JPY, CHF, AUD, CAD, CNY, HKD, SGD, # SEK, NOK, DKK, PLN, CZK, HUF, TRY, INR, KRW, THB, IDR, MYR, PHP, VND, # AED, SAR, ZAR, NGN, KES, GHS, BRL, MXN, ARS, CLP, COP, PEN, RUB, UAH, # ILS, PKR, BDT, LKR, TWD, BHD, KWD, RON, NZD ``` -------------------------------- ### Withdraw All Funds Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Withdraw the entire balance of a cryptocurrency to an external address. Use `calculate_all()` for a dry-run to preview fees before executing the actual withdrawal. A withdrawal can also be initiated using a typed request object. ```python from kryptoexpress import KryptoExpressClient from kryptoexpress.models.common import CryptoCurrency from kryptoexpress.models.wallet import WithdrawalAllRequest client = KryptoExpressClient(api_key="your-api-key") # Dry-run to calculate fees without executing dry_run = client.wallet.calculate_all( crypto_currency=CryptoCurrency.BTC, to_address="bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh", ) print(f"Total Withdrawal: {dry_run.total_withdrawal_amount} BTC") print(f"Receiving Amount: {dry_run.receiving_amount} BTC") print(f"Blockchain Fee: {dry_run.blockchain_fee_amount} BTC") print(f"Service Fee: {dry_run.service_fee_amount} BTC") # Execute the actual withdrawal withdrawal = client.wallet.withdraw_all( crypto_currency=CryptoCurrency.BTC, to_address="bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh", ) print(f"Withdrawal ID: {withdrawal.id}") print(f"Transaction IDs: {withdrawal.tx_id_list}") # Using typed request object withdrawal = client.wallet.withdraw( WithdrawalAllRequest( crypto_currency=CryptoCurrency.ETH, to_address="0x742d35Cc6634C0532925a3b844Bc9e7595f5eAb3", only_calculate=False, ) ) ``` -------------------------------- ### Verify Payment Webhook Signature (FastAPI) Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Handles incoming payment webhooks in a FastAPI application, verifying the signature for security. It uses `request.body()` for the raw data and `request.headers.get()` for the signature. ```python from fastapi import FastAPI, Request, HTTPException app = FastAPI() @app.post("/webhook/payment") async def handle_payment_webhook(request: Request): raw_body = await request.body() x_signature = request.headers.get("X-Signature") if not verify_callback_signature( raw_body=raw_body, callback_secret="my_webhook_secret_123", signature=x_signature, ): raise HTTPException(status_code=401, detail="Invalid signature") payload = await request.json() return {"status": "processed", "payment_id": payload["id"]} ``` -------------------------------- ### List Cryptocurrencies Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Retrieve lists of supported cryptocurrencies - all currencies, native coins only, or stablecoins only. ```APIDOC ## GET /currencies/list ### Description Retrieve lists of supported cryptocurrencies. You can get all currencies, native coins only, or stablecoins only. ### Method GET ### Endpoint /currencies/list ### Query Parameters - **type** (string) - Optional - Filter by currency type: 'all', 'native', or 'stable'. Defaults to 'all'. ### Response #### Success Response (200) - **currencies** (array) - A list of supported cryptocurrency values (e.g., 'BTC', 'ETH', 'USDT'). ### Response Example ```json { "currencies": ["BTC", "ETH", "USDT", "USDC"] } ``` ``` -------------------------------- ### List Fiat Currencies Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Retrieve the list of all supported fiat currencies for payment processing. ```APIDOC ## GET /fiat/list ### Description Retrieve the list of all supported fiat currencies for payment processing. ### Method GET ### Endpoint /fiat/list ### Response #### Success Response (200) - **currencies** (array) - A list of supported fiat currency symbols (e.g., 'USD', 'EUR', 'GBP'). ### Response Example ```json { "currencies": ["USD", "EUR", "GBP", "JPY"] } ``` ``` -------------------------------- ### Verify Callback Signature Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Use the `verify_callback_signature` helper function to verify the authenticity of callbacks received from KryptoExpress. This function requires the raw request body, the callback secret, and the signature from the `X-Signature` header. ```python from kryptoexpress import verify_callback_signature def handle_callback(raw_body: bytes, x_signature: str) -> bool: return verify_callback_signature( raw_body=raw_body, callback_secret="my_super_secret_1234567890", signature=x_signature, ) ``` -------------------------------- ### Create Stablecoin Payment Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Enables the creation of payments using stablecoins like USDT and USDC across different blockchain networks. Supports exact payment behavior only. ```APIDOC ## POST /api/v1/payments/create ### Description Creates a payment using stablecoins. This endpoint only supports the PAYMENT type with EXACT payment behavior. ### Method POST ### Endpoint /api/v1/payments/create ### Parameters #### Query Parameters - **crypto_currency** (CryptoCurrency) - Required - The stablecoin and network (e.g., USDT_ERC20, USDC_BEP20). - **fiat_currency** (FiatCurrency) - Required - The fiat currency for the payment. - **fiat_amount** (float) - Required - The exact amount in fiat currency. - **callback_url** (string) - Required - The URL to receive payment notifications. ### Request Example ```python from kryptoexpress import KryptoExpressClient from kryptoexpress.models.common import CryptoCurrency, FiatCurrency client = KryptoExpressClient(api_key="your-api-key") # USDT on Ethereum (ERC20) usdt_payment = client.payments.create_payment( crypto_currency=CryptoCurrency.USDT_ERC20, fiat_currency=FiatCurrency.USD, fiat_amount=100.00, callback_url="https://example.com/webhook", ) # USDC on BNB Chain (BEP20) usdc_payment = client.payments.create_payment( crypto_currency=CryptoCurrency.USDC_BEP20, fiat_currency=FiatCurrency.USD, fiat_amount=50.00, callback_url="https://example.com/webhook", ) ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the payment. - **payment_type** (string) - Type of payment (e.g., 'PAYMENT'). - **crypto_currency** (CryptoCurrency) - The cryptocurrency used for the payment. - **fiat_currency** (FiatCurrency) - The fiat currency of the payment. - **fiat_amount** (float) - The amount in fiat currency. - **crypto_amount** (float) - The amount in cryptocurrency (may be null until paid). - **address** (string) - The payment address. - **callback_url** (string) - The callback URL. - **status** (string) - The current status of the payment. #### Response Example ```json { "id": "pay_abc123", "payment_type": "PAYMENT", "crypto_currency": "USDT_ERC20", "fiat_currency": "USD", "fiat_amount": 100.00, "crypto_amount": null, "address": "0xabc...", "callback_url": "https://example.com/webhook", "status": "PENDING" } ``` ``` -------------------------------- ### Verify Payment Webhook Signature (Flask) Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Handles incoming payment webhooks in a Flask application by verifying the signature to ensure authenticity. Requires the raw request body, the 'X-Signature' header, and the callback secret. ```python from flask import Flask, request app = Flask(__name__) @app.route("/webhook/payment", methods=["POST"]) def handle_payment_webhook(): raw_body = request.get_data() x_signature = request.headers.get("X-Signature") callback_secret = "my_webhook_secret_123" # Same secret used when creating payment is_valid = verify_callback_signature( raw_body=raw_body, callback_secret=callback_secret, signature=x_signature, ) if not is_valid: return {"error": "Invalid signature"}, 401 # Process the verified webhook payload import json payload = json.loads(raw_body) print(f"Payment {payload['id']} status updated") return {"status": "ok"}, 200 ``` -------------------------------- ### Verify Callback Signature Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Verify the HMAC-SHA512 signature on webhook callbacks to ensure they originated from KryptoExpress. The signature is provided in the X-Signature header. ```APIDOC ## POST /webhooks/verify ### Description Verify the HMAC-SHA512 signature on webhook callbacks to ensure they originated from KryptoExpress. The signature is provided in the X-Signature header. ### Method POST ### Endpoint /webhooks/verify ### Parameters #### Request Headers - **X-Signature** (string) - Required - The HMAC-SHA512 signature provided by KryptoExpress. #### Request Body - **payload** (string) - Required - The raw request body of the webhook. ### Response #### Success Response (200) - **isValid** (boolean) - True if the signature is valid, false otherwise. ### Response Example ```json { "isValid": true } ``` ``` -------------------------------- ### Verify Callback Signature Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Verify the HMAC-SHA512 signature on webhook callbacks to ensure they originated from KryptoExpress. The signature is provided in the X-Signature header. ```python from kryptoexpress import verify_callback_signature ``` -------------------------------- ### Calculate Withdrawal Dry Run Source: https://github.com/kryptoexpress/kryptoexpress-python/blob/main/README.md Use typed requests for withdrawals to perform dry runs. The `calculate` method forces `onlyCalculate=true` and acts as an explicit dry-run for single withdrawals. ```python from kryptoexpress.models.wallet import WithdrawalAllRequest, WithdrawalSingleRequest dry_run = client.wallet.calculate( WithdrawalSingleRequest( payment_id=123, crypto_currency=CryptoCurrency.BTC, to_address="bc1destination", only_calculate=False, ) ) ``` -------------------------------- ### Withdraw All Funds Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Allows withdrawing the entire balance of a cryptocurrency to a specified external address. Includes a dry-run option to preview fees. ```APIDOC ## POST /api/v1/wallet/withdraw/all ### Description Withdraws the entire balance of a cryptocurrency to an external address. Use `calculate_all()` for a dry-run to preview fees. ### Method POST ### Endpoint /api/v1/wallet/withdraw/all ### Parameters #### Request Body - **crypto_currency** (CryptoCurrency) - Required - The cryptocurrency to withdraw. - **to_address** (string) - Required - The external address to send the funds to. - **only_calculate** (boolean) - Optional - If true, only calculates fees without executing the withdrawal. ### Request Example (Dry Run) ```python from kryptoexpress import KryptoExpressClient from kryptoexpress.models.common import CryptoCurrency client = KryptoExpressClient(api_key="your-api-key") dry_run = client.wallet.calculate_all( crypto_currency=CryptoCurrency.BTC, to_address="bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh", ) print(f"Total Withdrawal: {dry_run.total_withdrawal_amount} BTC") print(f"Receiving Amount: {dry_run.receiving_amount} BTC") print(f"Blockchain Fee: {dry_run.blockchain_fee_amount} BTC") print(f"Service Fee: {dry_run.service_fee_amount} BTC") ``` ### Request Example (Actual Withdrawal) ```python from kryptoexpress import KryptoExpressClient from kryptoexpress.models.common import CryptoCurrency client = KryptoExpressClient(api_key="your-api-key") withdrawal = client.wallet.withdraw_all( crypto_currency=CryptoCurrency.BTC, to_address="bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh", ) print(f"Withdrawal ID: {withdrawal.id}") print(f"Transaction IDs: {withdrawal.tx_id_list}") ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the withdrawal request. - **tx_id_list** (array) - A list of transaction IDs associated with the withdrawal. - **total_withdrawal_amount** (float) - The total amount to be withdrawn (including fees). - **receiving_amount** (float) - The amount that will be received after fees. - **blockchain_fee_amount** (float) - The fee charged by the blockchain network. - **service_fee_amount** (float) - The service fee charged by Kryptoexpress. #### Response Example ```json { "id": "wd_xyz789", "tx_id_list": ["txid123abc"], "total_withdrawal_amount": 0.1, "receiving_amount": 0.099, "blockchain_fee_amount": 0.0005, "service_fee_amount": 0.0005 } ``` ``` -------------------------------- ### Withdraw Single Payment Source: https://context7.com/kryptoexpress/kryptoexpress-python/llms.txt Withdraw funds from a specific payment to an external address. Use calculate_single() for a dry-run to preview fees. ```APIDOC ## POST /wallet/withdraw/single ### Description Withdraw funds from a specific payment to an external address. Use `calculate_single()` for a dry-run to preview fees. ### Method POST ### Endpoint /wallet/withdraw/single ### Parameters #### Request Body - **payment_id** (integer) - Required - The ID of the payment to withdraw from. - **crypto_currency** (string) - Required - The cryptocurrency to withdraw (e.g., 'BTC', 'ETH'). - **to_address** (string) - Required - The external address to send the funds to. - **only_calculate** (boolean) - Optional - If true, only calculates fees without executing the withdrawal. ### Request Example ```json { "payment_id": 12345, "crypto_currency": "BTC", "to_address": "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the withdrawal. - **payment_id** (integer) - The ID of the payment the withdrawal originated from. - **tx_id_list** (array) - A list of transaction IDs associated with the withdrawal. #### Response Example ```json { "id": "wd_abc123xyz", "payment_id": 12345, "tx_id_list": ["tx_12345abc"] } ``` ```