> ## Documentation Index
> Fetch the complete documentation index at: https://www.bitnob.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Bitnob has two APIs. The Business API (payouts, cards, trading, virtual accounts, stablecoin and bitcoin transfers) is at https://api.bitnob.com. The Enterprise API (non-custodial wallets) is at https://api.platform.bitnob.com.
> Business API auth: sign every request with HMAC-SHA256 and send four headers: `X-Auth-Client` (your client ID), `X-Auth-Timestamp` (Unix seconds), `X-Auth-Nonce` (16 random bytes, hex), and `X-Auth-Signature`, the hex HMAC-SHA256 of `CLIENT_ID:TIMESTAMP:NONCE:BODY` keyed with your client secret. BODY is the exact request body string you send, or an empty string. A missing header, a bad signature, or a timestamp more than about 5 minutes off returns `401`.
> Enterprise API auth: send your key in the `X-API-Key` header. Write requests such as creating a transaction also need an `Idempotency-Key` header, or they fail with `idempotency_key_required` before anything happens.
> Sandbox and production share the Business API base URL. The credentials you sign with select the environment, and `GET /api/whoami` returns it in `data.environment`. Use sandbox credentials in sample code and tests, and never put live credentials in code.
> Amounts are strings unless stated otherwise. Never parse them into floats. Balances, transactions, withdrawals (`POST /api/withdrawals`) and virtual accounts use integer strings in the smallest unit: satoshis for BTC, 6 decimals for USDT and USDC, kobo for NGN, and cents for KES and UGX (100 is 1 KES or 1 UGX). A mobile money collection takes `amount` as a JSON integer in cents.
> Payouts and trading use decimal strings in major units: a payout quote `amount` of `"1"` is 1 USDT, and a trading `quantity` of `"0.0001"` is 0.0001 BTC. Payout responses also carry `cent_amount`, the settlement amount in minor units.
> Card amounts are micro-units (1 USD = 1,000,000). Send them as JSON integers. Card responses return them as integer strings, and card webhooks as integers.
> Generate a unique `reference` for each money movement before the first attempt, and reuse it on retries. A reused reference returns `409` on payout quotes (`ALREADY_EXISTS`), withdrawals (`DUPLICATE_KEY_ERROR`) and card creation (`ALREADY_EXISTS`). It returns the existing record on NGN-pair trading orders, NGN virtual accounts and active mobile money collections. On a mobile money collection that has closed or failed it returns `409` `DUPLICATE_REFERENCE`. It isn't checked on crypto-pair trading orders, so look the order up with `GET /api/trading/orders/{reference}` before resending.
> Quotes expire at `expires_at`; read it from the response instead of assuming a window. An expired trading quote returns `422` `PRECONDITION_FAILED`, and an expired payout quote returns `400` `VALIDATION_ERROR`. Create a new quote rather than retrying. A payout quote can be initialized once, and a trading quote is consumed by the order that fills it.
> Webhooks: verify the `x-bitnob-signature` header, the hex HMAC-SHA512 of the raw request body keyed with your webhook secret, before parsing JSON. Compare in constant time and de-duplicate on `event_id`. A successful API response means accepted: confirm the outcome from the webhook, such as `payouts.withdrawal.success`.
> Errors return `status`, `code` and `detail`. Branch on `code`, never on `detail`. Since the November 5, 2026 response format change, each company gets either the current or the new error codes until its cutoff date, so handle both: `PROVIDER_ERROR` or `PROCESSING_ERROR`, and `BVN_PROVIDER_UNAVAILABLE` or `BVN_VERIFICATION_UNAVAILABLE`. A body that fails to parse returns `{"error": {"code": "BAD_REQUEST"}}`.

# Receive trade webhooks

> Two events carry every trade outcome: trade.completed and trade.failed. Act on them, not on the synchronous order response.

The order response returns immediately, but the outcome arrives as a webhook. Update balances and mark trades settled on `trade.completed`; surface and route failures on `trade.failed`.

| Event | Fires when | Act on it |
| - | - | - |
| `trade.completed` | The trade executed and settled. | Credit your ledger, show success. |
| `trade.failed` | The trade failed: quote expiry, balance, or system error. | Unlock any UI hold, show the reason, offer a re-quote. |

Deliveries are HTTPS POSTs from the addresses listed under [Source IPs](https://www.bitnob.dev/api-reference/webhooks.md#source-ips). Each one carries an `x-bitnob-signature` header: an HMAC SHA-512 of the raw request body, keyed with your webhook secret. Verify it before you parse the body, comparing in constant time, as shown in [Verifying events](https://www.bitnob.dev/docs/stablecoins/address-webhook-events.md).

## Payloads

```json trade.completed theme={null}
{
  "event": "trade.completed",
  "event_id": "944a4089-6065-49ca-8f43-fb10f15c59e6",
  "data": {
    "tradeId": "trd_0a9eab21",
    "reference": "trade_order_4837",
    "from": "usdt",
    "to": "bitcoin",
    "inputAmount": 10000,
    "outputAmount": 225000,
    "rate": 2250,
    "walletId": "wallet_btc_3488",
    "status": "completed",
    "timestamp": "2025-05-16T10:13:45Z"
  }
}
```

```json trade.failed theme={null}
{
  "event": "trade.failed",
  "event_id": "944a4089-6065-49ca-8f43-fb10f15c59e6",
  "data": {
    "tradeId": null,
    "reference": "trade_order_4837",
    "from": "bitcoin",
    "to": "usdt",
    "inputAmount": 500000,
    "reason": "Quote expired",
    "status": "failed",
    "timestamp": "2025-05-16T10:16:22Z"
  }
}
```

`reference` is your join key back to the order you submitted; `reason` on failures carries the cause, for example `Quote expired` or `Insufficient balance`.

## Delivery, retries and ordering

* Return a `200` as soon as the signature checks out, then process. A slow handler times out, and a timeout counts as a failed delivery.
* A `2xx` response marks the event delivered. `400`, `404`, `410`, `422`, and `451` are final and not retried. Anything else, including a timeout, is retried with increasing delays, up to the retry count set on your webhook (1 to 5 attempts in total). After that, delivery stops. See [Retries and duplicates](https://www.bitnob.dev/api-reference/webhooks.md#retries-and-duplicates).
* The same event can arrive more than once. De-duplicate on `event_id`.
* Events can arrive in any order, because a retried delivery may land after a later one. Each trade ends in exactly one terminal event: `trade.completed` or `trade.failed`.
* Retries are finite, so an endpoint that is down for long enough misses events for good. Reconcile anything you still hold as pending with [Get order](https://www.bitnob.dev/api-reference/trading/get-order-by-id-or-reference.md).

## Handler checklist

* Match `reference` against your ledger before mutating anything.
* Log every event with delivery timestamp and processing outcome.
* Reconcile on a schedule, so a missed delivery never strands a trade as pending. [List orders](https://www.bitnob.dev/api-reference/trading/list-orders.md) returns crypto-pair orders only; fetch NGN orders one at a time with [Get order](https://www.bitnob.dev/api-reference/trading/get-order-by-id-or-reference.md).
* Alert internally when `trade.failed` volume spikes; a burst usually means a systemic cause, not user error.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.