Create Swap
Changed onSwaps one token for another in an account or user's wallet, or converts between their fiat balances. Crypto swaps finish in the background — retrieve the swap to follow its status.
Request
- Base URLhttps://api.whop.com/api/v1
- Auth
- HTTP bearer
- or HTTP bearer
- or HTTP bearer
Headers
Pins the request to a dated API version.
A unique key that makes this request safe to retry. See Idempotent requests.
Request body
Business account that makes the swap, prefixed biz_. Provide this or user_id.
Source token amount. Required for a crypto pair: a decimal amount, or all to swap the whole from_token balance in the account's wallet, read from the chain when the swap is created (any token but USDT). An amount above that balance is rejected when the balance can be read. For fiat pairs: the amount of from_token to convert; omit (along with to_amount) to repay the full negative to_token balance instead.
Source chain name or chain ID. Defaults to the source token's chain when omitted.
Source token contract address or ticker symbol, such as "USDT".
Maximum slippage tolerance in basis points.
Fiat pairs only: sizes a partial repayment of the negative to_token balance, denominated in to_token. Must not exceed the debt. Mutually exclusive with amount.
Destination chain name or chain ID. Defaults to the destination token's chain when omitted.
Destination token contract address or ticker symbol, such as "XAUT".
The caller's own user ID, prefixed user_, to swap in their personal account. Provide this or account_id.
Example request
{
"account_id": "biz_xxxxxxxxxxxxxx",
"amount": "100",
"from_chain": "plasma",
"from_token": "usd",
"slippage_bps": 50,
"to_amount": "180.00",
"to_chain": "plasma",
"to_token": "cad"
}Response
swap created
Account that owns the swap: a business ID prefixed biz_, or the user ID for a personal account.
Crypto pairs only: the from_token amount the swap spends, as a decimal string. A request for all returns the wallet balance it read.
Fiat pairs only: amount of the source currency converted. Null while the conversion is settling.
Fiat pairs only: amount credited in the destination currency. Null while the conversion is settling.
Expected destination token amount.
Minimum destination amount after slippage.
Fiat pairs only: the source currency.
Swap ID. Poll GET /swaps/:id for status.
Quoted exchange rate used to create the swap.
Swap status. Crypto swaps start queued. Fiat conversions return complete, or working while the conversion settles.
Destination chain for the swap.
Fiat pairs only: the destination currency.
User whose personal account owns the swap, prefixed user_. Null for a business account.
Example response
{
"account_id": "biz_xxxxxxxxxxxxxx",
"amount": "100.0",
"amount_in": 131.4,
"amount_out": 180,
"amount_out_expected": "98.9",
"amount_out_min": "98.4",
"from_token": {
"symbol": "usd"
},
"id": "vault-swap-cwal_xxxxxxxxxxxxxx",
"object": "swap",
"rate": "0.989",
"status": "queued",
"to_chain": "ethereum",
"to_token": {
"symbol": "cad"
}
}Changes
- info
the security scope
crypto_wallet:swapwas added to the endpoint's security schemebearerAuth - info
the security scope
payout:transfer_fundswas removed from the endpoint's security schemebearerAuth
- info
- info
the security scope
crypto_wallet:swapwas added to the endpoint's security schemebearerAuth
1 more change in this revision
- info