> ## 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"}}`.

# How trading works

> How conversions are priced, why quotes expire in seconds, what atomic execution guarantees, and the questions every integrator asks before building.

Behind the two API calls sits a routing engine: price discovery across centralized exchanges and OTC desks, quote generation with optional locking, atomic execution, and instant wallet settlement. You never touch order books, slippage management, or venue routing; you quote, execute, and confirm.

```mermaid theme={null}
%%{init: {'theme':'base','themeVariables':{'primaryColor':'#E6F7F2','primaryTextColor':'#004233','primaryBorderColor':'#00A57F','lineColor':'#00A57F','secondaryColor':'#CCEEE5','tertiaryColor':'#F2FCF9','fontFamily':'inherit'}}}%%
flowchart TD
    A[Create quote<br/>rate locked briefly] --> B[Submit order<br/>with quote id and price]
    B --> C[Atomic execution<br/>full fill or clean failure]
    C --> D[Balance credited instantly]
    D --> E[trade.completed webhook]
    C -.-> F[trade.failed webhook]
```

## Prices come from routing, not a feed

The `price` on a quote reflects live pricing across venues, routing optimized for reliability and capital efficiency, and any margin configuration on your tier. Treat the quote as the truth for pricing: never reconstruct or cache a rate beyond its `expires_at`. For an indicative rate with no execution promise, read [List all prices](https://www.bitnob.dev/api-reference/trading/list-all-prices.md) instead.

## Market rate or locked quote

| Mode | Behavior |
| - | - |
| Locked quote | Fetch a [quote](https://www.bitnob.dev/docs/trading/create-quote.md) first, execute with its `id` and `price`. The user gets exactly the rate shown. |
| Market rate | Submit the order without a `quote_id`. Executes at the best current rate; the output can vary slightly. |

Lock the quote whenever a user sees a rate before confirming, and whenever you promise a fixed price. An NGN order without a `quote_id` needs a `reference` and fills at the market rate. Quotes expire fast. NGN quotes last 30 seconds in both environments. Crypto quotes last about 10 seconds in production and about 5 minutes in sandbox. Drive a visible countdown from `expires_at` and disable the confirm action when it passes.

## What atomic execution buys you

An order fills completely or fails cleanly; there is no partial state. If the quote expired, the balance is short, or execution errors, no funds move and you get a clean error. Consequently:

* Never debit a user before `trade.completed` arrives.
* A failed trade needs no cleanup, only a fresh quote.
* On NGN pairs, retrying with the same `reference` is safe: it returns the original order. On crypto pairs it can trade twice, so look the order up first. See [Execute a trade](https://www.bitnob.dev/docs/trading/execute-trade.md).

## Amounts and rates

Requests take `quantity` in major units of the base currency: `"0.0001"` BTC, `"10"` USDT, `"5000"` for ₦5,000. The quoted `price` is per unit of base currency in the quote currency, and the `exchange` block on every quote spells out exactly what you send and receive, so display from it rather than computing your own conversion.

## Common questions

> [accordion] Why do quotes expire so quickly?
>
> Markets move. A quote that stayed valid would let callers exploit price changes at Bitnob's expense, so each one carries a short `expires_at`. Executing after expiry fails cleanly with `422` and code `PRECONDITION_FAILED`; fetch a fresh quote. For display-only pricing with no expiry, use [List all prices](https://www.bitnob.dev/api-reference/trading/list-all-prices.md).

> [accordion] What is a spread, and can I add my own?
>
> The spread is the difference between the rate a user gets and the market rate, and it is how trading platforms earn. You can pass Bitnob's rate through untouched or apply your own markup on top before showing it; the quote's rate is the executable floor.

> [accordion] How are prices determined?
>
> From centralized exchanges, OTC desks, and internal routing. You do not manage any of it; the quote you receive is trusted and executable, and your system receives the promised output or nothing.

> [accordion] Can I fetch quotes without trading?
>
> Yes, quotes are free and don't commit you to anything. But for browsing and pricing calculators, use indicative rates instead: [List all prices](https://www.bitnob.dev/api-reference/trading/list-all-prices.md) for crypto pairs and [Get exchange rate](https://www.bitnob.dev/api-reference/exchange-rates/get-single-pair-rate.md) for NGN pairs. Create a quote only when the user is ready to confirm. NGN quotes are checked against your balance and back a single order.

> [accordion] What happens during execution?
>
> Quote validation, balance check, execution, credit to the destination balance, then the `trade.completed` event. Any failure along the way moves no funds.

> [accordion] What am I responsible for as an integrator?
>
> Unique `reference` per trade, no execution of expired quotes, webhook-driven state rather than trusting the synchronous response, and reconciliation of trades against balances. See [Handle trading failures](https://www.bitnob.dev/docs/trading/error-handling-patterns.md).

## A complete sell flow

A user holds 100,000 sats and wants stablecoins:

1. [Create a quote](https://www.bitnob.dev/api-reference/trading/create-quote.md) for the BTC → USDT pair.
2. Show "You'll receive \$45.12" with a countdown from `expires_at`.
3. On confirmation, [submit the order](https://www.bitnob.dev/api-reference/trading/submit-order.md) with the quote `id`, `price`, and your `reference`.
4. On `trade.completed`, credit your ledger and show success.
5. Optionally continue into a [payout](https://www.bitnob.dev/docs/payouts/overview.md) to a bank or mobile money account.


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