> For the complete documentation index, see [llms.txt](https://docs.infoway.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.infoway.io/en-docs/rest-api/market-data/post-kline-archive-download.md). Agents can also search and read this documentation through its [MCP server](https://docs.infoway.io/~gitbook/mcp).

# POST Download Monthly Candle Archives

Get monthly historical candle ZIP download links by market and period, with the remaining daily request allowance.

### Overview

Request ZIP archive download links for one or more months, for a selected market and candle period. Each month has its own short-lived link. The successful response also includes the remaining successful-request allowance and the number of seconds until it resets.

If any requested month is outside your permissions or has no archive package, the entire request fails. A month within your permitted history window must still have an existing archive package to be downloadable.

### Endpoint

```http
POST https://data.infoway.io/kline/archive/download
```

### Request headers

| Header         | Type   | Required | Description        |
| -------------- | ------ | -------- | ------------------ |
| `apiKey`       | String | Yes      | Plan API key       |
| `Content-Type` | String | Yes      | `application/json` |

### Request parameters

| Parameter   | Type           | Required | Description                                                                                       |
| ----------- | -------------- | -------- | ------------------------------------------------------------------------------------------------- |
| `market`    | String         | Yes      | Market code from the table below                                                                  |
| `klineType` | Integer        | Yes      | `1` 1 minute; `2` 5 minutes; `3` 15 minutes; `4` 30 minutes; `5` 1 hour; `6` 2 hours; `7` 4 hours |
| `yyyyMM`    | Array\<String> | Yes      | Months in `yyyyMM` format, up to 36 distinct months, such as `["202609","202608"]`                |

| Market code | Market                                                            | Time zone used to determine calendar months |
| ----------- | ----------------------------------------------------------------- | ------------------------------------------- |
| `us`        | US equities                                                       | `America/New_York`                          |
| `hk`        | Hong Kong equities                                                | `Asia/Shanghai`                             |
| `cn`        | China A-shares                                                    | `Asia/Shanghai`                             |
| `common`    | Forex, energy, commodities, metals, futures, and related products | `UTC`                                       |
| `crypto`    | Crypto                                                            | `UTC`                                       |
| `in`        | India                                                             | `Asia/Kolkata`                              |
| `jp`        | Japan                                                             | `Asia/Tokyo`                                |
| `kr`        | Korea                                                             | `Asia/Seoul`                                |
| `tw`        | Taiwan                                                            | `Asia/Taipei`                               |

This endpoint supports minute and hour periods (1–7). Each request specifies one market and one period, with one or more months. Month entries are trimmed, blank entries are ignored, and duplicates are removed while preserving their first occurrence. The resulting month list must be nonempty.

```json
{
  "market": "crypto",
  "klineType": 1,
  "yyyyMM": ["202609", "202608"]
}
```

### Plan and month permissions

* The API key must belong to an active account with an unexpired plan. The Free plan cannot download monthly archives.
* Basic, Premium, Professional, and Custom plans can request archives for all markets, subject to the plan's history allowance.
* Market-specific plans allow only their corresponding markets: AllUSStocks for `us`, AllHongKongStocks for `hk`, AllA-ShareStocks for `cn`, and India/Japan/Korea/Taiwan for `in`/`jp`/`kr`/`tw`, respectively.
* Months are evaluated in the market time zone above, and only months before the current month are allowed. The earliest allowed month is the calendar month containing the current time minus the plan's allowed history in months; that entire month is eligible. Actual availability depends on whether the archive package exists.

### Request allowance and link expiry

The endpoint shares the standard HTTP [request rate limit](https://docs.infoway.io/en-docs/getting-started/api-limitation/rest-api-limitation.md) and also has a separate archive allowance:

* Each API key has **5 successful requests per UTC calendar day**, shared across markets. The allowance resets at 00:00 UTC.
* Requesting several packages successfully in one call uses **1 allowance**. Obtaining the links uses the allowance; downloading a ZIP does not require another call to this endpoint.
* Invalid parameters, denied access, and missing packages do not use a successful-request allowance.
* Each link is valid for **3 minutes**; `expireAt` gives its expiry time.

### Successful response

The following values illustrate the format. The example download URLs are not usable download links.

```json
{
  "ret": 200,
  "msg": "success",
  "traceId": "example-trace-id",
  "data": {
    "remaining": 4,
    "refreshInSeconds": 3600,
    "items": [
      {
        "yyyyMM": "202609",
        "archiveKey": "kline_1_202609",
        "downloadUrl": "https://example.invalid/crypto-202609.zip",
        "expireAt": 1791878580
      },
      {
        "yyyyMM": "202608",
        "archiveKey": "kline_1_202608",
        "downloadUrl": "https://example.invalid/crypto-202608.zip",
        "expireAt": 1791878580
      }
    ]
  }
}
```

| Field                   | Type    | Description                                                                     |
| ----------------------- | ------- | ------------------------------------------------------------------------------- |
| `data.remaining`        | Integer | Successful-request allowance remaining after this request                       |
| `data.refreshInSeconds` | Long    | Seconds until the next 00:00 UTC                                                |
| `data.items`            | Array   | One download entry per month, in the order of the deduplicated requested months |
| `items[].yyyyMM`        | String  | Month                                                                           |
| `items[].archiveKey`    | String  | Archive identifier: `kline_<klineType>_<yyyyMM>`                                |
| `items[].downloadUrl`   | String  | Short-lived URL for the monthly archive package                                 |
| `items[].expireAt`      | Long    | Link expiry time, in Unix **seconds**                                           |

Use GET on the returned `downloadUrl` to download the file. Keep the full URL intact and use it before it expires.

### Error responses

The following numbers are business codes in the JSON `ret` field. For HTTP statuses and shared behavior, see [REST API Error Codes](https://docs.infoway.io/en-docs/getting-started/error-codes/rest-api-error-codes.md).

| `ret` | Condition                                                                                      |
| ----- | ---------------------------------------------------------------------------------------------- |
| `404` | An archive package is missing: `Archive not found: kline_<type>_<yyyyMM>`                      |
| `502` | The daily allowance of 5 successful requests is exhausted                                      |
| `506` | Unsupported market/period, invalid month, or too many months                                   |
| `507` | A required parameter is missing, or the month list is empty                                    |
| `509` | The plan has expired                                                                           |
| `513` | Current/future month or a month outside the plan history window: `Month not allowed: <yyyyMM>` |
| `514` | Account status disallows access, the plan is Free, or the market is not permitted              |

When the allowance is exhausted, the response still includes the reset countdown:

```json
{
  "ret": 502,
  "msg": "Request frequency for the day upper limit：5",
  "traceId": "example-trace-id",
  "data": {
    "remaining": 0,
    "refreshInSeconds": 3600
  }
}
```
