自带数据算指标
POST /api/indicators/compute 让你用自己的 K 线调用引擎的 60+ 指标计算逻辑 —— 不依赖引擎的内存缓存,也不限定 venue / symbol。
适合场景:
- 回测:数据库 / CSV 里的历史 OHLCV 想跑指标
- 自定义数据源:对手交易所、聚合合约、你自己的 tick 重采样
- 离线分析:某段时段想验证指标值,但不想被引擎 cache 限制
不适合:
- 实时行情:走
POST /api/indicators让引擎从内存 store 取,延迟更低 - 跨周期(MTF)指标(比如 SMC 的
fvg_timeframe):这类参数需要引擎自己 prefetch 多周期数据,只能走 store 路径
30 秒上手
bash
curl -X POST 'https://api.mobiusquant.ai/api/indicators/compute' \
-H 'authorization: Bearer mq_xxx' \
-H 'content-type: application/json' \
-d '{
"klines": [
[1735689600000, 95000.0, 95500.0, 94800.0, 95200.0, 1234.5],
[1735693200000, 95200.0, 95800.0, 95100.0, 95650.0, 1500.2]
],
"interval": "1h",
"calc": [{"name": "rsi", "params": {"period": 14}}]
}'返回:
jsonc
{
"count": 2,
"interval": "1h",
"klines": [[1735689600000, 95000.0, ...], ...], // echo
"indicators": {
"rsi:period=14": {
"columns": ["open_time", "rsi"],
"data": [[1735689600000, null], [1735693200000, null]],
"explain": { /* knowledge: summary_focus / signals / caveats */ }
}
}
}RSI 在前 14 根之前返回 null —— 这是正常的,所有"累积型"指标都需要 warmup。详见下方限制。
Python 集成示例
python
import requests
import pandas as pd
# 从你自己的数据源拉历史 OHLCV
df = pd.read_csv('btc_1h_history.csv') # 列:open_time(ms), open, high, low, close, volume
klines = df[['open_time', 'open', 'high', 'low', 'close', 'volume']].values.tolist()
resp = requests.post(
'https://api.mobiusquant.ai/api/indicators/compute',
headers={'Authorization': 'Bearer mq_xxx'},
json={
'klines': klines,
'interval': '1h',
'calc': [
{'name': 'ema', 'params': {'period': 20}, 'id': 'ema20'},
{'name': 'ema', 'params': {'period': 200}, 'id': 'ema200'},
{'name': 'rsi', 'params': {'period': 14}},
],
},
)
result = resp.json()
print(result['indicators']['ema20']['data'][-1]) # 最新 EMA20 值
print(result['indicators']['rsi:period=14']['data'][-1])SMC 等"复合指标"也支持
像 SMC (Smart Money Concepts) 这种非数值输出指标,返回结果除了 per-bar columns 还会附带 objects sidecar:
bash
curl -X POST 'https://api.mobiusquant.ai/api/indicators/compute?explain=false' \
-H 'content-type: application/json' \
-d '{
"klines": [/* ≥500 根历史 K 线 */],
"calc": [{"id": "smc", "name": "smc",
"params": {"show_swing_points": true, "show_premium_discount_zones": true}}]
}'响应里 indicators.smc.objects 包含 swing_structures / order_blocks_swing / fair_value_gaps / premium_zone 等结构化对象,可以直接喂给 chart 渲染器或 LLM 分析。详见 SMC 指标页。
请求字段
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
klines | array | ✓ | OHLCV 数组,每根 K 线两种格式自动识别(见下) |
calc | array | ✓ | 指标列表,每项 {name, params, id?},跟 /api/indicators 同 |
interval | string | ✗ | 仅元数据,响应回显;某些 MTF 指标用不到 |
echo_klines | bool | ✗ | 默认 true,响应回 echo;false 时只返指标 |
klines 元素的两种格式:
jsonc
// 紧凑(Binance 嵌套列表风格):[open_time_ms, open, high, low, close, volume, quote_volume?]
[1735689600000, 95000.0, 95500.0, 94800.0, 95200.0, 1234.5, 117526200.0]
// 对象(更显式)
{
"open_time": 1735689600000,
"open": 95000.0,
"high": 95500.0,
"low": 94800.0,
"close": 95200.0,
"volume": 1234.5,
"quote_volume": 117526200.0 // 可选,部分指标用(VWAP / CVD 等);缺省补 0
}响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
count | int | 处理的 K 线根数 |
interval | string | 回显 request 里的 interval(传了才有) |
klines | array | echo 输入的 K 线(echo_klines=false 时省略) |
indicators | object | key = id 或自动生成的 name:p1=v1,...,value = 单个指标的 columns/data/objects/explain |
每个 indicators.<key> 的结构跟 POST /api/indicators 完全一致:
jsonc
{
"columns": ["open_time", "rsi"],
"data": [[1735689600000, null], [1735693200000, 67.4], ...],
"objects": { /* 仅 SMC 等非数值指标 */ },
"explain": { /* knowledge: 仅 ?explain=true 时 */ }
}限制
| 限制 | 值 | 触发 |
|---|---|---|
| K 线数量 | ≤ 2000 根 | 超返 413 |
open_time | 严格单调递增的毫秒 | 否则 400 |
| OHLCV | 必须 finite(无 NaN / inf) | 否则 400 |
calc 列表 | 非空,且 name 必须在 registry 里 | 否则 400 |
calc 非法参数 | Pydantic / signature 校验 | 422 |
关键:无 warmup buffer
/api/indicators 内部会自动预取 1000 根 warmup 喂给 EMA / RSI / ATR 这类"累积型"指标。/api/indicators/compute 不会 —— 它老老实实只用你给的 K 线。
所以请确保 history 够长:
| 指标 / 用法 | 最少 K 线 |
|---|---|
| RSI(14) 想稳定 | ≥ 50 |
| EMA(200) / ATR(200) 想稳定 | ≥ 200 |
| Bollinger / Keltner / Donchian 默认参数 | ≥ 30 |
| SMC 内部结构 + FVG | ≥ 50 |
| SMC swing 结构 / OB / Strong-Weak / P/D zones | ≥ 100(默认 swing_size=50,加 buffer) |
| SMC 完整功能 + EQH/EQL 稳定 | ≥ 200(ATR 收敛阈值) |
| 生产分析建议 | 500+ |
前 N 根的指标值返回 null 是正常的,你应该丢掉那段 warmup,只用尾部稳定的结果。
鉴权与速率限制
跟 /api/indicators 同套:
- 不带
Authorizationheader → 走匿名 IP 桶(低限速) - 带合法
Bearer mq_xxx→ 走 token 桶(高限速) - 没 token 的话先 申请一个,免费
错误码
| Code | 含义 | 处理 |
|---|---|---|
400 | 校验失败(非单调递增 / NaN / 未知指标 / 列数不够) | 看 detail,改请求 |
401 | 带了 Authorization 但 token 无效 | 重新申请 |
413 | klines 超 2000 根 | 分批,或缩短窗口 |
422 | Pydantic 校验失败(缺字段 / 类型错 / 多余 key) | 看 detail.loc |
429 | 超 rate limit | 看 Retry-After,带 token 限速更高 |
500 | 指标计算异常(指标自身 bug) | 报 issue,附 detail 里的 indicator name |
相关
POST /api/indicators— 从引擎缓存取 K 线 + 算指标(更快,但限定 venue/symbol)GET /api/indicators/registry— 全部 60+ 指标列表 + 参数签名- SMC 指标详情页 — sidecar
objects结构说明 - AI Agent 操作手册 — 给 LLM 看的引擎接入文档
- Skill 运行时查询指南 — Skill 集成时的 endpoint 决策树