# Margin

## Trade

### Security Type: [TRADE](https://exdocs.gitbook.io/v/english/general-info#endpoint-security-type)

Endpoints under **Trade** require an [API-key and a signature.​](https://exdocs.gitbook.io/v/english/general-info#signed-trade-yu-userdata-endpoint-security)

## &#x20;New Order

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

**Rate Limit：100times/2s**

#### Headers

| Name        | Type    | Description  |
| ----------- | ------- | ------------ |
| X-CH-SIGN   | string  | Sign         |
| X-CH-APIKEY | string  | Your API-key |
| X-CH-TS     | integer | timestamp    |

#### Request Body

| Name             | Type   | Description                                             |
| ---------------- | ------ | ------------------------------------------------------- |
| symbol           | string | Symbol Name. E.g. `BTCUSDT`                             |
| volume           | number | Order vol. For MARKET BUY orders, vol=amount.           |
| side             | string | Side of the order, `BUY/SELL`                           |
| type             | string | Type of the order, `LIMIT/MARKET`                       |
| price            | number | Order price, REQUIRED for LIMIT orders                  |
| newClientOrderId | string | Unique order ID generated by users to mark their orders |
| recvWindow       | string | Time window                                             |

{% 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;Query Order

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

**Rate Limit: 20times/2s**

#### Query Parameters

| Name             | Type   | Description                                                                                      |
| ---------------- | ------ | ------------------------------------------------------------------------------------------------ |
| orderId          | string | Order ID                                                                                         |
| newClientOrderId | string | Client Order Id, Unique order ID generated by users to mark their orders. E.g. 354444heihieddada |
| symbol           | string | Symbol Name.E.g. `BTCUSDT`                                                                       |

#### Headers

| Name        | Type    | Description  |
| ----------- | ------- | ------------ |
| X-CH-SIGN   | string  | Sign         |
| X-CH-APIKEY | string  | Your API-key |
| X-CH-TS     | integer | timestamp    |

{% 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;Cancel Order

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

**Rate Limit: 100times/2s**

#### Headers

| Name        | Type    | Description  |
| ----------- | ------- | ------------ |
| X-CH-SIGN   | string  | Sign         |
| X-CH-APIKEY | string  | Your API-key |
| X-CH-TS     | integer | timestamp    |

#### Request Body

| Name             | Type   | Description                                                                                      |
| ---------------- | ------ | ------------------------------------------------------------------------------------------------ |
| orderId          | string | Order ID                                                                                         |
| newClientOrderId | string | Client Order Id, Unique order ID generated by users to mark their orders. E.g. 354444heihieddada |
| symbol           | string | Symbol Name. E.g. `BTCUSDT`                                                                      |

{% tabs %}
{% tab title="200 " %}

```java
{
    'symbol': 'BHTUSDT', 
    'clientOrderId': '0', 
    'orderId': '499890200602846976', 
    'status': 'CANCELED'
}
```

{% endtab %}
{% endtabs %}

## &#x20;Current Open Orders

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

**Rate Limit: 20times/2s**

#### Query Parameters

| Name   | Type   | Description                 |
| ------ | ------ | --------------------------- |
| symbol | string | Symbol Name. E.g. `BTCUSDT` |
| limit  | string | Default 100; Max 1000       |

#### Headers

| Name        | Type    | Description  |
| ----------- | ------- | ------------ |
| X-CH-SIGN   | string  | Sign         |
| X-CH-APIKEY | string  | Your API-key |
| X-CH-TS     | integer | timestamp    |

{% 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;Trades

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

**Rate Limit: 20times/2s**

#### Query Parameters

| Name   | Type    | Description                 |
| ------ | ------- | --------------------------- |
| symbol | string  | Symbol Name. E.g. `BTCUSDT` |
| limit  | string  | Default 100; Max 1000       |
| fromId | integer | Trade Id to fetch from      |

#### Headers

| Name        | Type    | Description  |
| ----------- | ------- | ------------ |
| X-CH-SIGN   | string  | Sign         |
| X-CH-APIKEY | string  | Your API-key |
| X-CH-TS     | integer | timestamp    |

{% 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 %}
