只读接口,数据与网站前端实时一致。Base URL:https://nbchannel.pythonanywhere.com 或 https://api.nb-channel.top
/api/market(含子路径与导出)、/api/comments、/api/stats
需要带 X-API-Key 请求头,否则返回 401 UNAUTHORIZED。curl -H "X-API-Key: 你申请到的Key" "https://api.nb-channel.top/api/market"请用请求头而不是
?key= 参数(URL 会进日志与 referrer),也不要把 Key 提交到公开仓库。/api/bili-fans 与 /api/docs 仍然完全公开,不需要 Key。
成功:{"success": true, "code": "OK", ...数据字段};失败:{"success": false, "code": "错误码", "message": "说明"}
| 错误码 | HTTP | 含义 |
|---|---|---|
OK | 200 | 成功 |
UNAUTHORIZED | 401 | API Key 缺失或错误(请带 X-API-Key 请求头) |
RATE_LIMITED | 429 | 请求过于频繁(每 IP 每分钟 60 次) |
NOT_FOUND | 404 | 公司不存在 |
INVALID_PARAM | 400 | 参数不合法 |
DB_ERROR | 500 | 后端数据库异常 |
/api/market — 全市场快照
参数:name(可选,按公司名模糊查询,最多50家)
curl -H "X-API-Key: 你的Key" "https://api.nb-channel.top/api/market" curl -H "X-API-Key: 你的Key" "https://api.nb-channel.top/api/market?name=NB"
/api/market/<company_id> — 单家公司市值
curl -H "X-API-Key: 你的Key" "https://api.nb-channel.top/api/market/1"
/api/market/<company_id>/history — 历史K线(市值走势点)
参数:days(可选,默认 7,范围 1~30)
curl -H "X-API-Key: 你的Key" "https://api.nb-channel.top/api/market/1/history?days=7"
/api/market/export?format=csv — 全市场快照导出(CSV 文件下载)
curl -H "X-API-Key: 你的Key" "https://api.nb-channel.top/api/market/export?format=csv" -o market.csv
/api/comments — 最新评论(只读)
参数:page(默认 1)、limit(默认 20,最大 50)、page_path(可选,按页面筛选,如 comments-beta.html)
响应含 total(总评论数)与 page_count(总页数,按当前 limit 计算)
curl -H "X-API-Key: 你的Key" "https://api.nb-channel.top/api/comments?page=1&limit=20" curl -H "X-API-Key: 你的Key" "https://api.nb-channel.top/api/comments?page_path=comments-beta.html"
/api/stats — API 用量统计(当日请求数/端点分布/限流次数)
curl -H "X-API-Key: 你的Key" "https://api.nb-channel.top/api/stats"
/api/docs — 本文档
{
"success": true,
"code": "OK",
"as_of": "2026-08-19T12:00:00+00:00",
"total_market_value": 1234567,
"count": 54,
"companies": [
{"id": 1, "name": "NB频道", "market_value": 148467, "owner": "NB搞事局"}
]
}
{
"success": true,
"code": "OK",
"as_of": "2026-08-19T12:00:00+00:00",
"company_id": 1,
"name": "NB频道",
"days": 7,
"points_count": 900,
"points": [
{"t": "2026-08-19T03:55:00+00:00", "v": 148467}
]
}
完整 SDK 示例见仓库 api-sdk/ 目录(python_example.py / js_example.js)。
from python_example import NBMarket nb = NBMarket() # 或 NBMarket(base_url="https://nbchannel.pythonanywhere.com") market = nb.market() # 全市场 print(market["total_market_value"]) print(nb.market(name="NB")) # 按名模糊查询 print(nb.market_by_id(3)) # 单公司 print(nb.history(3, days=7)) # 历史K线 comments = nb.comments(page=1, limit=10) # 评论(含 total / page_count) print(comments["total"], comments["page_count"])
// 浏览器:<script src="js_example.js"> 后直接用 window.NBMarket
const market = await NBMarket.market();
console.log(market.total_market_value);
const one = await NBMarket.marketById(3);
const kline = await NBMarket.history(3, 7);
const comments = await NBMarket.comments(1, 10);
console.log('共', comments.total, '条,', comments.page_count, '页');
| 字段 | 说明 |
|---|---|
as_of | 数据生成时间(UTC ISO8601),调用方可判断数据新旧 |
market_value | 公司当前市值(NB币) |
t / v | K线采样时间 / 该时刻市值 |
owner | 公司归属用户名 |
X-RateLimit-Limit / X-RateLimit-Remaining 可查剩余/api/virtual-market-value、/api/Virtual market value 与 /api/market 等价