Skip to main content
Use the swap endpoints to exchange one cryptocurrency or network balance for another directly within your PeerPesa wallet. For example, you can swap USDC on Stellar for cUSD on Celo, or XLM for USDC on the same network. Swaps use a two-step flow: first request a locked quote that fixes the rate and fees for exactly 30 minutes, then execute the quote. If the market moves beyond your configured slippage tolerance before execution, the swap fails with a slippage_exceeded error.
All requests require an Authorization: Bearer <token> header. POST endpoints accept an optional Idempotency-Key header to prevent duplicate transactions. Amounts are decimal strings. Network codes are uppercase as returned by GET /currencies: STELLAR, CELO, BITCOIN.

Generate a swap quote

Request a quote for swapping one asset to another. The quote locks the rate, minimum received amount, and fees for 30 minutes.

Endpoint

Request headers

string
required
Bearer token
string
Optional unique key to prevent duplicate quote creation

Request body

object
required
Asset you are swapping from
object
required
Asset you are swapping to
string
required
Amount to swap as a decimal string
string
required
Which side the amount refers to: from or to
number
Maximum acceptable slippage as a percentage, e.g. 0.5 for 0.5%. Defaults to the slippage value from GET /currencies or 0.5% if not specified.

Response fields

string
Quote ID, e.g. sq_...
object
object
string
Exchange rate (to per from unit)
string
Minimum amount you are guaranteed to receive, based on slippage
object
Fee breakdown:
number
Slippage percentage used for this quote
string
ISO 8601 timestamp. Quote expires 30 minutes after created_at.
string
ISO 8601 timestamp

Example request

Example response


Execute a swap

Execute a previously generated swap quote to create a swap transaction. The swap deducts the source asset from your balance and credits the target asset.

Endpoint

Request headers

string
required
Bearer token
string
Optional unique key to prevent duplicate execution

Request body

string
required
ID of the swap quote to execute, e.g. sq_7xYz9AbCdEfGhIjK
string
Optional external reference string

Response fields

The response is a wallet transaction object.
string
Transaction ID, e.g. txn_...
string
Always swap
string
pending, processing, completed, failed, or refunded
object
Source asset details:
object
Target asset details:
object
Fee breakdown as in the quote
string
Net target amount received after fees
string
External reference if provided
string
On-chain transaction hash (null until completed)
string
ISO 8601 timestamp
string
ISO 8601 timestamp

Example request

Example response


Understanding slippage

Slippage is the difference between the quoted price and the actual execution price. Market prices can change between quote generation and execution, especially for cross-network swaps. When you request a quote, you set a slippage tolerance as a percentage. If the executable rate moves unfavorably beyond that tolerance before you execute, the API returns a slippage_exceeded error and you must request a fresh quote.
A lower slippage gives you better price protection but increases the chance the quote becomes unexecutable. A higher slippage makes execution more likely but you may receive less than quoted.
The minimum_received field in the quote shows the worst-case amount you are guaranteed to receive if the swap executes within tolerance.

Error codes


Step-by-step flow

1

Request a quote

Call POST /wallet/swap/quote with your from/to assets, amount, and optional slippage tolerance.
2

Review the quote

Check the rate, minimum_received, and fee. The quote is valid for 30 minutes.
3

Execute the quote

Call POST /wallet/swap with the quote_id. No additional balance checks are needed.
4

Track completion

Poll GET /orders/{order_id} or listen for webhook events transaction.processing, transaction.completed, and transaction.failed.