# 杠杆交易

## 交易

### 安全类型: [TRADE](../general-info#jie-kou-jian-quan-lei-xing)

交易下方的接口都需要[签名和API-key验证](../general-info#xu-yao-qian-ming-de-jie-kou-trade-yu-userdata)

## &#x20;创建杠杆订单

<mark style="color:green;">`POST`</mark> `https://openapi.xxx.com/sapi/v1/margin/order`

**Demo:**\
`https://github.com/exchange2021/openapidemo/blob/master/src/main/java/com/margin/NewOrder.java` \
\
**限速规则：10次/s**

#### Headers

| Name        | Type    | Description |
| ----------- | ------- | ----------- |
| X-CH-SIGN   | string  |  签名         |
| X-CH-APIKEY | string  |  您的API-key  |
| X-CH-TS     | integer |  时间戳        |

#### Request Body

| Name             | Type   | Description            |
| ---------------- | ------ | ---------------------- |
| symbol           | string |  币对名称 E.g. `BTCUSDT`   |
| volume           | number |  订单数量                  |
| side             | string |  订单方向, `BUY/SELL`      |
| type             | string |  订单类型, `LIMIT/MARKET`  |
| price            | number |  订单价格, 对于`LIMIT`订单必须发送 |
| newClientOrderId | string |  客户端订单标识               |
| recvWindow       | string |  时间窗口                  |

{% tabs %}
{% tab title="200  发送杠杆订单成功" %}
```java
{
    'symbol': 'LXTUSDT', 
    'orderId': '494736827050147840', 
    'clientOrderId': '157371322565051',
    'transactTime': '1573713225668', 
    'price': '0.005452', 
    'origQty': '110', 
    'executedQty': '0', 
    'status': 'NEW',
    'type': 'LIMIT', 
    'side': 'SELL'
}
```
{% endtab %}
{% endtabs %}

## &#x20;杠杆订单查询

<mark style="color:blue;">`GET`</mark> `https://openapi.xxx.com/sapi/v1/margin/order`

**Demo:**\
`https://github.com/exchange2021/openapidemo/blob/master/src/main/java/com/margin/QueryOrder.java`\


#### Query Parameters

| Name             | Type   | Description         |
| ---------------- | ------ | ------------------- |
| orderId          | string |  订单ID               |
| newClientOrderId | string |  客户端订单标识            |
| symbol           | string |  币对名称E.g. `BTCUSDT` |

#### Headers

| Name        | Type    | Description |
| ----------- | ------- | ----------- |
| X-CH-SIGN   | string  |  签名         |
| X-CH-APIKEY | string  |  您的API-key  |
| X-CH-TS     | integer |  时间戳        |

{% tabs %}
{% tab title="200 " %}
```java
{
    'orderId': '499890200602846976', 
    'clientOrderId': '157432755564968', 
    'symbol': 'BHTUSDT', 
    'price': '0.01', 
    'origQty': '50', 
    'executedQty': '0', 
    'avgPrice': '0', 
    'status': 'NEW', 
    'type': 'LIMIT', 
    'side': 'BUY', 
    'transactTime': '1574327555669'
}
```
{% endtab %}
{% endtabs %}

## &#x20;撤销杠杆订单

<mark style="color:green;">`POST`</mark> `https://openapi.xxx.com/sapi/v1/margin/cancel`

**Demo:**\
`https://github.com/exchange2021/openapidemo/blob/master/src/main/java/com/margin/CancelOrder.java`\


#### Headers

| Name        | Type    | Description |
| ----------- | ------- | ----------- |
| X-CH-SIGN   | string  |  签名         |
| X-CH-APIKEY | string  |  您的API-key  |
| X-CH-TS     | integer |  时间戳        |

#### Request Body

| Name             | Type   | Description         |
| ---------------- | ------ | ------------------- |
| orderId          | string |  订单id               |
| newClientOrderId | string |  客户端订单标识            |
| symbol           | string |  币对名称E.g. `BTCUSDT` |

{% tabs %}
{% tab title="200 " %}
```java
{
    'symbol': 'BHTUSDT', 
    'clientOrderId': '0', 
    'orderId': '499890200602846976', 
    'status': 'CANCELED'
}
```
{% endtab %}
{% endtabs %}

## &#x20;杠杆当前委托

<mark style="color:blue;">`GET`</mark> `https://openapi.xxx.com/sapi/v1/margin/openOrders`

**Demo:**\
`https://github.com/exchange2021/openapidemo/blob/master/src/main/java/com/margin/CurrentOpenOrders.java`\


#### Query Parameters

| Name   | Type    | Description          |
| ------ | ------- | -------------------- |
| symbol | string  |  币对名称 E.g. `BTCUSDT` |
| limit  | integer |  默认100; 最大1000       |

#### Headers

| Name        | Type    | Description |
| ----------- | ------- | ----------- |
| X-CH-SIGN   | string  |  签名         |
| X-CH-APIKEY | string  |  您的API-key  |
| X-CH-TS     | integer |  时间戳        |

{% tabs %}
{% tab title="200 " %}
```java
[
    {
        'orderId': '499902955766523648', 
        'symbol': 'BHTUSDT', 
        'price': '0.01', 
        'origQty': '50', 
        'executedQty': '0', 
        'avgPrice': '0', 
        'status': 'NEW', 
        'type': 'LIMIT', 
        'side': 'BUY', 
        'time': '1574329076202'
        },...
]
```
{% endtab %}
{% endtabs %}

## &#x20;杠杆交易记录

<mark style="color:blue;">`GET`</mark> `https://openapi.xxx.com/sapi/v1/margin/myTrades`

**Demo:**\
`https://github.com/exchange2021/openapidemo/blob/master/src/main/java/com/margin/Trades.java`\


#### Query Parameters

| Name   | Type    | Description          |
| ------ | ------- | -------------------- |
| symbol | string  |  币对名称 E.g. `BTCUSDT` |
| limit  | integer |  默认100; 最大1000       |
| fromId | integer |  从这个tradeId开始检索      |

#### Headers

| Name        | Type    | Description |
| ----------- | ------- | ----------- |
| X-CH-SIGN   | string  |  签名         |
| X-CH-APIKEY | string  |  您的API-key  |
| X-CH-TS     | integer |  时间戳        |

{% tabs %}
{% tab title="200 " %}
```java
[
  {
    "symbol": "ETHBTC",
    "id": 100211,
    "bidId": 150695552109032492,
    "askId": 150695552109032493,
    "price": "4.00000100",
    "qty": "12.00000000",
    "time": 1499865549590,
    "isBuyer": true,
    "isMaker": false,
    "feeCoin": "ETH",
    "fee":"0.001"
  },...
]
```
{% endtab %}
{% endtabs %}
