Testing Swaps
Test FX quotes, quoted swaps, direct live-rate swaps, cross-country swaps, idempotency, and error paths in sandbox.
Quote 100 USD in KES, execute the swap, then replay the request to verify that it settles once. Sandbox has separate balances and lets you start with an unfunded account.
Set up your sandbox session
- Generate a bearer token at
POST /api/sandbox/b2b/auth/generate-bearer-tokenand setHC_SANDBOX_TOKENin your shell. - Use Bash or Zsh with
curl,jq, anduuidgen. Run the blocks in order in the same shell. - Generate the identifiers below once per walkthrough. Keep them for the replay.
base_url='https://api-v2.honeycoin.app/api/sandbox/b2b'
run_id="$(uuidgen)"
swap_ref="sbx-kes-$run_id"
swap_key="swap-$run_id"1. Create a quote
quote=$(curl -fsS "$base_url/quotes" \
-H "Authorization: Bearer $HC_SANDBOX_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"type": "swap",
"senderAmount": 100,
"senderCurrency": "USD",
"receiverCurrency": "KES"
}')
quote_id=$(jq -er '.data.id' <<< "$quote")
jq '.data | {id, status, receiverAmount, exchangeRate, expiresAt}' <<< "$quote"Expect active. The receiver amount and exchange rate come from the quote. Execute the next step before expiresAt (Unix milliseconds). If the quote expires unused, create a fresh one.
2. Execute the swap
swap_body=$(jq -nc --arg id "$quote_id" --arg ref "$swap_ref" \
'{quoteId: $id, externalReference: $ref}')
swap=$(curl -fsS "$base_url/swaps" \
-H "Authorization: Bearer $HC_SANDBOX_TOKEN" \
-H "X-Idempotency-Key: $swap_key" \
-H 'Content-Type: application/json' \
-d "$swap_body")
swap_id=$(jq -er '.data.id' <<< "$swap")
jq '.data | {id, status, senderBalanceAfter, receiverBalanceAfter}' <<< "$swap"Expect successful. An initially unfunded USD balance can become negative in sandbox. To test a retry, rerun step 2 with the same variables. The response should contain the original swap ID and balance snapshots.
3. Verify the transaction and quote
curl -fsS "$base_url/transactions/$swap_id" \
-H "Authorization: Bearer $HC_SANDBOX_TOKEN" \
| jq '.data | {type, externalReference}'
curl -fsS "$base_url/quotes/$quote_id" \
-H "Authorization: Bearer $HC_SANDBOX_TOKEN" \
| jq '.data | {status, consumedAt, consumedById}'| Read | Expected result |
|---|---|
| Transaction | type is swap and externalReference matches $swap_ref. |
| Quote | status is consumed, consumedAt is populated, and consumedById matches $swap_id. |
Try a direct swap
Send either body below to POST /api/sandbox/b2b/swaps with your sandbox bearer token, JSON content type, and a fresh X-Idempotency-Key. Choose a unique externalReference each time you start a new swap.
Buy USDC with USD. Expect 201 Created, data.quoteId: null, and data.receiverCountry: null.
{
"senderAmount": 100,
"senderCurrency": "USD",
"receiverCurrency": "USDC",
"externalReference": "sbx-usdc-001"
}Move XOF from Benin to Senegal. Expect 201 Created. Check the debit on the BJ ledger and the credit on the SN ledger.
{
"senderAmount": 10000,
"senderCurrency": "XOF",
"senderCountry": "BJ",
"receiverCurrency": "XOF",
"receiverCountry": "SN",
"externalReference": "sbx-xof-001"
}Exercise error handling
For independent swap tests, start with a fresh idempotency key and external reference unless the test calls for reusing one.
| Change to a valid request | Expected HTTP response |
|---|---|
Add senderAmount or a currency or country to a quoted swap | 400 VALIDATION_ERROR |
| Select the same ledger on both legs, or omit the country for XOF | 400 VALIDATION_ERROR |
| Add an unknown body field on either POST | 400 VALIDATION_ERROR |
| Add a query parameter on any quote or swap call | 400 QUERY_VALIDATION_ERROR |
| Use a malformed quote ID in the GET path | 400 PARAMS_VALIDATION_ERROR |
Submit an unused quote after its expiresAt | 422 QUOTE_EXPIRED |
| Submit a consumed quote again using a fresh reference and key | 409 CONFLICT |
| Submit another direct swap with an existing reference and a fresh key | 409 CONFLICT |
Updated about 3 hours ago
