- Users want to lock in the value of their BTC
- You want to stabilize treasury or float in stablecoins
- You’re enabling BTC payments but settling in USDT
Key concepts
Swaps allow users to convert volatile assets (BTC) into stable assets (USDT) inside Bitnob. Bitnob handles the exchange rate matching, balance updates, and fees all through simple API calls. By default, every Bitnob account has a BTC and USDT wallet created automatically. You don’t need to create these.Prerequisites
A Bitnob sandbox or production API key The user must have BTC in their wallet (from on-chain or Lightning) You should track reference IDs for each swapStep 1: Check BTC wallet balance
To confirm the user has sufficient funds to swap, check their BTC balance with Get Balances, or Get Balance By Currency for a single asset.available_balance.
Step 2: Get a swap quote (optional)
You can fetch a live rate before executing the swap with Quotes. This allows you to show the user what they’ll receive.expires_at. You should show this info to the user (rate, amount they’ll receive) before confirming the swap.
Step 3: Execute the quote
To perform the conversion, send a swap request: see Create Order, and Get Order By ID to confirm it settled.Step 4: Confirm stablecoin wallet balance
To verify the updated balance, call:available_balance, pending_balance, total_balance, and currency.
Handling errors
If the user has insufficient BTC, you’ll get a 422 error with a descriptive message If the quote has expired, you’ll be asked to fetch a new one If the wallet is locked or unavailable, the swap will fail Always log the orderid and reference for reconciliation
Best practices
Always fetch a quote before swapping, especially if you’re building a user-facing UI Show a timer for the quote expiry if you use quotes in the front end Clearly display fees and rates for transparency Use unique reference values per swap so you can audit them later Avoid executing back-to-back swaps without confirming balancesSummary
With just a few API calls, you can enable users to:- Convert Bitcoin (on-chain or Lightning) into stablecoins
- Lock in value without withdrawing funds
- Prepare for local spending, bill payments, or off-ramps
Next
Track orders and history
Confirm and reconcile the swap.
Handle trading failures
Before you take this to production.