# Get KLine Data

#### /sapi/v1/market/history/kline

Request type: GET

Signature verification: No

Interface permission: Read

Rate Limit: For public interface to get market data such as Get Kline data, Get Market Data Overview, Get Contract Information,Get market in-depth data, Get premium index Kline, Get real-time forecast capital rate kline, Get basis data, Get the last Trade of a Contract and so on： （1）For restful interfaces, products, (future, coin margined swap, usdt margined Contracts)800 times/second for one IP at most

Interface description: The interface supports cross margin mode and isolated margin mode. The request parameter "contract\_code" supports the contract code of futures, in that the format is BTC-USDT-210625; and supports contract type: BTC-USDT, BTC-USDT-CW, BTC-USDT-NW, BTC-USDT-CQ, BTC-USDT-NQ.

### Request Address

| Environment                         | Address                                     |
| ----------------------------------- | ------------------------------------------- |
| Online                              | [https://api.sunx.io](https://api.sunx.io/) |
| Online (preferred by aws customers) | [https://api.sunx.io](https://api.sunx.io/) |

### Request Parameter

| Parameter      | Data Type | Required | Description                    | Value Range                                                                                               | Default Value |
| -------------- | --------- | -------- | ------------------------------ | --------------------------------------------------------------------------------------------------------- | ------------- |
| contract\_code | string    | true     | contract code or contract type | swap: "BTC-USDT"... , future: "BTC-USDT-220325" ... or BTC-USDT-CW, BTC-USDT-NW, BTC-USDT-CQ, BTC-USDT-NQ |               |
| period         | string    | true     | KLine Type                     | 1min, 5min, 15min, 30min, 60min, 1hour,4hour,1day, 1mon                                                   |               |
| size           | int       | false    | Acquisition Quantity           | \[1,2000]                                                                                                 | 150           |
| from           | long      | false    | start timestamp seconds.       |                                                                                                           |               |
| to             | long      | false    | end timestamp seconds          |                                                                                                           |               |

Notes: \
Either size field or from and to fields need to be filled.\
If size field and from/to fields are not filled, It will return error messages.\
If from field is filled, to field need to filled too.\
The api can mostly return the klines of last two years.\
If from to size are all filled,'from' and 'to' will be ignored.

### Response Parameter

| Parameter       | Data Type  | Required | Description                                                                                                                                        | Value Range |
| --------------- | ---------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| ch              | string     | true     | Data belonged channel，Format： market.period                                                                                                        |             |
| status          | string     | true     | Request Processing Result                                                                                                                          |             |
| ts              | long       | true     | Time of Respond Generation, Unit: Millisecond                                                                                                      |             |
| \<data>         | kline data | false    |                                                                                                                                                    |             |
| id              | long       | true     | kline id,the same as kline timestamp, kline start timestamp                                                                                        |             |
| vol             | decimal    | true     | Trade Volume(Cont.) . Sum of both buy and sell sides                                                                                               |             |
| count           | decimal    | true     | Order Quantity. Sum of both buy and sell sides                                                                                                     |             |
| open            | decimal    | true     | Open Price                                                                                                                                         |             |
| close           | decimal    | true     | Clos Price, the price in the last kline is the latest order price                                                                                  |             |
| low             | decimal    | true     | Low Price                                                                                                                                          |             |
| high            | decimal    | true     | High Price                                                                                                                                         |             |
| amount          | decimal    | true     | Trade Amount(Coin), trade amount(coin)=sum(order quantity of a single order \* face value of the coin/order price). Sum of both buy and sell sides |             |
| trade\_turnover | decimal    | true     | Transaction amount, that is, sum (transaction quantity \* contract face value \* transaction price). Sum of both buy and sell sides                |             |
| \</data>        |            | false    |                                                                                                                                                    |             |

### Request Example

```
GET https://api.sunx.io/sapi/v1/market/history/kline?contract_code=BTC-USDT&period=1day
```

### Response Example

```
{
    "ch": "market.BTC-USDT.kline.1day",
    "ts": 1757931133018,
    "status": "ok",
    "data": [
        {
            "id": 1757433600,
            "open": 113608.0,
            "close": 113862.3,
            "high": 114263.7,
            "low": 113340.9,
            "amount": 1.16,
            "vol": 1160,
            "trade_turnover": 132119.9386,
            "count": 579
        },
        {
            "id": 1757520000,
            "open": 113818.2,
            "close": 114209.0,
            "high": 114682.5,
            "low": 113131.5,
            "amount": 11.132,
            "vol": 11132,
            "trade_turnover": 1268248.2292,
            "count": 5491
        }
    ]
}
```
