# 合约交易

## **接入准备**

### **交易对**

交易对由基础币种和报价币种组成。以交易对 btc\_usdt 为例，btc 为商品币种，usdt 为计价币种。

### **申请API Key**

手机访问hibt官网，进入个人设置页找到API管理，申请API Key，创建成功后请务必记住以下信息：

* Access Key API 访问密钥
* Secret Key 签名认证加密所使用的密钥（仅申请时可见)
* Password管理API时使用

### **接口鉴权**

公共接口可用于获取基础信息和行情数据。公共接口无需认证即可调用。

私有接口可用于交易管理和账户管理。每个私有请求必须使用您的API Secret Key进行签名验证。

### **REST API**

`https://fapi.hibt0.com/open-api`

### **签名认证**

除公共接口（基础信息，行情数据）外的私有接口均必须使用您的 API Key 做加密处理，以校验参数或参数值在传输途中是否发生了更改。 每一个API Key需要有适当的权限才能访问相应的接口，每个新创建的API Key都需要分配权限。在使用接口前，确认你的API Key有相应的权限。

一个合法的请求所需要的内容：

* 方法请求地址：例如 <https://fapi.hibt0.com/open-api/v2/order/open>。
* Header中填API 访问密钥（X-ACCESS-KEY）：您申请的 API Key 中的 Access Key。
* Header中填Body签名后的数据 (X-SIGNATURE): 您发送请求的body用Secret Key 加密后得到
* Post请求Body中和Get请求url参数加入请求时间戳字段（timestamp）: 请求时的毫秒时间戳，签名时使用
* 必选和可选参数：每个方法都有一组用于定义 API 调用的必需参数和可选参数。可以在每个方法的说明中查看这些参数及其含义。
* 签名：加密计算得出的值，用于确保签名有效和未被篡改，**为了您 API Key 的安全，一次参数签名 5分钟后会过期**。
* 签名必要参数：需要签名认证的接口，必须添加 timestamp参数（传值为服务器最新时间，可通过`v2/server/time` 接口获取）。

### **加密方式**

开仓post请求body内容

```json
{
    "customID": "11111", //您的自定义订单id
    "symbol": "btc_usdt",//交易币对
    "type": 1,// 1限价 2市价
    "side": 1,// 方向 1 buy 2 shell
    "leverage": 10, //杠杆
    "price": "2660", //下单价(限价委托使用) 非限价单不需要传此字段
    "amount": "0.01", //下单量
    "triggerType": 2, //止盈止损出发类型 1:成交价触发,2:指数价触发 不设置止盈止损可以不填
    "spPrice":"2770", //预设止盈价格 不设置止盈 不需要传此字段
    "slPrice":"2450", //预设止损价 不设置止损 不需要传此字段
    "isSetSp": true, //是否止盈
    "isSetSl": true, //是否止损
    "timestamp": 1724916869475 //当前时间戳 ms
}
```

对参数按照ASCII进行排序

`amount=0.01&customID=11111&isSetSl=true&isSetSp=true&leverage=10&price=2660&side=1&slPrice=2450&spPrice=2770&symbol=btc_usdt&timestamp=1724916869475&triggerType=2&type=1`

将排完序的请求参数使用secretKey 进行HMAC SHA256进行加密，得到的结果

`9543936a83c8b4fd0aae02a6e6fa272dc8ebc95b871f620eb23ae1a6dadffee7`

```python
import json
import hmac
import hashlib
from collections import OrderedDict
​
​
def bytes_to_hex(bytes_array):
    return ''.join(['%02x' % byte for byte in bytes_array])
​
​
def generate_hmac_sha256(data, key):
    secret_key = key.encode()
    message = data.encode()
    signature = hmac.new(secret_key, message, hashlib.sha256).digest()
    return bytes_to_hex(signature)
​
​
def get_sort(json_str):
    # 解析JSON字符串
    data = json.loads(json_str, object_pairs_hook=OrderedDict)
​
    # 创建一个新字典，用于存储排序后的键值对
    sorted_data = OrderedDict()
​
    # 对原始字典的键进行排序，并按顺序插入到新字典中
    for key in sorted(data.keys()):
        if data[key] != "":
            sorted_data[key] = data[key]
​
    return sorted_data
​
​
def get_key(json_str, secret_key):
    # 过滤掉空字符串值
    sortData = get_sort(json_str)
    filtered_data = {k: v for k, v in sortData.items() if v != ""}
    # 拼接签名串
    sign_str = []
    for k, v in filtered_data.items():
        # #如果v 是数组，则转换为字符串
        if isinstance(v, list):
            for i in range(len(v)):
                v[i] = get_sort(json.dumps(v[i], ensure_ascii=False, separators=(',', ':')))
            v = json.dumps(v,ensure_ascii=False, separators=(',', ':'))
            sign_str.append(f"{k}={v}")
            continue
        sign_str.append(f"{k}={v}")
    sorted(sign_str) # 按字典顺序排序
    sign_str = '&'.join(sign_str)
    print("签名串：", sign_str)
​
    # 计算HMAC SHA256签名
    signature = generate_hmac_sha256(sign_str, secret_key)
    return signature
    # print("签名：", signature)
​
if __name__ == '__main__':
    json_str ={"items": [{"amount": "1", "customID": "123223", "leverage": 20, "side": 1, "symbol": "eth_usdt", "type": 2}, {"amount": "0.01", "customID": "321322", "leverage": 100, "side": 1, "symbol": "btc_usdt", "type": 2}], "timestamp": 1725599130897}
    g =json.dumps(json_str)
    a = get_key(g, "your secret key")
    print(a) #打印签名
```

**备注： 如果参数字段含有数组 单独对其转为json字符串后拼接到签名串**

**构建 http 请求使用**

1. `使用`**`X-ACCESS-KEY`**`存储access key信息，并在 header 中进行参数传递`
2. `使用`**`X-SIGNATURE`**`存储生成的签名信息，并在 header 中进行参数传递`
3. `使用`**`X-TIMESTAMP`**`存储请求时间戳，并在 header 中进行参数传递`

**请求方式**

目前只有两种方法：GET和POST

* GET请求：所有的参数都在路径参数里
* POST请求，所有参数以JSON格式发送在请求主体（body）里

**返回格式**

```json
{
  "msg": "success",
  "code": 0,
  "data": ""
}
```

### **常见错误码**

#### **21XXXX(参数错误类)**

#### **22XXXX(业务错误类)**

| 错误码    | 描述                  |
| ------ | ------------------- |
| 210001 | 传参错误                |
| 210004 | 止盈价设置错误             |
| 210005 | 止损价设置错误             |
| 210007 | 只允许查询最近三个月数据        |
| 210008 | 只允许查询7天之间的数据        |
| 210009 | 只允许查询三个月之间数据        |
| 210010 | 错误的交易对              |
| 210011 | endTime 大于现在时       |
| 210116 | 无效的用户               |
| 210117 | 币种余额不存在             |
| 220001 | 数据未找到               |
| 220002 | timestamp时间戳过期      |
| 220003 | X-ACCESS-KEY未填写     |
| 220004 | api key 鉴权失败        |
| 220005 | X-SIGNATURE 签名未填写   |
| 220007 | Access Key 已过期      |
| 220008 | 签名校验失败              |
| 220011 | 授权已失效               |
| 220012 | IP地址不在白名单中          |
| 220013 | 没有查询权限              |
| 220014 | 没有交易权限              |
| 220015 | websocket专用 错误的事件类型 |
| 220017 | 访问过于频繁              |
| 210019 | 无认证                 |
| 210020 | 无交易和查询权             |
| 210021 | Access Key 无效       |

## **基础信息接口**

### **服务器时间获取**

#### **HTTP请求**

#### **GET** `/v2/server/time`

#### **鉴权** 否

#### **请求参数**

无任何参数

#### **返回字段**

```json
{
    "code":0,
    "msg":"success",
    "data":{"serverTime":1724916869475}  //ms毫秒
}
​
```

### **查询所有交易币对**

#### **HTTP请求**

#### **GET** `/v2/market/symbols`

#### **请求参数** 无

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[
        {
            "symbol": "",
            "supportTrade": true, //是否支持交易
            "volumePrecision": 0, //交易对下单数量的精度（小数点后位数）
            "pricePrecision": 0, //交易对下单价格的精度（小数点后位数）
            "marketMiniAmount": "", //交易对市价最小下单量
            "limitMiniAmount": "" //交易对限价最小下单量
        }
    ]
​
}
```

### **查询单个币对ticker数据**

#### **HTTP请求**

#### **GET** `/v2/market/tickers`

#### **请求参数**

| 参数     | 描述  | 是否必填      | 类型     |
| ------ | --- | --------- | ------ |
| symbol | 交易对 | 否(不填返回全部) | string |

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[
        {
            "symbol": "",
            "amount": "", //以基础币种计量的交易量 btc
            "volume": "", //以报价币种计量的交易量 usdt
            "open": "",// 最近24小时开盘价
            "close": "", // 最近24小时收盘价
            "high": "", // 最近24小时最高价
            "low": "", //最近24小时最低价
            "lastPrice": "", //最新成交价
            "lastAmount": "",//最新成交价对应的量
            "lastTime": 0, //最新一笔交易的时间戳
            "change": 5.55   //涨跌幅
        }
    ]
}
```

### **查询单个币对K线数据**

#### **HTTP请求**

#### **GET** `/v2/market/candle`

#### **请求参数**

| 参数     | 描述                                                         | 是否必填 | 类型     |
| ------ | ---------------------------------------------------------- | ---- | ------ |
| symbol | 交易对                                                        | 是    | string |
| period | 返回数据时间粒度，也就是每根蜡烛的时间区间（M1,M5,M15,M30,H1,H4,H6,D1）           | 是    | string |
| start  | 查询起始时间戳，单位毫秒                                               | 否    | int    |
| end    | 查询截止时间戳，单位毫秒                                               | 否    | int    |
| count  | 返回K线数据条数\[1,500]，默认200 最大500。有start、end时，实际返回调试以时间范围内的条数为准 | 否    | int    |

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[
        {
            "symbol": "",
            "amount": "", //以基础币种计量的交易量
            "volume": "", //以报价币种计量的交易量
            "open": "", //本阶段开盘价
            "close": "",//本阶段收盘价
            "high": "", //本阶段最高价
            "low": "",//本阶段最低价
            "ts": 0 //本阶段开始的时间戳
        }
    ]
}
```

### **查询单个币对ticker价格**

#### **HTTP请求**

#### **GET** `/v2/market/ticker/price`

#### **请求参数**

<table><thead><tr><th width="151">参数</th><th>描述</th><th width="229">是否必填</th><th>类型</th></tr></thead><tbody><tr><td>symbol</td><td>交易对</td><td>否 （不填返回所有交易对）</td><td>string</td></tr></tbody></table>

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[
        {
            "symbol": "",
            "price":""
        }
    ]
}
```

### **查询单个币对深度**

#### **HTTP请求**

#### **GET** `/v2/market/depth`

#### **请求参数**

| 参数     | 描述                             | 是否必填 | 类型     |
| ------ | ------------------------------ | ---- | ------ |
| symbol | 交易对                            | 是    | string |
| limit  | 深度挡位数量 5, 10, 20, 50, 100, 200 | 否    | int    |

**返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":{
        "bid": [
            [
                "9638.0", // 价格
                "431"    // 数量
            ]
        ],
        "ask": [
            [
                "9638.0", // 价格
                "431"    // 数量
            ]
        ]}
}
```

### **查询单个币对最新成交**

#### **HTTP请求**

#### **GET** `/v2/market/deals`

#### **请求参数**

| 参数     | 描述  | 是否必填 | 类型     |
| ------ | --- | ---- | ------ |
| symbol | 交易对 | 是    | string |

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[{
        "symbol": "",
        "amount": "", //以基础币种计量的交易量
        "price": "", //以报价币种为单位的成交价格
        "side": "", // 交易方向：“sell” 或 “buy”, “buy” 即买，“sell” 即卖
        "time": 0 // 当前时间戳 ms
    }]
}
```

### **查询单个币对标记价格**

#### **HTTP请求**

#### **GET** `/v2/market/index`

#### **请求参数**

<table><thead><tr><th>参数</th><th>描述</th><th width="211">是否必填</th><th>类型</th></tr></thead><tbody><tr><td>symbol</td><td>交易对</td><td>否（不填返回全部币对）</td><td>string</td></tr></tbody></table>

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[{
        "symbol": "", //币对
        "marketPrice": "" //价格
    }]
}
```

### **查询单个币对指数价格K线**

#### **HTTP请求**

#### **GET** `/v2/market/indexCandle`

#### **请求参数**

| 参数     | 描述                                                     | 是否必填 | 类型     |
| ------ | ------------------------------------------------------ | ---- | ------ |
| symbol | 交易对                                                    | 是    | string |
| type   | K线周期 M1, M3, M5, M15, M30, H1, H2, H4, H6, H12, D1, W1 | 是    | string |
| start  | 起始时间戳 ms，不传默认当前时间                                      | 否    | int64  |
| limit  | 条数 默认20 最大5000                                         | 否    | int    |

#### **返回示例**

```json
{
    "msg": "success",
    "code": 0,
    "data": [
        [
            "77533.312",    // 开盘价
            "77585.699",    // 最高价
            "77533.307",    // 最低价
            "77584.674",    // 收盘价
            "1776830220000" // 时间戳 ms
        ]
    ]
}
```

### **查询资金费率**

#### **HTTP请求**

#### **GET** `/v2/market/fundingRate`

#### **请求参数**

<table><thead><tr><th width="167">参数</th><th width="217">描述</th><th width="154">是否必填</th><th>类型</th></tr></thead><tbody><tr><td>symbol</td><td>交易对</td><td>是</td><td>string</td></tr><tr><td>startTime</td><td>起始时间戳 ms 只能查区间三个月的数据</td><td>否</td><td>int64</td></tr><tr><td>endTime</td><td>结束时间戳</td><td>否</td><td>int64</td></tr><tr><td>limit</td><td>条数 默认100 最大1000</td><td>否</td><td>int</td></tr></tbody></table>

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[
        {
            "symbol": "",
            "rate": "", //资金费率
            "time": 0 //时间戳
        }
    ]
}
```

### **查询风险限额**

#### **HTTP请求**

#### **GET** `/v2/market/riskLimit`

#### **请求参数**

| 参数     | 描述  | 是否必填 | 类型     |
| ------ | --- | ---- | ------ |
| symbol | 交易对 | 是    | string |

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[
        {
            "symbol": "",
            "minValue": "", // 最小仓位价值
            "maxValue": "", // 最大仓位价值
            "maxLeverage": 0, // 最大可用杠杆
            "maintenanceMarginRate": "" // 维持保证金率
        }
    ]
}
```

### **查询合约最新行情**

**HTTP请求**

#### **GET** `/v2/market/contracts`

#### **请求参数**

| 参数     | 描述  | 是否必填      | 类型     |
| ------ | --- | --------- | ------ |
| symbol | 交易对 | 否(不填返回全部) | string |

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[
        {
            "ticker_id": "合约标识",  // 合约标识
            "base_currency": "基础货币",  // 基础货币
            "quote_currency": "计价货币",  // 计价货币
            "last_price": "最新价格",  // 最新价格
            "base_volume": "基础货币成交量",  // 基础货币成交量
            "USD_volume": "美元成交量",  // 美元成交量
            "quote_volume": "计价货币成交量",  // 计价货币成交量
            "bid": "买一价",  // 买一价
            "ask": "卖一价",  // 卖一价
            "high": "最高价",  // 最高价
            "low": "最低价",  // 最低价
            "product_type": "产品类型",  // 产品类型
            "open_interest": "未平仓量（基币）",  // 未平仓量（基币）
            "open_interest_usd": "未平仓量（美元）",  // 未平仓量（美元）
            "index_price": "指数价格",  // 指数价格
            "creation_timestamp": 0,  // 创建时间戳
            "expiry_timestamp": 0,  // 到期时间戳
            "funding_rate": "资金费率",  // 资金费率
            "next_funding_rate": "下期资金费率",  // 下期资金费率
            "next_funding_rate_timestamp": 0,  // 下期资金费率时间戳
            "maker_fee": "挂单手续费率",  // 挂单手续费率
            "taker_fee": "吃单手续费率",  // 吃单手续费率
            "contract_type": "合约类型",  // 合约类型
            "contract_price": "合约面值",  // 合约面值
            "contract_price_currency": "合约面值货币"  // 合约面值货币
        }
    ]
}
```

### **查询合约交易的说明**

#### **HTTP请求**

#### **GET** `/v2/market/contractSpecifications`

#### **请求参数** 无

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[
        {
            "contract_type": "okb_usdt",
            "contract_price": "123.45", //最新价
            "contract_price_currency": "usdt"
        }
    ]
}
```

### **查询合约订单簿**

#### **HTTP请求**

#### **GET** `/v2/market/orderBook`

#### **请求参数**

| 参数     | 描述      | 是否必填 | 类型     |
| ------ | ------- | ---- | ------ |
| depth  | 挡位1-100 | 否    | int    |
| symbol | 交易对     | 否    | string |

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[
        {
            "ticker_id": "btc_usdt",  // 交易对标识符，例如 "BTCUSD"
            "timestamp": 1689991200,  // 时间戳（毫秒级）
            "bids": [  // 买方订单列表
                ["10000.50", "2.3"],  // [价格, 数量]
                ["9999.75", "1.1"]
            ],
            "asks": [  // 卖方订单列表
                ["10001.00", "3.5"],
                ["10002.25", "0.8"]
            ]
        }
    ]
}
```

## **交易接口**

### **合约开仓**

#### **HTTP请求**

#### **POST** `/v2/order/open`

#### **鉴权** 有

#### **请求参数**

```json
{
    "customID": "11111", //您的自定义订单id；非必填但要保证唯一性
    "symbol": "btc_usdt",//交易币对
    "type": 1,// 1限价 2市价
    "side": 1,// 方向 1 buy 2 shell
    "leverage": 10, //杠杆 仅分仓模式下有效，合仓模式以用户设置的交易对杠杆为准
    "price": "2660", //下单价(限价委托使用) 非限价单不需要传此字段
    "amount": "0.01", //下单量
    "triggerType": 2, //止盈止损出发类型 1:成交价触发,2:指数价触发 不设置止盈止损可以不填
    "spPrice":"2770", //预设止盈价格 不设置止盈 不需要传此字段
    "slPrice":"2450", //预设止损价 不设置止损 不需要传此字段
    "isSetSp": true, //是否止盈
    "isSetSl": true, //是否止损
    "timestamp": 1724916869475 //当前时间戳 ms
}
```

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":{
        "orderID":"24081233332184101100143203708" //委托单id
    }
}
```

### **批量开仓**

#### **HTTP请求**

#### **POST** `/v2/order/batchOpen`

#### **鉴权** 有

#### **请求参数**

```json
{
  "timestamp": 1724916869475, //当前时间戳 ms

  "items": [
    {
      "customID": "11111", //您的自定义订单id；非必填但要保证唯一性
      "symbol": "btc_usdt", //交易币对
      "type": 1, // 1限价 2市价
      "side": 1, // 方向 1 buy 2 shell
      "leverage": 10, //杠杆 仅分仓模式下有效，合仓模式以用户设置的交易对杠杆为准
      "price": "2660", //下单价(限价委托使用) 非限价单不需要传此字段
      "amount": "0.01", //下单量
      "triggerType": 2, //止盈止损出发类型 1:成交价触发,2:指数价触发 不设置止盈止损可以不填
      "spPrice": "2770", //预设止盈价格 不设置止盈 不需要传此字段
      "slPrice": "2450", //预设止损价 不设置止损 不需要传此字段
      "isSetSp": true, //是否止盈
      "isSetSl": true //是否止损
    },
    {
      "customID": "11111", //您的自定义订单id；非必填但要保证唯一性
      "symbol": "btc_usdt", //交易币对
      "type": 1, // 1限价 2市价
      "side": 1, // 方向 1 buy 2 shell
      "leverage": 10, //杠杆 仅分仓模式下有效，合仓模式以用户设置的交易对杠杆为准
      "price": "2660", //下单价(限价委托使用) 非限价单不需要传此字段
      "amount": "0.01", //下单量
      "triggerType": 2, //止盈止损出发类型 1:成交价触发,2:指数价触发 不设置止盈止损可以不填
      "spPrice": "2770", //预设止盈价格 不设置止盈 不需要传此字段
      "slPrice": "2450", //预设止损价 不设置止损 不需要传此字段
      "isSetSp": true, //是否止盈
      "isSetSl": true //是否止损
    }
  ]
}
```

**返回示例**

```json
{
  "msg": "success",
  "code": 0,
  "data": {
    "success": { "11111": "orderID", "2222222": "orderID" }, // {"自定义订单id":"委托单id"}
    "fail": { "333333": "sp price error", "44444444": "bad symbol" } // {"自定义订单id":"错误内容"}
  }
}
```

### **合约撤单**

#### **HTTP请求**

#### **POST** `/v2/order/cancel`

#### **鉴权** 有

#### **请求参数**

```json
{
  "symbol": "btc_usdt",
  "orderID": "22222222", //orderID customID  positionID 三选一
  "customID": "",
  "positionID": "",
  "timestamp": 1724916869475 //当前时间戳 ms
}
```

**返回示例**

```json
{
  "msg": "success",
  "code": 0,
  "data": {
    "success": { "11111": "orderID", "2222222": "orderID" }, // {"自定义订单id":"委托单id"}
    "fail": { "333333": "orderID", "44444444": "orderID" } // {"自定义订单id":"委托单id"}
  }
}
```

### **批量撤单**

#### **HTTP请求**

#### **POST** `/v2/order/batchCancel`

#### **鉴权** 有

#### **请求参数**

```json
{
  "symbol": "btc_usdt",
  "listOrderID": ["11111"], //listOrderID listCustomID  listPositionID 三选一 或者都不填
  "listCustomID": [""],
  "listPositionID": [""],
  "timestamp": 1724916869475 //当前时间戳 ms
}
```

#### **返回示例**

```json
{
  "msg": "success",
  "code": 0,
  "data": {
    "success": { "11111": "orderID", "2222222": "orderID" }, // {"自定义订单id":"委托单id"}
    "fail": { "333333": "orderID", "44444444": "orderID" } // {"自定义订单id":"委托单id"}
  }
}
```

### **合约平仓**

#### **HTTP请求**

#### **POST** `/v2/order/close`

#### **鉴权** 有

#### **请求参数**

```json
{
  "amount": "0.01",
  "price": "2256", //仅限于限价平仓
  "type": 1, //1 限价， 2市价
  "positionID": "12222222222222", // 仓位id
  "timestamp": 1724916869475 //当前时间戳 ms
}
```

#### **返回示例**

```json
{
  "msg": "success",
  "code": 0,
  "data": {
    "orderID": "24081233332184101100143203708" //委托单id
  }
}
```

### **一键平仓**

#### **HTTP请求**

#### **POST** `/v2/order/closeAll`

#### **鉴权** 有

#### **请求参数**

```json
{
    "symbol": "btc_usdt",
    "timestamp": 1724916869475 //当前时间戳 ms
}
```

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":{
        "listOrderID":["24081233332184101100143203708"] //委托单id
    }
}
```

### **查询未完成订单**

#### **HTTP请求**

#### **GET** `/v2/order/unFinish`

#### **鉴权** 有

#### **请求参数**

| 参数         | 描述                                             | 是否必填 | 数据类型   |
| ---------- | ---------------------------------------------- | ---- | ------ |
| symbol     | 交易对                                            | 否    | string |
| orderID    | 委托单id // orderID customID positionID 三选一 或者都不填 | 否    | string |
| customID   | 自定义订单id                                        | 否    | string |
| positionID | 仓位id                                           | 否    | string |
| timestamp  | 当前时间戳ms                                        | 是    |        |

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[{
            "id": "", //订单id
            "customID": "", //自定义订单id
            "symbol": "",//交易对
            "type": 1, //订单类型 订单类型 1限价 2市价
            "action": 0, //订单事件 0开仓 1平仓 2止损 3止盈 4强平 5FOK强平 6ADL减仓 7加仓 8反向开仓 9穿仓
            "side": 1,  //交易方向 1 buy 2 sell
            "positionID": "", //仓位id
            "price": "", //订单价格，限价单才有值
            "leverage": 0, //杠杆
            "amount": "", //下单量
            "frozen": "", //冻结保证金
            "filledAmount": "", //已完成量
            "filledPrice": "", //成交均价
            "filledValue": "",//成交价值
            "triggerType": 2, //止盈止损触发类型 1成交价 2指数价
            "spPrice": "", //预设止盈价
            "slPrice": "", //预设止损价
            "state": 1,//状态 1正常 2已完成 3撤销 4部分成交 5部分成交已撤销 6撤销中
            "profit": "", //已实现盈亏（平仓订单使用）
            "fee": "", //原始手续费
            "pointFee": "", //积分(赠金)手续费抵扣
            "pointProfit": "", //积分(赠金)盈亏抵扣
            "closePrice": "", //破产价
            "triggerPrice": "", //触发价
            "createdAt": 0,
            "updatedAt": 0
        }]
   
}
```

### **查询已经完成订单详情**

#### **HTTP请求**

#### **GET** `/v2/order/finishedInfo`

#### **鉴权** 有

#### **请求参数**

<table><thead><tr><th>参数</th><th width="234">描述</th><th>是否必填</th><th>数据类型</th></tr></thead><tbody><tr><td>orderID</td><td>委托单id //orderID customID positionID 三选一</td><td>二选一</td><td>string</td></tr><tr><td>customID</td><td>自定义订单id</td><td>二选一</td><td>string</td></tr><tr><td>positionID</td><td>仓位id</td><td>否</td><td>string</td></tr><tr><td>timestamp</td><td>当前时间戳</td><td>是</td><td>number</td></tr></tbody></table>

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":{
            "id": "", //订单id
            "customID": "", //自定义订单id
            "symbol": "",//交易对
            "type": 1, //订单类型 订单类型 1限价 2市价
            "action": 0, //订单事件 0开仓 1平仓 2止损 3止盈 4强平 5FOK强平 6ADL减仓 7加仓 8反向开仓 9穿仓
            "side": 1,  //交易方向 1 buy 2 sell
            "positionID": "", //仓位id
            "price": "", //订单价格，限价单才有值
            "leverage": 0, //杠杆
            "amount": "", //下单量
            "frozen": "", //冻结保证金
            "filledAmount": "", //已完成量
            "filledPrice": "", //成交均价
            "filledValue": "",//成交价值
            "triggerType": 2, //止盈止损触发类型 1成交价 2指数价
            "spPrice": "", //预设止盈价
            "slPrice": "", //预设止损价
            "state": 1,//状态 1正常 2已完成 3撤销 4部分成交 5部分成交已撤销 6撤销中
            "profit": "", //已实现盈亏（平仓订单使用）
            "fee": "", //原始手续费
            "pointFee": "", //积分(赠金)手续费抵扣
            "pointProfit": "", //积分(赠金)盈亏抵扣
            "closePrice": "", //破产价
            "triggerPrice": "", //触发价
            "createdAt": 0,
            "updatedAt": 0
        }
   
}
```

### **查询历史完成订单列表**

#### **HTTP请求**

#### **GET** `/v2/order/finished`

#### **鉴权** 有

#### **请求参数**

<table><thead><tr><th>参数</th><th width="215">描述</th><th width="164">是否必填</th><th>数据类型</th></tr></thead><tbody><tr><td>symbol</td><td>交易对(参数"btc_usdt,eth_usdt")</td><td>否</td><td>string</td></tr><tr><td>startTime</td><td>开始时间</td><td>是</td><td>int</td></tr><tr><td>endTime</td><td>结束时间</td><td>是</td><td>int</td></tr><tr><td>pageIndex</td><td>分页</td><td>是</td><td>int</td></tr><tr><td>pageSize</td><td>条数 最大50</td><td>是</td><td>int</td></tr><tr><td>timestamp</td><td>当前时间戳</td><td>是</td><td>number</td></tr></tbody></table>

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":{
        "total":100, //总量
        "page":1, //当前第几页
        "data":[{
            "id": "", //订单id
            "customID": "", //自定义订单id
            "symbol": "",//交易对
            "type": 1, //订单类型 订单类型 1限价 2市价
            "action": 0, //订单事件 0开仓 1平仓 2止损 3止盈 4强平 5FOK强平 6ADL减仓 7加仓 8反向开仓 9穿仓
            "side": 1,  //交易方向 1 buy 2 sell
            "positionID": "", //仓位id
            "price": "", //订单价格，限价单才有值
            "leverage": 0, //杠杆
            "amount": "", //下单量
            "frozen": "", //冻结保证金
            "filledAmount": "", //已完成量
            "filledPrice": "", //成交均价
            "filledValue": "",//成交价值
            "triggerType": 2, //止盈止损触发类型 1成交价 2指数价
            "spPrice": "", //预设止盈价
            "slPrice": "", //预设止损价
            "state": 1,//状态 1正常 2已完成 3撤销 4部分成交 5部分成交已撤销 6撤销中
            "profit": "", //已实现盈亏（平仓订单使用）
            "fee": "", //原始手续费
            "pointFee": "", //积分(赠金)手续费抵扣
            "pointProfit": "", //积分(赠金)盈亏抵扣
            "closePrice": "", //破产价
            "triggerPrice": "", //触发价
            "createdAt": 0,
            "updatedAt": 0
        }]
    }

}
```

### **添加计划委托**

#### **HTTP请求**

#### **POST** `/v2/entrust/add`

#### **鉴权** 有

#### **请求参数**

```json
{
  "customID": "11111", //自定义订单id
  "symbol": "btc_usdt", //交易对
  "side": 1, //交易方向 1 buy 2 sell
  "triggerType": 1, //触发类型：1最新价 2指数价
  "triggerPrice": "", //触发价格
  "amount": "", //下单量
  "price": "", //委托价
  "leverage": 0, //杠杆
  "spSlTriggerType": 0, //止盈止损触发类型：1最新价 2指数价
  "spPrice": "", //预设止盈价 设置了止盈 就传
  "slPrice": "", //预设止损价 设置了止损就传
  "IsSetSp": false, //是否设置止盈
  "IsSetSl": false, //是否设置止损
  "timestamp": 1724916869475 //当前时间戳 ms
}
```

#### **返回示例**

```json
{
  "msg": "success",
  "code": 0,
  "data": {
    "id": "", //委托id
    "symbol": "", //币对
    "leverage": 0, //杠杆
    "triggerType": 1, //触发类型：1最新价 2指数价
    "triggerPrice": "", //触发价格
    "status": 2, //状态 1-待委托 2-已委托 3-用户撤消 4-系统撤消
    "side": 1, //交易方向 1 buy 2 sell
    "price": "", //委托价
    "startPrice": "", //触发下单的价格
    "amount": "", //委托量
    "spSlTriggerType": 0, // 止盈止损触发类型
    "spPrice": "", //预设止盈价
    "slPrice": "", //预设止损价
    "isSetSp": false, //是否设置止盈
    "isSetSl": false, //是否设置止损
    "frozen": "", //冻结保证金
    "createdAt": 0,
    "updatedAt": 0
  }
}
```

### **撤销计划委托**

#### **HTTP请求**

#### **POST** `/v2/entrust/cancel`

#### **鉴权** 有

#### **请求参数**

```json
{
    "symbol": "", //交易币对
    "entrustID": "", //委托id  与自定义id 二选一
    "customID": "", // 自定义用户id
    "timestamp": 1724916869475 //当前时间戳 ms
}
```

**返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":["委托id1"，"委托id2"] // 返回取消成功的列表
}
```

### **获取未完成计划委托列表**

#### **HTTP请求**

#### **GET** `/v2/entrust/unFinish`

#### **鉴权** 有

#### **请求参数**

| 参数        | 描述    | 是否必填 | 数据类型   |
| --------- | ----- | ---- | ------ |
| symbol    | 交易对   | 否    | string |
| timestamp | 当前时间戳 | 是    | number |

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[{
        "id": "", //委托id
        "symbol": "", //币对
        "leverage": 0, //杠杆
        "triggerType": 1,//触发类型：1最新价 2指数价
        "triggerPrice": "", //触发价格
        "status": 2, //状态 1-待委托 2-已委托 3-用户撤消 4-系统撤消
        "side": 1, //交易方向 1 buy 2 sell
        "price": "",//委托价
        "startPrice": "",//触发下单的价格
        "amount": "", //委托量
        "spSlTriggerType": 0, // 止盈止损触发类型
        "spPrice": "", //预设止盈价
        "slPrice": "", //预设止损价
        "isSetSp": false, //是否设置止盈
        "isSetSl": false, //是否设置止损
        "frozen": "", //冻结保证金
        "createdAt": 0,
        "updatedAt": 0
    }]
}
```

### **获取已完成计划委托列表**

#### **HTTP请求**

#### **GET** `/v2/entrust/finished`

#### **鉴权** 有

#### **请求参数**

| 参数        | 描述      | 是否必填 | 数据类型   |
| --------- | ------- | ---- | ------ |
| symbol    | 交易对     | 否    | string |
| pageIndex | 分页      | 是    | int    |
| pageSize  | 条数 最大50 | 是    | int    |
| timestamp | 当前时间戳   | 是    | number |

#### **返回示例**

```json
{
  "msg": "success",
  "code": 0,
  "data": {
    "total": 100, //总量
    "page": 1, //当前第几页
    "data": [
      {
        "id": "", //委托id
        "symbol": "", //币对
        "leverage": 0, //杠杆
        "triggerType": 1, //触发类型：1最新价 2指数价
        "triggerPrice": "", //触发价格
        "status": 2, //状态 1-待委托 2-已委托 3-用户撤消 4-系统撤消
        "side": 1, //交易方向 1 buy 2 sell
        "price": "", //委托价
        "startPrice": "", //触发下单的价格
        "amount": "", //委托量
        "spSlTriggerType": 0, // 止盈止损触发类型
        "spPrice": "", //预设止盈价
        "slPrice": "", //预设止损价
        "isSetSp": false, //是否设置止盈
        "isSetSl": false, //是否设置止损
        "frozen": "", //冻结保证金
        "createdAt": 0,
        "updatedAt": 0
      }
    ]
  }
}
```

## **账户接口**

### **获取账户余额**

#### **HTTP请求**

#### **GET** `/v2/account/balance`

#### **鉴权** 有

#### **请求参数** 无

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":{
        "balance": "余额",  // 账户余额
        "frozen": "挂单冻结",  // 挂单冻结金额
        "margin": "持仓保证金",  // 持仓保证金
        "point": "积分(赠金)",  // 积分或赠金
        "loans": "借贷",  // 借贷金额
        "profit": "未实现盈亏",  // 未实现盈亏
        "unProfit": "浮盈",  // 浮盈
        "unLosses": "浮亏",  // 浮亏
        "coin": "币种"  // 币种
    }
}
```

### **调整开仓杠杆**

#### **HTTP请求**

#### **POST** `/v2/account/setLeverage`

#### **鉴权** 有

#### **请求参数**

```json
{
  "symbol": "", //交易对
  "leverage": 0, //杠杆
  "timestamp": 1724916869475 //当前时间戳 ms
}
```

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":{
        "symbol": "", //交易对
        "leverage": 0 //杠杆
    }
}
```

### **获取用户持仓**

#### **HTTP请求**

#### **GET** `/v2/account/position`

#### **鉴权** 有

#### **请求参数**

| 参数         | 描述      | 是否必填 | 类型     |
| ---------- | ------- | ---- | ------ |
| symbol     | 交易对     | 否    | string |
| positionID | 仓位id    | 否    | string |
| timestamp  | 当前时间戳ms | 是    | number |

**返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[{
        "positionID": "",          // 仓位ID
        "symbol": "",              // 交易对
        "side": 0,                 // 持仓方向（1: 买入, 2: 卖出）
        "leverage": 0,             // 使用杠杆倍数
        "price": "",               // 成交均价
        "amount": "",              // 持仓量
        "frozenAmount": "",        // 平仓冻结量
        "margin": "", //持仓保证金
        "triggerType": 1, //止盈止损触发类型 1 成交价 2 指数价
        "spPrice": "",// 止盈价
        "slPrice": "", //止损价
        "openProfit": "", //未实现盈亏
        "updatedAt": 0, //时间戳
        "spSlModel": 0, //止盈止损模式 1-全部止盈止损 2-部分止盈止损
        "spType": 0, //止盈类型 0未设置止盈 1限价 2市价
        "slType": 0, //止损类型 0未设置止损 1限价 2市价
        "spTriggerPrice": "", //止盈委托价
        "slTriggerPrice": "", //止损委托价
        "spSlPartData": [ //部分止盈止损数据
            {
                "id": 0,
                "triggerType": 1,// 止盈止损触发类型
                "spPrice": "", //止盈价
                "slPrice": "", // 止损价
                "amount": "", // 止盈止损数量
                "spType": 1, // 止盈类型 0未设置止盈 1限价 2市价
                "slType": 1, // 止损类型 0未设置止损 1限价 2市价
                "spTriggerPrice": "", //止盈委托价
                "slTriggerPrice": "" //止损委托价
            }
        ]
    }]

}
```

### **获取账户成交历史**

#### **HTTP请求**

#### **GET** `/v2/account/order`

#### **鉴权** 有

#### **请求参数**

| 参数        | 描述              | 是否必填 | 类型     |
| --------- | --------------- | ---- | ------ |
| symbol    | 交易对             | 是    | string |
| startTime | 开始时间 单位s        | 否    | int64  |
| endTime   | 结束时间 s          | 否    | int64  |
| limit     | 条数 默认500 最大1000 | 否    | int    |
| timestamp | 当前时间戳ms         | 是    |        |

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[{
        "id": "",                          // 订单ID
        "symbol": "",                      // 合约标识
        "type": 0,                         // 订单类型 (1: 限价, 2: 市价)
        "action": 0,                       // 订单事件 (0: 开仓, 1: 平仓, 2: 止损, 3: 止盈, 4: 强平, 5: FOK强平, 6: ADL减仓, 7: 加仓, 8: 反向开仓, 9: 穿仓)
        "side": 0,                         // 交易方向 (1: buy, 2: sell)
        "positionId": "",                  // 仓位ID
        "price": "",                       // 订单价格，限价单才有值
        "leverage": 0,                     // 杠杆倍数
        "amount": "",                      // 下单量
        "frozen": "",                      // 冻结保证金 (OpenPrice * Amount * BaseMarginRate)
        "filledAmount": "",                // 已完成量
        "filledPrice": "",                 // 成交均价
        "filledValue": "",                 // 成交价值
        "triggerType": 0,                  // 止盈止损触发类型 (1: 成交价, 2: 指数价)
        "spPrice": "",                     // 预设止盈价
        "slPrice": "",                     // 预设止损价
        "createdAt": 0,                    // 创建时间
        "updatedAt": 0,                    // 更新时间
        "state": 0,                        // 状态 (1: 正常, 2: 已完成, 3: 撤销, 4: 部分成交, 5: 部分成交已撤销, 6: 撤销中)
        "profit": "",                      // 已实现盈亏（平仓订单使用）
        "fee": "",                         // 手续费
        "pointFee": "",                    // 积分(赠金)手续费抵扣
        "pointProfit": "",                 // 积分(赠金)盈亏抵扣
        "closePrice": ""                   // 破产价
    }]
}
```

### **获取账户资金账单**

#### **HTTP请求**

#### **GET** `/v2/account/balanceRecord`

#### **鉴权** 有

#### **请求参数**

| 参数        | 描述                                                            | 是否必填 | 类型     |
| --------- | ------------------------------------------------------------- | ---- | ------ |
| symbol    | 交易对                                                           | 否    | string |
| startTime | 开始时间 单位ms 间隔时间30天                                             | 否    | int64  |
| endTime   | 结束时间 ms 间隔时间30天                                               | 否    | int64  |
| event     | 1:充值，2:扣款，3:转入，4:转出，9:资金费用，201:开多，202:开空，204:平多，205:平空，206:强平 | 否    | int    |
| limit     | 数据条数 默认500 最大1000                                             | 否    | int    |
| timestamp | 当前时间戳                                                         | 是    |        |

#### **返回示例**

```json
{
    "msg":"success",
    "code":0,
    "data":[{
        "id": "",                          // 交易ID
        "event": 0,                        // 类型：1:充值, 2:扣款, 3:转入, 4:转出, 9:资金费用, 201:开多, 202:开空, 204:平多, 205:平空, 206:强平
        "amount": "",                      // 余额相关的操作代表金额，交易相关操作代表盈亏
        "coin": "",                        // 币种
        "fee": "",                         // 手续费
        "symbol": "",                      // 所属交易对
        "note": "",                        // 备注
        "createdAt": 0                     // 时间
    }
           ]
}
```

#### **获取用户强平历史**

#### **HTTP请求**

#### **GET** `/v2/account/orderForced`

#### **鉴权** 有

#### **请求参数**

| 参数        | 描述                               | 是否必填 | 类型     |
| --------- | -------------------------------- | ---- | ------ |
| symbol    | 交易对                              | 否    | string |
| startTime | 开始时间 单位ms start end 区间为7天内       | 否    | int64  |
| endTime   | 结束时间 ms                          | 否    | int64  |
| action    | 强平类型：4-强平,5-FOK强平,6-ADL自动减仓,9-穿仓 | 否    | int    |
| limit     | 数据条数 默认500 最大1000                | 否    | int    |
| timestamp | 当前时间戳                            | 是    |        |

**返回示例**

```
{
    "msg":"success",
    "code":0,
    "data":[{
        "id": "",                          // 订单ID
        "symbol": "",                      // 币对
        "type": 0,                         // 订单类型 (1: 限价, 2: 市价)
        "action": 0,                       // 强平类型：4-强平, 5-FOK强平, 6-ADL自动减仓, 9-穿仓
        "side": 0,                         // 交易方向 (1: buy, 2: sell)
        "positionID": "",                  // 仓位ID
        "price": "",                       // 订单价格，限价单才有值
        "leverage": 0,                     // 杠杆
        "amount": "",                      // 下单量
        "frozen": "",                      // 冻结保证金 (OpenPrice * Amount * BaseMarginRate)
        "filledAmount": "",                // 已完成量
        "filledPrice": "",                 // 成交均价
        "filledValue": "",                 // 成交价值
        "triggerType": 0,                  // 止盈止损触发类型 (1: 成交价, 2: 指数价)
        "spPrice": "",                     // 预设止盈价
        "slPrice": "",                     // 预设止损价
        "createdAt": 0,                    // 创建时间
        "updatedAt": 0,                    // 更新时间
        "state": 0,                        // 状态 (1: 正常, 2: 已完成, 3: 撤销, 4: 部分成交, 5: 部分成交已撤销, 6: 撤销中)
        "profit": "",                      // 已实现盈亏（平仓订单使用）
        "fee": "",                         // 手续费
        "pointFee": "",                    // 积分(赠金)手续费抵扣
        "pointProfit": "",                 // 积分(赠金)盈亏抵扣
        "closePrice": ""                   // 破产价
    }]
}
```

## **合约WebSocket接口**

#### **请求方式**&#x20;

#### 例如`wss://fapi.hibt0.com/v2/ws`

#### **接口鉴权**

需要鉴权的订阅请先发送认证消息

signature //把时间戳字符串 签名即可

```
{"event":"auth","accessKey":"XXX","timestamp":"XXX","signature":"XXX"}
```

#### **订阅主题**

`{”event“:"sub", "topic":"主题内容"}`

### **订阅深度**

支持的深度主题 5deep 10deep 20 deep

请求json `{"event":"sub","topic":"btc_usdt.5deep"}`

#### **返回示例**

```json
{
      "type":"btc_usdt.5deep",
      "ts":1725356328427,
      "data":{
            "symbol":"btc_usdt",
            "asks":["58930.89","2.51","58930.99","2.38","58931.09","2.9","58931.19","3.72","58931.29","1.41"],
            "bids":["58930.71","1.44","58930.61","1.61","58930.51","2.22","58930.41","1.22","58930.31","1.94"]
            }
}
```

### **订阅ticker**

请求json `{"event":"sub","topic":"btc_usdt.ticker"}`

#### **返回示例**

```json
{
  "type": "btc_usdt.ticker",
  "ts": 1725356998063,
  "data": {
    "symbol": "btc_usdt",
    "amount": "473529.69",   // btc 量
    "volume": "27853751718.826", //USDT 价值
    "open": "58147.82", //最近24小时开盘价
    "close": "58920.25",
    "high": "59805.51",
    "low": "58103.55",
    "lastPrice": "58920.25", //最新成交价
    "lastAmount": "0.99", //最新成交价对应的量
    "lastTime": 1725356998061,
    "change": "1.32" //24小时涨跌幅
  }
}
```

### **订阅指数价格**

请求json `{"event":"sub","topic":"btc_usdt.index"}`

#### **返回示例**

```json
{
  "type": "btc_usdt.index",
  "ts": 1725357439229,
  "data": {
    "symbol": "btc_usdt",
    "price": "58901.1",
    "time": 1725357439228
  }
}
```

### **订阅最新成交**

请求json `{"event":"sub","topic":"btc_usdt.trade"}`

#### **返回示例**

```json
{
  "type": "btc_usdt.trade",
  "ts": 1725357599308,
  "data": [
    "58872.48", //价格
    "1",  //1买 2卖
    "2.59", //成交数量
    "1725357599305"//时间戳
  ]
}
```

### **订阅行情K线**

请求json `{"event":"sub","topic":"btc_usdt.candle.M1"}`

#### **支持周期**

```
"M1","M5","M15","M30","H1","H2","H4","H6","H12","D1","W1"
```

#### **返回示例**

```json
{
  "type": "btc_usdt.candle.M1",
  "ts": 1725357897306,
  "data": [
    "410.89", //成交量
    "24207865.8365", //成交额
    "58891.64", //开盘价
    "58945.88", //最高价
    "58891.64", //最低价
    "58923.96", //收盘价
    "1725357840000" //时间戳
  ]
}
```

### 订阅指数K线

请求json `{"event":"sub","topic":"btc_usdt.indexCandle.M1"}`

#### **支持周期**

```
"M1","M3","M5","M15","M30","H1","H2","H4","H6","H12","D1","W1"
```

#### **返回示例**

```json
{
    "type": "btc_usdt.indexCandle.M1",
    "ts": 1776830734242,
    "data": [
        "77589.629",    // 开盘价
        "77593.079",    // 最高价
        "77566.025",    // 最低价
        "77570.13",     // 收盘价
        "1776830700000" // 时间戳 ms
    ]
}
```

### **订阅计划委托触发推送(需认证)**

请求json `{"event":"sub","topic":"user.entrust"}`

#### **返回示例**

```json
{
    "type": "user.entrust",
    "ts": 1725437392251,
    "data": [
        {
            "id": "24090408062338901100109440001",
            "symbol": "btc_usdt",
            "leverage": 10, //杠杆
            "triggerType": 2, //触发类型 1成交价(最新价) 2指数价(标记价)
            "triggerPrice": "56762", //触发价格
            "status": 2, //状态 1-待委托 2-已委托 3-用户撤消 4-系统撤消
            "side": 1, //交易方向 1buy 2sell
            "price": "56830", //委托价
            "startPrice": "", //触发下单的价格
            "amount": "0.12", //委托量
            "spSlTriggerType": 0, //止盈止损触发类型
            "spPrice": "0", //预设止盈价
            "slPrice": "0", //预设止损价
            "isSetSp": false, //是否设置止盈
            "isSetSl": false, //是否设置止损
            "frozen": "", // 冻结保证金
            "createdAt": 1725437183389,
            "updatedAt": 1725437392240
        }
    ]
}
```

### **订阅仓位变更(需要认证)**

请求json `{"event":"sub","topic":"user.position"}`

#### **返回示例**

```json
{
    "type": "user.position",
    "ts": 1725364233774,
    "data": [
        {
            "positionID": "240903114238636010629", //仓位id
            "symbol": "btc_usdt", //
            "side": 1, // 方向 1buy 2sell
            "leverage": 10, //杠杆
            "price": "59066", //成交均价
            "amount": "0.21", //持仓量
            "frozenAmount": "0.21", //平仓冻结量
            "margin": "1240.386", //持仓保证金
            "triggerType": 1, // 止盈止损触发类型
            "spPrice": "", //止盈价
            "slPrice": "", //止损价
            "openProfit": "", //未实现盈亏
            "updatedAt": 1725364233773,
            "spSlModel": 1, // 止盈止损模式 1-全部止盈止损 2-部分止盈止损
            "spType": 0, // 止盈类型 0未设置止盈 1限价 2市价
            "slType": 0, //止损类型 0未设置止损 1限价 2市价
            "spTriggerPrice": "0", //止盈委托价
            "slTriggerPrice": "0", //止损委托价
            "spSlPartData": [{
                "id": 0,
                "triggerType": 1, //止盈止损触发类型
                "spPrice": "", //止盈价
                "slPrice": "", //止损价
                "amount": "", //部分止盈止损数量
                "spType": 0, //止盈类型 0未设置止盈 1限价 2市价
                "slType": 0, //止损类型 0未设置止损 1限价 2市价
                "spTriggerPrice": "", //止盈委托价
                "slTriggerPrice": ""  //止损委托价
            }] //部分止盈止损数据
        }
    ]
}
```

### **订阅委托单成交推送(需要认证)**

请求json `{"event":"sub","topic":"user.order"}`

#### **返回示例**

```json
{
    "type": "user.order",
    "ts": 1725432998830,
    "data": [
        {
            "id": "24090406563872601100109440728", //订单id
            "customID": "", //自定义订单号
            "symbol": "btc_usdt",
            "type": 2, //订单类型 1限价 2市价
            "action": 0, //订单事件 0开仓 1平仓 2止损 3止盈 4强平 5FOK强平 6ADL减仓 7加仓 8反向开仓 9穿仓
            "side": 1, //  交易方向 1buy 2sell
            "positionID": "240904065638726010729", //仓位ID
            "price": "0", //订单价格，限价单才有值
            "leverage": 10, //杠杆
            "amount": "0.2", //下单量
            "frozen": "1128.5496", //冻结保证金  OpenPrice*Amount*BaseMarginRate
            "filledAmount": "0", //已完成量
            "filledPrice": "0", //成交均价
            "filledValue": "", //成交价值
            "triggerType": 1,//止盈止损触发类型 1成交价 2指数价
            "spPrice": "0", //预设止盈价
            "slPrice": "0", //预设止损价
            "state": 0, //状态 1正常 2已完成 3撤销 4部分成交 5部分成交已撤销 6撤销中
            "profit": "", //已实现盈亏（平仓订单使用）
            "fee": "", //手续费
            "pointFee": "", //积分(赠金)手续费抵扣
            "pointProfit": "", //积分(赠金)盈亏抵扣
            "closePrice": "", //破产价
            "triggerPrice": "", //触发价
            "createdAt": 1725432998726,
            "updatedAt": 0
        }
    ]
}
```

### **订阅账户资金变更(需要认证)**

请求json `{"event":"sub","topic":"user.balance"}`

#### **返回示例**

```json
{
  "type": "user.balance",
  "ts": 1725364751331,
  "data": {
    "balance": "4853.95", //余额usdt
    "frozen": "0", //挂单冻结保证金
    "margin": "1181.29", //持仓保证金
    "point": "0", ////赠金余额
    "loans": "", //借贷
    "profit": "0",  //未实现盈亏 unProfit+unLosses
    "unProfit": "0",  //未实现盈利  
    "unLosses": "0", //未实现亏损
    "coin": "usdt" //usdt
  }
}
```

<br>


---

# 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://apidoc.hibt.co/hibt-openapi-cn/he-yue-jiao-yi.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.
