概述
换汇服务支持以下场景:- 收款后换汇:将收到的款项转换为结算币种
- 统一结算币种:以单一币种维护账户余额
- 余额再平衡:优化各账户之间的币种分布
接入流程
标准换汇流程如下:第一步:查询可交易币种范围(可选)
接口:GET /v1/pay/convert/currency
Retrieves the list of currencies available for conversion. This step is optional but recommended for user interface initialization and validation.
Query 参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
side | string | No | Filter by buy or sell direction |
响应 字段
The response includes available currencies with precision and amount constraints:minBuyAmount: Minimum buy amount (field precision rules apply)maxBuyAmount: Maximum buy amount (field precision rules apply)minSellAmount: Minimum sell amount (field precision rules apply)maxSellAmount: Maximum sell amount (field precision rules apply)
步骤 2: Query Available 币种 Pairs (Optional)
接口:GET /v1/pay/convert/pair
Retrieves supported trading pairs and exchange rate information.
Query 参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
currency | string | No | Filter pairs by base currency |
side | string | No | Filter by buy or sell direction |
步骤 3: Get Quote
接口:POST /v1/pay/convert/preview
Generates a 报价 for currency conversion. The 报价 includes an expiration timestamp; expired 报价s cannot be used for 订单 creation.
请求 参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
buyCurrency | string | Yes | Target currency to buy |
sellCurrency | string | Yes | Source currency to sell |
buyAmount | string | Conditional | Amount to buy (mutually exclusive with sellAmount) |
sellAmount | string | Conditional | Amount to sell (mutually exclusive with buyAmount) |
buyAmount or sellAmount, but not both.
响应 字段
| 字段 | 类型 | 说明 |
|---|---|---|
quoteId | string | Unique 报价 identifier; required for 订单 creation |
exchangeRate | string | Current exchange rate |
buyAmount | string | Amount in target currency |
sellAmount | string | Amount in source currency |
expirationTime | timestamp | Quote expiration timestamp |
步骤 4: Create Swap Order
接口:POST /v1/pay/convert
Creates a currency conversion 订单 using a valid 报价. This endpoint is idempotent: submitting the same clientReqId multiple times will return the same business result.
请求 参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
quoteId | string | Yes | Quote ID from 步骤 3 |
buyCurrency | string | Yes | Target currency |
sellCurrency | string | Yes | Source currency |
buyAmount | string | Yes | Amount to buy |
sellAmount | string | Yes | Amount to sell |
clientReqId | string | Yes | 商户-generated unique request ID for 幂等性 |
响应 字段
| 字段 | 类型 | 说明 |
|---|---|---|
orderId | string | Platform 订单 number for queries |
clientReqId | string | Echoed from request |
status | string | Initial 订单 status (typically processing) |
buyAmount | string | Final buy amount |
sellAmount | string | Final sell amount |
Example 请求
步骤 5: Query Swap Order
接口:GET /v1/pay/convert/order
Queries the status and details of a swap 订单. Supports multiple query keys for flexibility.
Query 参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
orderId | string | Conditional | Platform 订单 number |
clientReqId | string | Conditional | 商户-generated request ID |
orderId or clientReqId (not both required, but at least one).
响应 字段
| 字段 | 类型 | 说明 |
|---|---|---|
orderId | string | Platform 订单 number |
clientReqId | string | 商户 request ID |
status | string | Order status (see enumeration below) |
buyCurrency | string | Target currency |
sellCurrency | string | Source currency |
buyAmount | string | Final buy amount |
sellAmount | string | Final sell amount |
completionTime | timestamp | Order completion timestamp |
Swap Order 状态 Enumeration
| 状态 | 说明 |
|---|---|
processing | Order is being processed; check back later |
success | Conversion completed successfully; 资金 are now in the account |
failure | Conversion failed; 资金 returned to original account |
Retry and Error 处理方式
处理方式 Uncertain 响应
If a network timeout or uncertain response occurs:- Query first: Use
GET /v1/pay/convert/orderwithclientReqIdororderIdto determine final status - Only 重试 if necessary: Only reuse the same
clientReqIdfor 订单 creation if the query result remains uncertain - Preserve 幂等性: Keep
clientReqIdunchanged to ensure the same business result
Common Failure Scenarios
| Failure Reason | 说明 | Resolution |
|---|---|---|
| Insufficient balance | Account does not have enough 资金 in sell currency | Fund the account or reduce sell amount |
| Unsupported trading pair | 币种 pair is not available | Use a different currency pair |
| Expired 报价 | Quote lifetime has elapsed | Generate a new 报价 using POST /v1/pay/convert/preview |
| Invalid quantity precision | Amount does not match currency precision rules | Adjust amount to match precision requirements |
| Amount limit exceeded | Amount exceeds currency limits | Review limits via GET /v1/pay/convert/currency |
回调 Behavior
The swap capability does not provide 异步 回调s. Final 订单 confirmation must be obtained through the query API (GET /v1/pay/convert/order).
For information on 回调s for other products, see 通知 & 回调.
机构 API Integration
For institutional use cases, swap endpoints are available under the institution namespace:| Capability | Standard 接口 | Institution 接口 |
|---|---|---|
| Create swap 订单 | POST /v1/pay/convert | POST /transfer/open/institution/v1/pay/convert |
| Query swap 订单 | GET /v1/pay/convert/order | GET /transfer/open/institution/v1/pay/convert/order |
Error 处理方式
For comprehensive error codes and resolution steps, refer to 错误码 & 最佳实践.Integration Checklist
- Retrieve available currency pairs from
GET /v1/pay/convert/pair - Implement 报价 retrieval with expiration handling
- Generate unique
clientReqIdfor each swap request - Create swap 订单s with valid 报价s
- Implement query fallback for 订单 confirmation
- Handle all failure scenarios gracefully
- Store 订单 IDs for 对账
- Monitor conversion rates and limits

