跳到主要内容

获取回测结果

获取回测任务的状态,以及(在结果就绪时)完整的结果。

接口

GET /v1/backtest/jobs/{id}

权重: 2

鉴权: 必需(已签名)

路径参数

名称类型必填说明
idstring创建任务 返回的任务标识符,例如 bt_3c91ef

响应

成功响应返回完整的任务对象。result 负载仅在 statusdone 时才会被填充。

{
"id": "bt_3c91ef",
"status": "done",
"config": {
"template_id": "tpl_grid",
"params": {
"grid_levels": 8,
"upper_price": "72000",
"lower_price": "60000"
},
"symbols": ["BTCUSDT"],
"timeframe": "1h",
"start": "2025-01-01T00:00:00Z",
"end": "2025-12-31T23:59:59Z",
"capital": "10000.00",
"leverage": 1,
"fee_model": "fixed_bps",
"fee_bps": "5"
},
"submitted_at": "2026-04-29T10:15:00Z",
"started_at": "2026-04-29T10:15:08Z",
"finished_at": "2026-04-29T10:17:42Z",
"progress": 1.0,
"result": {
"metrics": {
"sharpe": "1.84",
"sortino": "2.31",
"calmar": "1.12",
"max_drawdown": "-0.142",
"win_rate": "0.638",
"profit_factor": "1.92",
"cagr": "0.187",
"expected_value": "12.43",
"total_trades": 247,
"avg_trade_duration_seconds": 14820
},
"equity_curve": [
["2025-01-01T00:00:00Z", "10000.00"],
["2025-01-02T00:00:00Z", "10031.50"]
],
"trades": [
{
"id": 1,
"side": "buy",
"symbol": "BTCUSDT",
"entry_time": "2025-01-15T08:00:00Z",
"entry_price": "62100.00",
"exit_time": "2025-01-15T14:00:00Z",
"exit_price": "63250.00",
"qty": "0.0805",
"pnl": "92.58",
"fee": "10.18"
}
]
},
"error": null
}

任务处于 queuedrunning 时,resultnullprogress[0, 1] 的小数。任务处于 failed 时,resultnullerror 携带失败详情。

响应字段

字段类型说明
idstring任务标识符。
statusenumqueuedrunningdonefailedcancelled。后三者为终止状态。
configobject任务运行时的解析后配置。字段含义参见 创建任务
submitted_atstring (ISO 8601)任务被接受的时间。
started_atstring (ISO 8601) | nullWorker 开始处理的时间。
finished_atstring (ISO 8601) | null任务进入终止状态的时间。
progressnumber位于 [0, 1] 的进度比例。完成时为 1.0
resultobject | null仅在 status = "done" 时填充。
result.metricsobject性能指标。定义参见 指标
result.equity_curvearray<[ISO 8601, decimal string]>权益样本;模拟周期内每天一条。
result.tradesarray<object>已平仓成交。每条成交包含 idsidesymbolentry_timeentry_priceexit_timeexit_priceqtypnlfee
errorobject | nullstatus = "failed" 时为 { "code", "message" }

轮询建议

  • 单个任务每 5 秒最多轮询一次。更激进的轮询会被限流。
  • 一旦 status 进入终止值(donefailedcancelled),立即停止轮询。
  • 对长时间运行的任务,建议在前几次轮询之后改用指数退避。

大结果分页

对于跨度较长的回测,result.equity_curveresult.trades 未来可能会分页以控制响应体积。在首发版本中,完整数组始终在一次响应中返回。

未来: 通过 ?expand=equity_curve&cursor=...(以及 expand=trades)显式选择启用分页。届时默认响应只返回指标与每个数组的首页。

错误

HTTP错误码原因
404NOT_FOUND任务 ID 不存在,或不归当前已鉴权密钥所有。

通用错误语义参见 错误

示例

curl -X GET https://api.pipai.example/v1/backtest/jobs/bt_3c91ef \
-H "X-PipAI-API-Key: $API_KEY" \
-H "X-PipAI-Timestamp: $TS" \
-H "X-PipAI-Signature: $SIG"