> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stablepayfi.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 创建报价并锁定汇率

> 创建报价并锁定汇率

完整[认证、签名、数据约定与错误响应](https://docs.stablepayfi.ai/zh/api/stablecoin-exchange/overview)。每次重试均须重新生成时间戳、nonce 与签名。

`POST /quote` 锁定汇率与费用的单次凭据，有效期见 `expires_at`。

## 请求头

**Authorization** `string` *required*

Bearer API Key。

**X-StablePay-Timestamp** `string` *required*

Unix 秒，允许与服务端相差最多 5 分钟。

**X-StablePay-Nonce** `string` *required*

每次请求唯一的随机串，16–64 字符。

**X-StablePay-Signature** `string` *required*

HMAC-SHA256 签名，小写十六进制；签名必须对应实际发送的请求体。

**Idempotency-Key** `string`

幂等键

## 请求参数

**merchant\_id** `string`

10 位数字

**quote\_type** `string` *required*

`on_ramp`、`off_ramp`、swap

**source\_currency** `string` *required*

卖出币种

**target\_currency** `string` *required*

买入币种

**amount** `integer` *required*

卖出金额，源币种最小单位

**metadata** `object`

自定义元数据

## 响应

**quote\_id** `string` *required*

报价 ID，10 位数字

**quote\_type** `string` *required*

`on_ramp`、`off_ramp`、swap

**source\_currency** `string` *required*

卖出币种

**target\_currency** `string` *required*

买入币种

**source\_amount** `integer` *required*

卖出金额，源币种最小单位

**target\_amount** `integer` *required*

买入金额

**rate** `string` *required*

锁定汇率，十进制字符串

**fee\_amount** `integer` *required*

手续费，源币种最小单位

**fee\_currency** `string` *required*

费用币种

**expires\_at** `integer` *required*

过期时间

**status** `string` *required*

open、used、expired

**metadata** `object`

自定义元数据

**created** `integer` *required*

创建时间

## 状态与错误

400 参数不合法或交易对不支持。

```bash cURL theme={"system"}
curl --request POST \
  --url "https://api.stablepay.co/api/v1/quote" \
  --header "Authorization: Bearer <API_KEY>" \
  --header "X-StablePay-Timestamp: <TIMESTAMP>" \
  --header "X-StablePay-Nonce: <NONCE>" \
  --header "X-StablePay-Signature: <SIGNATURE>" \
  --header "Content-Type: application/json" \
  --data '{
  "quote_type": "on_ramp",
  "source_currency": "USD",
  "target_currency": "USDC",
  "amount": 100500
}'
```

```javascript JavaScript theme={"system"}
const response = await fetch("https://api.stablepay.co/api/v1/quote", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <API_KEY>",
    "X-StablePay-Timestamp": "<TIMESTAMP>",
    "X-StablePay-Nonce": "<NONCE>",
    "X-StablePay-Signature": "<SIGNATURE>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "quote_type": "on_ramp",
    "source_currency": "USD",
    "target_currency": "USDC",
    "amount": 100500
  })
});
console.log(await response.json());
```

```json 200 theme={"system"}
{
  "quote_id": "9000000017",
  "quote_type": "on_ramp",
  "source_currency": "USD",
  "target_currency": "USDC",
  "source_amount": 100500,
  "target_amount": 100479,
  "rate": "0.9998",
  "fee_amount": 5,
  "fee_currency": "USD",
  "expires_at": 1718730000,
  "status": "open",
  "created": 1718726400
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.