跳转至

用户手册

行情只通过 POST /api/v1/query 读取。金额、权重、点位和涨跌在线上都是十进制定点字符串,日期输出 YYYYMMDD,形态为 fields + items

身份 怎么带 能看到什么
API Key 请求头 X-API-Key 按 Key 的 scope、指数范围和会员时效返回。Key 无效或权限不足直接失败
网站会话 浏览器 Cookie,不带 Key 与该登录账户相同的时效和会员指数;不返回 private 指数
免费访客 不带 Key、也没有会话 与免费用户相同:延迟行情,不含会员指数

网站身份下,只有 visibility = aggregate 的指数返回 weighted_price 和规格报价;index_only 只返回点位。API Key 只要具备对应 scope,就返回该数据集的完整字段。

输入日期接受 YYYYMMDDYYYY-MM-DD。Python SDK 把查询结果转成 DataFrame:日期列为 datetime64,点位和价格列为 float64

指数系列

当前维护 7 个报价指数。visibility 与后台「公开级别」一一对应。Hardware_Index 由六个基础指数派生,只对会员开放,没有规格报价,租赁指数不参与计算。

index_code 名称 visibility 公开级别 规格报价
Server_Index AI 服务器售价指数 aggregate 公开点位与整体价格
Server_Rental_Index AI 服务器租赁指数 aggregate 公开点位与整体价格
GPU_Index 算力卡指数 index_only 仅公开指数点位
DRAM_Index 内存指数 index_only 仅公开指数点位
SSD_Index 固态存储指数 index_only 仅公开指数点位
CPU_Index 处理器指数 index_only 仅公开指数点位
OI_Index 光互联指数 index_only 仅公开指数点位
Hardware_Index 算力硬件指数 member 仅会员

展示顺序是 index_basic.sort_no 升序,再按 index_code。后台可以调整排序,调用方不要把上表顺序写死。

统一查询协议

1
2
3
POST /api/v1/query
Content-Type: application/json
X-API-Key: tokease_xxxxxxxxxxxx_xxxxxxxx

请求体

{
  "api_name": "index_daily",
  "params": {
    "index_code": "Server_Index",
    "start_date": "20260801",
    "end_date": "20260831"
  },
  "fields": ["trade_date", "index_code", "weighted_price", "index_value"],
  "limit": 1000,
  "offset": 0
}
字段 类型 必填 说明
api_name string 数据集名称,仅允许本文列出的值
params object 查询条件;键和值均为字符串,每个数据集有独立白名单
fields string[] 返回列;省略或传空数组时使用该数据集默认字段
limit integer 每页行数,默认 1000,最小 1,最大 5000
offset integer 偏移量,默认 0

未知参数、未知字段或不属于该数据集的字段会返回 40001,不会拼接到 SQL 中。

成功响应

{
  "request_id": "req_01J5KQ9GQ3K7Y6W2R1D4N8F0VA",
  "code": 0,
  "message": "ok",
  "data": {
    "fields": ["trade_date", "index_code", "weighted_price", "index_value"],
    "items": [
      ["20260820", "Server_Index", "10020000.000000", "1000.000000"],
      ["20260821", "Server_Index", "10040040.000000", "1002.000000"]
    ],
    "limit": 1000,
    "offset": 0,
    "returned": 2,
    "has_more": false
  }
}

说明:

  • items[i][j] 是第 i 行第 j 个字段的值,列顺序与 fields 完全一致。
  • 日期统一输出 YYYYMMDD;时间戳统一输出 RFC 3339。
  • 金额、权重、点位与涨跌幅均为十进制定点字符串,避免浮点误差;请用 decimal 解析。
  • 查询没有数据仍返回 code: 0,此时 items: []
  • request_id 是本次请求的追踪 ID,报错反馈时应提供该值。

数据集一览

api_name 内容 scopes 要求 时效限制
index_basic 指数基本信息 index:read
index_daily 指数日线(点位 / 加权价格) index:read 有(会员才可查最新)
index_latest 每个可见指数的最新一条日线 index:read 有(会员才可查最新)
index_quote 规格报价明细 quote:read
trade_calendar 交易日历 calendar:read

scopes 与 Key

调用前需要在 API 密钥 页面创建 Key。新创建的 Key 默认具备全部公开数据集的读取权限:

Scope 可调用数据集
index:read index_basicindex_dailyindex_latest
quote:read index_quote
calendar:read trade_calendar

Key 还可以配置指数范围与有效期;会员 Key 可进一步配置 IP 白名单。具备 scope 并不代表可访问全部指数:免费用户可访问 7 个公开指数,专业会员可访问 8 个指数系列(额外含会员专享指数 Hardware_Index)。

通用参数约定

  • 业务日期:8 位字符串 YYYYMMDD,例如 20260820
  • start_dateend_date 均为包含边界start_date 不得晚于 end_date
  • trade_date 与日期区间参数不能在同一次请求中同时出现。
  • 保留 index_code 的原始大小写(推荐从 index_basic 获取,不要自行猜测)。
  • 未使用的过滤参数应直接省略,不要传空字符串。
  • 参数值均为字符串;一次请求只查一个指数,多个指数应分别查询或省略 index_code 分页读取。

排序与分页

各数据集采用稳定的升序排序:

数据集 排序键
index_basic sort_no, index_code
index_daily trade_date, index_code
index_latest sort_no, index_code
index_quote trade_date, index_code, specification
trade_calendar trade_date

分页方式为 limit + offset

  1. 首次请求传 limit: 1000, offset: 0
  2. has_moretrue,下一次传 offset + returned
  3. 直到 has_morefalse

批量同步时应固定 end_date,避免翻页期间新增数据导致分页窗口变化。协议允许的 limit 最大值为 5000;服务端还可能用更小的实际上限压低页大小,客户端应以响应中的 data.limit 为准。

offset = 0
while True:
    resp = query({"api_name": "index_daily",
                  "params": {"index_code": "Server_Index",
                             "start_date": "20260101",
                             "end_date": "20261231"},
                  "limit": 1000, "offset": offset})
    rows.extend(resp["items"])
    if not resp["has_more"]:
        break
    offset += resp["returned"]

Python SDK

仓库提供 python/tokease。不发请求即可查看每个数据集的输入参数;配置 API Key 后按同一套参数查询。

pip install tokease

仓库内开发用 pip install -e python/tokease。发布方式见 python/tokease/README.md

import tokease

tokease.dataset_params("index_daily")

client = tokease.Client()  # 读取 TOKEASE_API_KEY,请求发往 pyproject.toml 的 Homepage
daily = client.index_daily(
    index_code="Server_Index",
    start_date="20260801",
    end_date="20260831",
)

dataset_params / dataset_fields / describe 覆盖统一查询的五个数据集。客户端会在本地拒绝未知参数、未知字段,以及 trade_date 与日期区间同时出现的请求。查询方法直接返回 DataFrame。Key 无效或权限不足时抛出异常;省略 index_code 时只返回该 Key 可见的数据。

其他接口

除统一查询接口外,本手册还覆盖:

  • 站点配置与会员状态:登录前的站点配置,以及当前会话的会员权益。这两项不是行情数据。
  • 错误码与限流:统一错误格式、错误码表、限流与额度规则。API Key 调用计入额度;网站身份的查询不计入 Key 额度。