# 签名机制

**使用HMAC SHA256对参数进行签名。**

### 需要配置参数

[生成api-key api-secret](/benpay-kai-fa-zhe-zhong-xin/code-demo/sheng-cheng-apikey-apisecret.md)

```
测试配置
api_key AAAAACcVAAABnztMqrATYmlG5XNpNnyY
api_secret 41a2cba262436582f859b1453de08a3c
api_url https://dex-api.benpay.com/

请求需要header
API-KEY
API-SIGNATURE-METHOD HmacSHA256 固定值
API-SIGNATURE-VERSION 1 固定值
API-TIMESTAMP 1751871801483 当前时间戳(ms)
API-Signature 动态生成签名
```

### 签名步骤

#### **所有参数通过 query string 发送**

```
比如请求如下url get请求
https://dex-api.benpay.com/v1/contracts/orders/closed?range=202507&offsetId=0&limit=100

payload - 签名内容
依次拼接method host url sorted-params key signature-method version timestamp
GET
dex-api.benpay.com
/v1/contracts/orders/closed
limit=100&offsetId=0&range=202507
API-KEY: AAAAACcVAAABnztMqrATYmlG5XNpNnyY
API-SIGNATURE-METHOD: HmacSHA256
API-SIGNATURE-VERSION: 1
API-TIMESTAMP: 1751876801442 注意此处需要添加\n

signature aea0677b6b594b06809ab7b6ecb3255a9aaab391fb7653b43a1c2867d9c6a4d3 payload签名信息

header中带上API-Signature，发送请求

请求
curl -X 'GET' \
  'https://dex-api.benpay.com/v1/contracts/orders/closed?limit=100&offsetId=0&range=202507' \
  -H 'accept: */*' \
  -H 'API-KEY: AAAAACcVAAABnztMqrATYmlG5XNpNnyY' \
  -H 'API-SIGNATURE-METHOD: HmacSHA256' \
  -H 'API-SIGNATURE-VERSION: 1' \
  -H 'API-TIMESTAMP: 1751876801442' \
  -H 'API-Signature: aea0677b6b594b06809ab7b6ecb3255a9aaab391fb7653b43a1c2867d9c6a4d3' \
  -d ''

响应
{"success":true,"data":{"hasMore":false,"nextOffsetId":0,"results":[],"range":"202507"}}
```

#### **所有参数通过 request body 发送**

```
比如请求如下url post请求
https://dex-api.benpay.com/v1/contracts/positions/XBTC/settings
body
{"cross":false,"leverage":5}

payload - 签名内容
依次拼接method host url sorted-params key signature-method version timestamp

POST
dex-api.benpay.com
/v1/contracts/positions/XBTC/settings

API-KEY: AAAAACcVAAABnztMqrATYmlG5XNpNnyY
API-SIGNATURE-METHOD: HmacSHA256
API-SIGNATURE-VERSION: 1
API-TIMESTAMP: 1751881676080
{"cross": true, "leverage": 10}

signature 48bb9c5962deac32b5c728d986653e633b5624d025c9c3c419eb3406eb67924d payload签名信息

header中带上API-Signature，发送请求

请求
curl -X 'POST' \
  'https://dex-api.benpay.com/v1/contracts/positions/XBTC/settings' \
  -H 'accept: */*' \
  -H 'API-KEY: AAAAACcVAAABnztMqrATYmlG5XNpNnyY' \
  -H 'API-SIGNATURE-METHOD: HmacSHA256' \
  -H 'API-SIGNATURE-VERSION: 1' \
  -H 'API-TIMESTAMP: 1751881676080' \
  -H 'API-Signature: 48bb9c5962deac32b5c728d986653e633b5624d025c9c3c419eb3406eb67924d' \
  --data-raw '{"cross":false,"leverage":10}'

响应
{'success': True, 'data': {'id': '10005_900000201', 'userId': 10005, 'symbolId': 900000201, 'riskLimit': {'id': 109, 'initialMarginRate': '0.01', 'maintenanceMarginRate': '0.005', 'marginRateStep': '0.005', 'maxLeverage': 20, 'riskLimitBase': '10', 'riskLimitStep': '5', 'maxRiskLimitSteps': 9, 'maxQuantity': '55', 'createdAt': 1735689600000}, 'cross': True, 'createdAt': 1751336113229, 'updatedAt': 1751881676881, 'entryValue': '0', 'entryPrice': '0', 'margin': '0', 'leverage': 10, 'liquidationPrice': '0', 'direction': 'LONG', 'quantity': '0', 'realizedPNL': '0', 'riskLevel': 0, 'minimumMaintenanceMarginRate': '0.005', 'minQuantity': '0', 'maxQuantity': '10', 'version': 0, 'empty': True}}
```

[Python Demo](/benpay-kai-fa-zhe-zhong-xin/code-demo/fa-song-dai-qian-ming-de-qing-qiu.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://benpaydex.gitbook.io/benpay-kai-fa-zhe-zhong-xin/rest-api/qian-ming-ji-zhi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
