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

  1. Generate a bearer token at POST /api/sandbox/b2b/auth/generate-bearer-token and set HC_SANDBOX_TOKEN in your shell.
  2. Use Bash or Zsh with curl, jq, and uuidgen. Run the blocks in order in the same shell.
  3. 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}'
ReadExpected result
Transactiontype is swap and externalReference matches $swap_ref.
Quotestatus 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 requestExpected HTTP response
Add senderAmount or a currency or country to a quoted swap400 VALIDATION_ERROR
Select the same ledger on both legs, or omit the country for XOF400 VALIDATION_ERROR
Add an unknown body field on either POST400 VALIDATION_ERROR
Add a query parameter on any quote or swap call400 QUERY_VALIDATION_ERROR
Use a malformed quote ID in the GET path400 PARAMS_VALIDATION_ERROR
Submit an unused quote after its expiresAt422 QUOTE_EXPIRED
Submit a consumed quote again using a fresh reference and key409 CONFLICT
Submit another direct swap with an existing reference and a fresh key409 CONFLICT

Create a Swap · Recover after a timeout or conflict