Swap Endpoints¶
This section covers API endpoints related to currency swaps. Swap operations allow users to exchange one currency for another within the platform using system-calculated rates. The main advantage of swaps is that they execute almost instantly at the current market rate, without waiting for specific price conditions to be met. Swaps are ideal for users who want to convert funds immediately at the current market price.
Get Available Swap Directions¶
Returns the list of swap directions available to the authenticated user.
Required Permissions¶
allow_swap
Rate Limit¶
30 requests per minute
Response Fields¶
List of swap direction objects.
| Field | Type | Description |
|---|---|---|
code | string | Unique code for the swap direction |
spend_currency | string | Currency code of the currency to spend |
receive_currency | string | Currency code of the currency to receive |
is_enabled | boolean | Whether the swap direction is currently enabled |
spend_precision | integer | Decimal precision for the spend amount |
receive_precision | integer | Decimal precision for the receive amount |
fee_percent | string | Percentage fee for the swap "0.1" means "0.1%" |
min_spend_amount | string | Minimum amount that can be spent |
max_spend_amount | string | Maximum amount that can be spent |
min_receive_amount | string | Minimum amount that can be received |
max_receive_amount | string | Maximum amount that can be received |
spend_rate_value | string | Amount of spend currency for exchange |
receive_rate_value | string | Amount of receive currency for exchange. Both rates fields form proportion, for example: 1 -> 1534 or 4434 -> 1 |
Response Example¶
[
{
"code": "BTC-USDT",
"spend_currency": "BTC",
"receive_currency": "USDT",
"spend_precision": 5,
"receive_precision": 2,
"min_spend_amount": "0.00050000",
"max_spend_amount": null,
"min_receive_amount": "10.00000000",
"max_receive_amount": null,
"is_enabled": true,
"spend_rate_value": "1.00500000",
"receive_rate_value": "20000.00000000",
"fee_percent": "0.40000000"
},
{
"code": "USDT-BTC",
"spend_currency": "USDT",
"receive_currency": "BTC",
"spend_precision": 2,
"receive_precision": 5,
"min_spend_amount": "10.00000000",
"max_spend_amount": null,
"min_receive_amount": "0.00050000",
"max_receive_amount": null,
"is_enabled": true,
"spend_rate_value": "20100.00000000",
"receive_rate_value": "1.00000000",
"fee_percent": "0.40000000"
}
]
Response Fields¶
| Field | Type | Description |
|---|---|---|
code | string | Unique code for the swap direction |
spend_currency | string | Currency code of the currency to spend |
receive_currency | string | Currency code of the currency to receive |
is_enabled | boolean | Whether the swap direction is currently enabled |
spend_precision | integer | Decimal precision for the spend amount |
receive_precision | integer | Decimal precision for the receive amount |
fee_percent | string | Percentage fee for the swap |
min_spend_amount | string | Minimum amount that can be spent |
max_spend_amount | string | Maximum amount that can be spent |
min_receive_amount | string | Minimum amount that can be received |
max_receive_amount | string | Maximum amount that can be received |
spend_rate_value | string | Amount of spend currency for exchange |
receive_rate_value | string | Amount of receive currency for exchange |
Create Swap¶
Initiates a swap between two currencies.
Required Permissions¶
allow_swap
Rate Limit¶
300 requests per minute
Request Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
direction | string | Yes | Code of the swap direction (see Get Available Swap Directions) |
spend_amount | string | No* | Amount to spend (*Either spend_amount or receive_amount must be provided) |
receive_amount | string | No* | Amount to receive (*Either spend_amount or receive_amount must be provided) |
callback_url | string | No | URL that will be called with status updates |
custom_id | string | No | Custom identifier for tracking this swap |
time_to_live | integer | No | Validity period in milliseconds (default: 30000) |
Example Request¶
{
"direction": "BTC-USDT",
"spend_amount": "0.01000000",
"callback_url": "https://example.com/callbacks/swaps",
"custom_id": "my-swap-123",
"time_to_live": 30000
}
Response¶
{
"code": "SWP123456",
"custom_id": "my-swap-123",
"callback_url": "https://example.com/callbacks/swaps",
"direction": "BTC-USDT",
"spend_currency": "BTC",
"receive_currency": "USDT",
"spend_amount": "0.01000000",
"receive_amount": "294.85250000",
"fee_amount": "0.73713125",
"fee_currency": "USDT",
"rate": "29485.25",
"status": "open",
"reason_code": null,
"reason_message": null,
"created_at": "2023-01-15T14:30:15Z",
"updated_at": "2023-01-15T14:30:15Z",
"done_at": null,
"expires_at": "2023-01-15T14:30:45Z"
}
Response Fields¶
| Field | Type | Description |
|---|---|---|
code | string | Unique swap code |
custom_id | string | Custom identifier provided in the request |
callback_url | string | URL that will be called with status updates |
direction | string | Swap direction code |
spend_currency | string | Currency code of the currency to spend |
receive_currency | string | Currency code of the currency to receive |
spend_amount | string | Amount to spend |
receive_amount | string | Amount to receive |
spend_rate | string | Amount to spend |
receive_rate | string | Amount to receive |
fee_amount | string | Fee amount |
fee_currency | string | Currency code of the fee |
spend_fee_filled | string | Filled fee for spend currency |
receive_fee_filled | string | Filled fee for receive currency |
spend_filled | string | Filled amount for spend currency |
receive_filled | string | Filled amount for receive currency |
status | string | Current status of the swap |
reason_code | string | Error code (if the swap failed) |
reason_message | string | Error message (if the swap failed) |
created_at | string | Creation timestamp (ISO 8601 format) |
updated_at | string | Last update timestamp (ISO 8601 format) |
done_at | string | Completion timestamp (ISO 8601 format) |
valid_till | string | Expiration timestamp (ISO 8601 format) |
Cancel Swap¶
Cancels a pending swap.
Required Permissions¶
allow_swap
Rate Limit¶
300 requests per minute
Request Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
code | string | Yes* | Unique order code |
custom_id | string | Yes* | Custom identifier |
At least one of the parameters code or custom_id must be provided. If both are provided, the code parameter will be used first.
Example Request¶
Response¶
Same as the swap object. Status may not be changed to cancelled instantly, as the system may need time to process the request. Instead cancel_requested_at will be set to the current time.
List Swaps¶
Returns a list of swaps.
Required Permissions¶
allow_swap
Rate Limit¶
300 requests per minute
Query Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
status | string | No | Filter by status (see Swap Status Values) |
direction | string | No | Filter by direction (see Get Available Swap Directions) |
custom_id | string | No | Filter by custom ID |
start_at | string | No | Filter by start datetime on field created_at (inclusive, ISO 8601 format) |
end_at | string | No | Filter by end datetime on field created_at (inclusive, ISO 8601 format) |
limit | integer | No | Number of results to return (default: 100, max: 200) |
offset | integer | No | Number of results to skip (for pagination) |
Response¶
[
{
"code": "SWP123456",
"custom_id": "my-swap-123",
"callback_url": "https://example.com/callbacks/swaps",
"direction": "BTC-USDT",
"spend_currency": "BTC",
"receive_currency": "USDT",
"spend_rate": "1.0000000",
"receive_rate": "29485.25000000",
"spend_amount": "0.01000000",
"receive_amount": "294.85250000",
"amount_parameter": "spend",
"fee_amount": "0.73713125",
"fee_currency": "USDT",
"spend_filled": "0.01000000",
"receive_filled": "294.85250000",
"spend_fee_filled": "0.00000000",
"receive_fee_filled": "0.73713125",
"status": "success",
"reason_code": null,
"reason_message": null,
"created_at": "2023-01-15T14:30:15Z",
"updated_at": "2023-01-15T14:35:20Z",
"done_at": "2023-01-15T14:35:20Z",
"valid_till": "2023-01-15T14:30:45Z",
"cancel_requested_at": null
}
// More swaps...
]
Response Fields¶
Same as the create swap response. The results are returned as a direct array without pagination metadata.
Pagination¶
The API uses simple offset-based pagination with limit and offset parameters. Offset is limited for maximum 10000, if you set more - error will be returned. The default limit is 100, and the maximum limit is 200. The response is a direct list of swap objects without pagination metadata wrapper. If you need to fetch more than 200 swaps, you should use the start_at and end_at parameters to fetch swaps in smaller date ranges. List is sorted by creation date in descending order.
Get Swap Details¶
Returns details of a specific swap.
Required Permissions¶
allow_swap
Rate Limit¶
300 requests per minute
Path Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
code | string | Yes | Unique swap code |
Response¶
Same as a single swap object from the list endpoint.
Swap Status Values¶
| Status | Description |
|---|---|
open | Swap is open and being processed |
success | Swap has been successfully completed |
failed | Swap has failed (see reason_code for details) |
Callback Notifications¶
If a callback_url was provided when creating the swap, the system will send POST requests to this URL when the swap status changes.
Important Note: You may not receive callbacks for every intermediate status change or field update if changes occur very rapidly. When operations transition through multiple states quickly, intermediate callbacks may be skipped. However, you will always receive callbacks for the final states of operations. Design your callback handling to be idempotent and not dependent on receiving every single state transition.
Callback Security
Currently, callbacks are not signed. The signature mechanism for callbacks is planned for a future update. You should validate callback data by making an authenticated API request to verify the swap status.
Callback Payload¶
The callback payload contains the same data as the swap details response, with essential fields for status updates:
{
"code": "SWP123456",
"custom_id": "my-swap-123",
"callback_url": "https://example.com/callbacks/swaps",
"direction": "BTC-USDT",
"spend_currency": "BTC",
"receive_currency": "USDT",
"spend_rate": "1.0000000",
"receive_rate": "29485.25000000",
"spend_amount": "0.01000000",
"receive_amount": "294.85250000",
"amount_parameter": "spend",
"fee_amount": "0.73713125",
"fee_currency": "USDT",
"spend_filled": "0.01000000",
"receive_filled": "294.85250000",
"spend_fee_filled": "0.00000000",
"receive_fee_filled": "0.73713125",
"status": "success",
"reason_code": null,
"reason_message": null,
"created_at": "2023-01-15T14:30:15Z",
"updated_at": "2023-01-15T14:35:20Z",
"done_at": "2023-01-15T14:35:20Z",
"valid_till": "2023-01-15T14:30:45Z",
"cancel_requested_at": null
}
Securing Callbacks¶
Since callbacks are not currently signed, you should implement these security measures:
- Whitelist IPs: Accept callbacks only from the service's IP addresses. Contact support to get the list of server IPs.
- Verify Data: Always make an authenticated API request to
/swap/{code}to verify the status and details of any swap after receiving a callback. - Use HTTPS: Ensure your callback URL uses HTTPS to encrypt the data in transit.
Common Use Cases¶
- Currency conversion: Convert one currency to another
- Price discovery: Get current exchange rates
- Trade execution: Execute trades at current market rates