# POST /v1/archive/history

自 2023 年以来的长期归档价格、总供应量和成交量。

返回 BUFF、Youpin、C5Game 和 `aggregate` 序列的长期挂单价格历史。数据始于 2023 年，每天约更新 1-2 次。每次请求最多 100 个饰品。

在每个分桶内，价格、挂单数量和 `total_supply` 均为最后观测值。`hourly_volume` 是近似成交数量：`1h` 响应中为每小时估算值，`1d` 分桶中为当天各小时估算值之和。

## 访问

需要 Scale 或 Enterprise API 密钥。

## 支持的间隔

| 间隔 | 分桶 |
| --- | --- |
| `1h` | 小时归档分桶 |
| `1d` | 日归档分桶 |

## 支持的来源

| 来源 | 字段 |
| --- | --- |
| `aggregate` | `ask`, `bid`, `ask_volume`, `bid_volume`, `hourly_volume`, `total_supply` |
| `buff` | `ask`, `bid`, `ask_volume`, `bid_volume` |
| `youpin` | `ask`, `bid`, `ask_volume`, `bid_volume` |
| `c5game` | `ask`, `bid`, `ask_volume`, `bid_volume` |

默认仅返回 `aggregate`。

## 请求

`POST https://api.cs2.sh/v1/archive/history`

**curl**

```bash
curl -X POST https://api.cs2.sh/v1/archive/history \
  -H "Authorization: Bearer <<YOUR_API_KEY>>" \
  -H "Accept-Encoding: gzip" --compressed \
  -H "Content-Type: application/json" \
  -d '{
  "items": [
    "USP-S | Printstream (Factory New)"
  ],
  "start": "2024-01-01",
  "end": "2026-07-26",
  "sources": [
    "aggregate",
    "buff"
  ],
  "interval": "1d"
}'
```

**Python**

```python
import requests

headers = {
    "Authorization": "Bearer <<YOUR_API_KEY>>",
    "Accept-Encoding": "gzip",
    "Content-Type": "application/json",
}

payload = {
    "items": ["USP-S | Printstream (Factory New)"],
    "start": "2024-01-01",
    "end": "2026-07-26",
    "sources": ["aggregate", "buff"],
    "interval": "1d",
}

response = requests.post(
    "https://api.cs2.sh/v1/archive/history",
    headers=headers,
    json=payload,
)

response.raise_for_status()
data = response.json()
```

**Node**

```javascript
const headers = {
  "Authorization": "Bearer <<YOUR_API_KEY>>",
  "Accept-Encoding": "gzip",
  "Content-Type": "application/json",
};

const response = await fetch("https://api.cs2.sh/v1/archive/history", {
  method: "POST",
  headers,
  body: JSON.stringify({
    "items": [
      "USP-S | Printstream (Factory New)"
    ],
    "start": "2024-01-01",
    "end": "2026-07-26",
    "sources": [
      "aggregate",
      "buff"
    ],
    "interval": "1d"
  }),
});

if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
```

**Go**

```go
package main

import (
    "bytes"
    "compress/gzip"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    payload := map[string]any{
        "items": []any{
            "USP-S | Printstream (Factory New)",
        },
        "start": "2024-01-01",
        "end": "2026-07-26",
        "sources": []any{
            "aggregate",
            "buff",
        },
        "interval": "1d",
    }
    body, _ := json.Marshal(payload)
    req, _ := http.NewRequest("POST", "https://api.cs2.sh/v1/archive/history", bytes.NewReader(body))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("Authorization", "Bearer <<YOUR_API_KEY>>")
    req.Header.Set("Accept-Encoding", "gzip")

    resp, err := http.DefaultClient.Do(req)
    if err != nil { panic(err) }
    defer resp.Body.Close()

    if resp.StatusCode < 200 || resp.StatusCode >= 300 {
        body, _ := io.ReadAll(resp.Body)
        panic(fmt.Sprintf("HTTP %d: %s", resp.StatusCode, body))
    }

    var reader io.Reader = resp.Body
    if resp.Header.Get("Content-Encoding") == "gzip" {
        gz, err := gzip.NewReader(resp.Body)
        if err != nil { panic(err) }
        defer gz.Close()
        reader = gz
    }

    var data any
    if err := json.NewDecoder(reader).Decode(&data); err != nil { panic(err) }
    fmt.Printf("%#v\n", data)
}
```

**R**

```r
library(httr2)

payload <- list(
  items = list(
    "USP-S | Printstream (Factory New)"
  ),
  start = "2024-01-01",
  end = "2026-07-26",
  sources = list(
    "aggregate",
    "buff"
  ),
  interval = "1d"
)

resp <- request("https://api.cs2.sh/v1/archive/history") |>
  req_headers(
    Authorization = "Bearer <<YOUR_API_KEY>>",
    `Accept-Encoding` = "gzip"
  ) |>
  req_body_json(payload) |>
  req_perform()

data <- resp_body_json(resp)
```

## 参数

| 字段 | 类型 | 必需 | 描述 |
| --- | --- | --- | --- |
| `items` | `string[]` | 是 | `market_hash_name` 值列表（最多 100 个） |
| `start` | `string` | 是 | 开始日期（YYYY-MM-DD 或 RFC3339） |
| `end` | `string` | 否 | 结束日期（YYYY-MM-DD 或 RFC3339）。默认现在。 |
| `sources` | `string[]` | 否 | 过滤到指定来源。默认：仅 aggregate。 |
| `interval` | `string` | 否 | 默认值: `1d`. 允许值: `1h`, `1d`. 聚合间隔 |

## 响应

```json
{
  "response_time": "2026-07-26T18:54:19.138233339Z",
  "currency": "USD",
  "start": "2026-04-27T00:00:00Z",
  "end": "2026-07-25T00:00:00Z",
  "interval": "1d",
  "items": {
    "USP-S | Printstream (Factory New)": {
      "market_hash_name": "USP-S | Printstream (Factory New)",
      "count": 89,
      "data": [
        {
          "bucket": "2026-04-27T00:00:00Z",
          "aggregate": {
            "time": "2026-04-27T23:59:07Z",
            "ask": 130.05,
            "ask_volume": 1225,
            "bid": 130.19,
            "bid_volume": 133,
            "hourly_volume": 27,
            "total_supply": 31291,
            "sample_count": 24
          },
          "buff": {
            "time": "2026-04-27T23:53:24Z",
            "ask": 133.12,
            "ask_volume": 405,
            "bid": 130.19,
            "bid_volume": 45,
            "sample_count": 24
          },
          "youpin": {
            "time": "2026-04-27T23:59:07Z",
            "ask": 130.05,
            "ask_volume": 510,
            "bid": 128.59,
            "bid_volume": 63,
            "sample_count": 24
          },
          "c5game": {
            "time": "2026-04-27T23:57:07Z",
            "ask": 132.21,
            "ask_volume": 139,
            "bid": 213.58,
            "bid_volume": 24,
            "sample_count": 24
          }
        }
      ]
    }
  }
}
```

## 响应字段

[ArchiveHistoryResponse](/zh-cn/docs/objects#archivehistoryresponse) 字段:

| 字段 | 类型 | 必需 | 描述 |
| --- | --- | --- | --- |
| `response_time` | `string (date-time)` | 是 | 响应生成时间。 |
| `currency` | `string` | 是 | 货币代码（始终为 `USD`）。 |
| `start` | `string (date-time)` | 是 | 查询范围的有效开始时间，向下取整到间隔边界。 |
| `end` | `string (date-time)` | 是 | 查询范围的有效结束时间，向上取整到间隔边界。不包含该时间。 |
| `interval` | `string` | 是 | 允许值: `1h`, `1d`. 归档分桶大小。 |
| `items` | [`Record<string, ArchiveHistoryItem>`](/zh-cn/docs/objects#archivehistoryitem) | 是 | `market_hash_name` 到归档时间序列的映射。 |
| `errors` | [ItemError[]](/zh-cn/docs/objects#itemerror) | 否 | 与成功结果一起返回的逐饰品失败（部分成功）。 |

## 分桶

| 字段 | 描述 |
| --- | --- |
| `items.<name>.count` | 有数据的分桶数。 |
| `items.<name>.data[]` | 归档分桶。 |
| `data[].bucket` | 分桶边界。 |
| `data[].<platform>` | 最后观测的 `ask`/`bid` 和 `ask_volume`/`bid_volume`，附带 `time` 和 `sample_count`。平台：`aggregate`、`buff`、`youpin`、`c5game`。 |
| `data[].aggregate.hourly_volume` | 该分桶内的大致成交数量。`1h` 为小时值，`1d` 为当天各小时的总和。 |
| `data[].aggregate.total_supply` | 该饰品的大致累计供应量。仅 `aggregate`。 |

- 每个归档分桶上都存在 `bucket`。
- 平台对象仅在该平台在该分桶中有数据时出现。
- 没有归档数据的有效请求饰品返回 `not_in_archive`。

完整结构：[ArchiveHistoryItem](/zh-cn/docs/objects#archivehistoryitem)、[ArchiveHistoryBucket](/zh-cn/docs/objects#archivehistorybucket)、[ArchiveHistoryPlatformData](/zh-cn/docs/objects#archivehistoryplatformdata)。

### ArchiveHistoryItem

单个饰品的长期归档时间序列。

| 字段 | 类型 | 必需 | 描述 |
| --- | --- | --- | --- |
| `market_hash_name` | `string` | 是 | Steam 市场哈希名称。 |
| `count` | `integer` | 是 | 有数据的分桶数量。 |
| `data` | [ArchiveHistoryBucket[]](/zh-cn/docs/objects#archivehistorybucket) | 是 | 按时间顺序排列的归档分桶。 |
| `variants` | `Record<string, object>` | 否 | 带有 Doppler / Gamma Doppler 相位或 Case Hardened 分层的饰品的逐变体归档时间序列。按显示名称作为键。 |

### ArchiveHistoryBucket

单个归档时间分桶。只有当该平台在此分桶中存在数据时，对应平台键才会出现。

| 字段 | 类型 | 必需 | 描述 |
| --- | --- | --- | --- |
| `bucket` | `string (date-time)` | 是 | 时间分桶的开始时间（UTC 对齐到间隔边界）。 |
| `aggregate` | [ArchiveHistoryPlatformData](/zh-cn/docs/objects#archivehistoryplatformdata) | 否 | 归档分桶内的逐平台价格数据。`hourly_volume` 和 `total_supply` 仅在 `aggregate` 平台上填充。 |
| `buff` | [ArchiveHistoryPlatformData](/zh-cn/docs/objects#archivehistoryplatformdata) | 否 | 归档分桶内的逐平台价格数据。`hourly_volume` 和 `total_supply` 仅在 `aggregate` 平台上填充。 |
| `youpin` | [ArchiveHistoryPlatformData](/zh-cn/docs/objects#archivehistoryplatformdata) | 否 | 归档分桶内的逐平台价格数据。`hourly_volume` 和 `total_supply` 仅在 `aggregate` 平台上填充。 |
| `c5game` | [ArchiveHistoryPlatformData](/zh-cn/docs/objects#archivehistoryplatformdata) | 否 | 归档分桶内的逐平台价格数据。`hourly_volume` 和 `total_supply` 仅在 `aggregate` 平台上填充。 |

### ArchiveHistoryPlatformData

归档分桶内的逐平台价格数据。`hourly_volume` 和 `total_supply` 仅在 `aggregate` 平台上填充。

| 字段 | 类型 | 必需 | 描述 |
| --- | --- | --- | --- |
| `time` | `string (date-time)` | 是 | 分桶内最后一次观测的实际时间戳。不同于分桶边界。 |
| `ask` | `number \| null` | 是 | 分桶内最后观测到的 ask 价格（USD）。 |
| `ask_volume` | `integer \| null` | 是 | 最后观测到的在售饰品数量。 |
| `bid` | `number \| null` | 是 | 分桶内最后观测到的 bid 价格（USD）。 |
| `bid_volume` | `integer \| null` | 是 | 最后观测到的求购单数量。 |
| `hourly_volume` | `number \| null` | 否 | 聚合交易量指标（仅 `aggregate` 平台）。 |
| `total_supply` | `number \| null` | 否 | 总市场供应量指标（仅 `aggregate` 平台）。 |
| `sample_count` | `integer` | 是 | 聚合到此分桶的观测数量。 |

## 错误

`404 not_found` 表示请求中的有效饰品均没有归档数据。部分结果返回 `200` 和 `errors[]`；饰品错误代码包括 `unknown_item`、`invalid_format` 和 `not_in_archive`。见[部分成功](/zh-cn/docs/using-the-api#部分成功)和[请求错误](/zh-cn/docs/using-the-api#请求错误)。
