backtester
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePlausibleAI Backtester
PlausibleAI Backtester
How to Use This Skill
如何使用该技能
When this skill is active, use the guidance below directly. Do not perform filesystem searches or tool-driven exploration to rediscover it.
Use the PlausibleAI publisher API as the source of truth for symbol discovery, DSL discovery, validation, and execution. Prefer validating unfamiliar payloads before running them.
当该技能激活时,请直接遵循以下指引操作。无需执行文件系统搜索或工具驱动的探索来重新查找相关内容。
请将PlausibleAI发布者API作为标的发现、DSL发现、验证和执行的权威来源。在运行不熟悉的请求负载前,优先进行验证。
Base Route
基础路由
All routes go through .
https://api.serendb.com/publishers/plausibleai所有请求均通过发送。
https://api.serendb.com/publishers/plausibleaiAuthentication
身份验证
All endpoints require .
Authorization: Bearer $SEREN_API_KEY所有端点均要求携带请求头。
Authorization: Bearer $SEREN_API_KEYWorkflow
工作流程
-
Resolve auth. Setfor bearer auth. Use
SEREN_API_KEYin examples; default it toSEREN_PUBLISHER_BASE_URL.https://api.serendb.com/publishers/plausibleai -
Discover the market universe before guessing symbols. Callto see supported market types and symbol counts. Call
GET /api/markets/typeswithGET /api/markets/symbols,market_type,search, andlimitwhen the symbol is unknown. Calloffsetwhen the caller needs metadata or data availability.GET /api/markets/symbols/{symbol} -
Load the DSL contract. Callbefore composing a new request shape. Treat the catalog as authoritative for indicators, parameters, operators, logic nodes, examples,
GET /api/backtests/catalog,price_adjustment_modes, and response metric definitions.entry_price_bases -
Build the request with stable rule ids. Every entry or exit rule must include a unique. Logic nodes reference rules by
id, never by position. Ifidis omitted, the API combines all rules in the set withlogic.AND -
Validate novel requests. Usewhen the request uses a new symbol, a new indicator combination, or a non-trivial logic tree. Surface validation errors directly instead of trying to guess what the API intended.
POST /api/backtests/validate -
Execute. Usefor a single run. Use
POST /api/backtestswhen the caller wants multiple independent runs. Batch requests run concurrently on the server; order in the response is stable regardless of completion order. Single-run backtests are also stored as short-lived retrievable results. The response body is a compact stored-result summary withPOST /api/backtests/batch,id, and follow-up links for fetching the full result, trades, and equity curve.expires_at -
Mine when the caller wants "the best actionable signal now". Use. Minimal request is just
POST /api/backtests/mine. Mining defaults to a sensible rolling window and ranks candidates by{ "symbol": "BTC-USD" }unless overridden. Mining returns a compact summary plus a nestedprofit_factorhandle withbacktest,id, and follow-up links.expires_at -
Retrieve large result sections incrementally. Usefor the stored full result. Use
GET /api/backtests/{id}for the full trade list, or addGET /api/backtests/{id}/tradeswhen pagination is needed. Use?limit=&offset=for the full equity curve, or addGET /api/backtests/{id}/equity-curvewhen pagination is needed. Stored results are ephemeral and expire automatically.?limit=&offset= -
Interpret the result carefully.is the summary.
reportis the buy-and-hold comparison over the same range.benchmarks.buy_and_holdshows the provider-native symbol actually used after the backend auto-resolves the best data source.execution.provider_symbolare closed trades. Each trade includestrades,trade_number,side,entry_bar_index,exit_bar_index,entry_date,exit_date,pnl, andduration_bars.exit_reasonis a snake_case string from a documented set:trades[].exit_reason,take_profit,stop_loss,trailing_stop,highest_high_exit,lowest_low_exit,exit_signal,end_of_data. The full list is inother.catalog.trade_exit_reasonsis trade-indexed, not bar-indexed, and uses the sameequity_curvevalues astrade_number. Top-leveltradesandfirst_entry_signal_atrefer to entry signals only.last_entry_signal_atreports signal counts and per-rule signal summaries using rule ids.diagnostics
-
完成身份验证配置 设置以使用Bearer身份验证。示例中使用
SEREN_API_KEY,默认值为SEREN_PUBLISHER_BASE_URL。https://api.serendb.com/publishers/plausibleai -
在猜测标的前先探索市场范围 调用查看支持的市场类型及标的数量。 当标的未知时,携带
GET /api/markets/types、market_type、search和limit参数调用offset。 当调用者需要标的元数据或数据可用性信息时,调用GET /api/markets/symbols。GET /api/markets/symbols/{symbol} -
加载DSL合约 在构建新请求结构前,先调用。 请将该目录作为指标、参数、运算符、逻辑节点、示例、
GET /api/backtests/catalog、price_adjustment_modes和响应指标定义的权威来源。entry_price_bases -
使用稳定的规则ID构建请求 每个入场或离场规则都必须包含唯一的。 逻辑节点通过
id引用规则,而非通过位置引用。 如果省略id参数,API会将规则集中的所有规则通过logic逻辑组合。AND -
验证新请求 当请求使用新标的、新指标组合或复杂逻辑树时,使用进行验证。 直接展示验证错误,无需猜测API的预期逻辑。
POST /api/backtests/validate -
执行回测 单次回测使用接口。 当调用者需要多次独立回测时,使用
POST /api/backtests接口。批量请求会在服务器上并发执行;响应结果的顺序与完成顺序无关,保持稳定。 单次回测的结果也会作为短期可检索结果存储。响应体是一个简洁的存储结果摘要,包含POST /api/backtests/batch、id以及用于获取完整结果、交易记录和权益曲线的后续链接。expires_at -
当调用者需要“当前可执行的最优信号”时,使用策略挖掘功能 调用接口。 最简请求仅需包含
POST /api/backtests/mine。 挖掘功能默认使用合理的滚动窗口,并以{ "symbol": "BTC-USD" }作为候选策略的排序依据,除非显式覆盖该配置。 挖掘功能返回简洁摘要,以及包含profit_factor、id和后续链接的嵌套expires_at句柄。backtest -
增量检索大型结果集 使用获取完整的存储结果。 使用
GET /api/backtests/{id}获取完整交易记录,当需要分页时可添加GET /api/backtests/{id}/trades参数。 使用?limit=&offset=获取完整权益曲线,当需要分页时可添加GET /api/backtests/{id}/equity-curve参数。 存储的结果为临时数据,会自动过期。?limit=&offset= -
仔细解读回测结果字段为结果摘要。
report为相同时间范围内的买入持有策略对比数据。benchmarks.buy_and_hold显示后端自动解析最优数据源后实际使用的供应商原生标的。execution.provider_symbol为已平仓交易记录。每条交易包含trades、trade_number、side、entry_bar_index、exit_bar_index、entry_date、exit_date、pnl和duration_bars。exit_reason为文档中定义的蛇形命名字符串,可选值包括:trades[].exit_reason、take_profit、stop_loss、trailing_stop、highest_high_exit、lowest_low_exit、exit_signal、end_of_data。完整列表可在other中查看。catalog.trade_exit_reasons按交易索引而非K线索引生成,与equity_curve中的trades值对应。 顶层字段trade_number和first_entry_signal_at仅指代入场信号的时间。last_entry_signal_at字段报告信号数量以及按规则ID统计的单规则信号摘要。diagnostics
Indicator Quick Reference
指标速查
| Key | Category | Required Params | Optional Params / Notes |
|---|---|---|---|
| trend | | |
| trend | | |
| trend | | — |
| trend | | — |
| trend | | — |
| trend | | Returns +1 (uptrend) or -1 (downtrend); compare against 0 |
| momentum | | |
| momentum | | range 0–100 |
| momentum | | — |
| momentum | | — |
| momentum | | — |
| momentum | | — |
| momentum | | — |
| momentum | | — |
| momentum | | range: -100 to +100 |
| volatility | | source not accepted |
| volatility | | — |
| volatility | | — |
| volatility | | — |
| volatility | | |
| volatility | | — |
| volatility | | — |
| price_action | | |
| price_action | | |
| seasonal | — | Sun=0, Mon=1 … Fri=5, Sat=6; use |
| seasonal | — | 1–31 |
| seasonal | — | 1–5; resets on month change |
| seasonal | — | 1–12 |
| seasonal | — | 1–4 |
periodindicators[].parameters| 键名 | 分类 | 必填参数 | 可选参数 / 说明 |
|---|---|---|---|
| 趋势类 | | |
| 趋势类 | | |
| 趋势类 | | — |
| 趋势类 | | — |
| 趋势类 | | — |
| 趋势类 | | 返回+1(上涨趋势)或-1(下跌趋势);需与0进行比较 |
| 动量类 | | |
| 动量类 | | 取值范围0–100 |
| 动量类 | | — |
| 动量类 | | — |
| 动量类 | | — |
| 动量类 | | — |
| 动量类 | | — |
| 动量类 | | — |
| 动量类 | | 取值范围: -100 至 +100 |
| 波动率类 | | 不接受source参数 |
| 波动率类 | | — |
| 波动率类 | | — |
| 波动率类 | | — |
| 波动率类 | | |
| 波动率类 | | — |
| 波动率类 | | — |
| 价格行为类 | | |
| 价格行为类 | | |
| 季节性类 | — | 周日=0, 周一=1 … 周五=5, 周六=6;使用 |
| 季节性类 | — | 1–31 |
| 季节性类 | — | 1–5;每月重置 |
| 季节性类 | — | 1–12 |
| 季节性类 | — | 1–4 |
periodcatalog.indicators[].parametersExecution Block Quick Reference
执行块速查
| Field | Type | Required | Notes |
|---|---|---|---|
| | yes | trade direction |
| enum | yes | |
| integer | no | used when any ATR-based entry offset or exit is present; defaults to |
| | no | only valid with |
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| | 是 | 交易方向 |
| 枚举值 | 是 | |
| 整数 | 否 | 当存在任何基于ATR的入场偏移或离场设置时使用;若省略则默认值为 |
| | 否 | 仅在 |
Exit Policy Quick Reference
离场规则速查
Price-based exits go in . A rule-based signal exit goes in .
exitsexit_signal| Field | Type | Mode options | Notes |
|---|---|---|---|
| | | value > 0 |
| | | value > 0 |
| | | value > 0 |
| integer | — | exits after N bars |
| integer | — | exits after N cumulative profitable closes since entry |
| integer | — | exits at the rolling highest high over N bars |
| integer | — | exits at the rolling lowest low over N bars |
| rule set | — | rule-based exit logic that can be combined with price exits |
If any ATR-based entry offset or exit is present and is omitted, the API defaults it to . is only valid with or .
execution.atr_period20entry_priceentry_mode: next_bar_limitnext_bar_stop基于价格的离场设置需放在字段中。基于规则信号的离场设置需放在字段中。
exitsexit_signal| 字段 | 类型 | 模式选项 | 说明 |
|---|---|---|---|
| | | value > 0 |
| | | value > 0 |
| | | value > 0 |
| 整数 | — | 持有N根K线后离场 |
| 整数 | — | 累计N次盈利平仓后离场 |
| 整数 | — | 在N根K线内的最高点离场 |
| 整数 | — | 在N根K线内的最低点离场 |
| 规则集 | — | 基于规则的离场逻辑,可与价格离场设置组合使用 |
如果存在任何基于ATR的入场偏移或离场设置,且未指定,API会将其默认值设为。仅在或模式下有效。
execution.atr_period20entry_priceentry_mode: next_bar_limitnext_bar_stopExample Strategies
示例策略
Use these as canonical request patterns for the main DSL surfaces.
以下为DSL核心功能的标准请求示例。
1. Trend Following: 50/200 SMA Golden Cross
1. 趋势跟踪:50/200 SMA黄金交叉
Good default example for rule ids and .
exit_signaljson
{
"symbol": "BTC-USD",
"timeframe": "daily",
"start_at": "2020-01-01",
"initial_capital": 100000,
"execution": {
"side": "long",
"entry_mode": "next_bar_open"
},
"entry": {
"rules": [
{
"id": "golden_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_above",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "golden_cross"
}
},
"exit_signal": {
"rules": [
{
"id": "death_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_below",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "death_cross"
}
}
}该示例展示了规则ID和的标准用法。
exit_signaljson
{
"symbol": "BTC-USD",
"timeframe": "daily",
"start_at": "2020-01-01",
"initial_capital": 100000,
"execution": {
"side": "long",
"entry_mode": "next_bar_open"
},
"entry": {
"rules": [
{
"id": "golden_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_above",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "golden_cross"
}
},
"exit_signal": {
"rules": [
{
"id": "death_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_below",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "death_cross"
}
}
}2. Mean Reversion: RSI Oversold Bounce
2. 均值回归:RSI超卖反弹
Good example for scalar thresholds plus and .
stop_losstake_profitjson
{
"symbol": "AAPL",
"timeframe": "daily",
"start_at": "2020-01-01",
"initial_capital": 100000,
"execution": {
"side": "long",
"entry_mode": "next_bar_open"
},
"entry": {
"rules": [
{
"id": "rsi_oversold",
"lhs": {
"indicator": {
"key": "rsi",
"params": {
"period": 14,
"source": "close"
}
}
},
"operator": "lte",
"rhs": {
"value": 30
}
}
],
"logic": {
"type": "rule",
"id": "rsi_oversold"
}
},
"exits": {
"stop_loss": {
"mode": "percent",
"value": 5
},
"take_profit": {
"mode": "percent",
"value": 10
},
"max_hold_bars": 20
}
}该示例展示了标量阈值结合和的用法。
stop_losstake_profitjson
{
"symbol": "AAPL",
"timeframe": "daily",
"start_at": "2020-01-01",
"initial_capital": 100000,
"execution": {
"side": "long",
"entry_mode": "next_bar_open"
},
"entry": {
"rules": [
{
"id": "rsi_oversold",
"lhs": {
"indicator": {
"key": "rsi",
"params": {
"period": 14,
"source": "close"
}
}
},
"operator": "lte",
"rhs": {
"value": 30
}
}
],
"logic": {
"type": "rule",
"id": "rsi_oversold"
}
},
"exits": {
"stop_loss": {
"mode": "percent",
"value": 5
},
"take_profit": {
"mode": "percent",
"value": 10
},
"max_hold_bars": 20
}
}3. Trend Breakout: Stop Above 55-Bar High
3. 趋势突破:突破55根K线高点的止损入场
Good example for a more canonical Donchian-style trend-following breakout with a long-term trend filter.
json
{
"symbol": "BTC-USD",
"timeframe": "daily",
"start_at": "2020-01-01",
"initial_capital": 100000,
"execution": {
"side": "long",
"entry_mode": "next_bar_stop",
"entry_price": {
"basis": "highest_high",
"lookback": 55,
"offset": {
"mode": "fixed",
"value": 0
}
}
},
"entry": {
"rules": [
{
"id": "above_sma_200",
"lhs": {
"field": "close"
},
"operator": "gte",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "above_sma_200"
}
},
"exits": {
"lowest_low_exit_lookback": 20
}
}该示例展示了经典Donchian风格的趋势突破策略,结合长期趋势过滤。
json
{
"symbol": "BTC-USD",
"timeframe": "daily",
"start_at": "2020-01-01",
"initial_capital": 100000,
"execution": {
"side": "long",
"entry_mode": "next_bar_stop",
"entry_price": {
"basis": "highest_high",
"lookback": 55,
"offset": {
"mode": "fixed",
"value": 0
}
}
},
"entry": {
"rules": [
{
"id": "above_sma_200",
"lhs": {
"field": "close"
},
"operator": "gte",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "above_sma_200"
}
},
"exits": {
"lowest_low_exit_lookback": 20
}
}Curl Reference
Curl参考示例
Use these snippets directly when you need to query or execute against the API.
当你需要查询或调用API时,请直接使用以下代码片段。
Base Variables
基础变量
bash
SEREN_PUBLISHER_BASE_URL="${SEREN_PUBLISHER_BASE_URL:-https://api.serendb.com/publishers/plausibleai}"
SEREN_API_KEY="${SEREN_API_KEY:?Set SEREN_API_KEY}"Every request uses:
bash
-H "Authorization: Bearer $SEREN_API_KEY"bash
SEREN_PUBLISHER_BASE_URL="${SEREN_PUBLISHER_BASE_URL:-https://api.serendb.com/publishers/plausibleai}"
SEREN_API_KEY="${SEREN_API_KEY:?Set SEREN_API_KEY}"所有请求均需携带:
bash
-H "Authorization: Bearer $SEREN_API_KEY"Market Discovery
市场探索
List market types:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/markets/types" \
-H "Authorization: Bearer $SEREN_API_KEY" | jqSearch symbols:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/markets/symbols?market_type=crypto&search=bitcoin&limit=20" \
-H "Authorization: Bearer $SEREN_API_KEY" | jqGet symbol detail:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/markets/symbols/BTC-USD" \
-H "Authorization: Bearer $SEREN_API_KEY" | jq列出市场类型:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/markets/types" \
-H "Authorization: Bearer $SEREN_API_KEY" | jq搜索标的:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/markets/symbols?market_type=crypto&search=bitcoin&limit=20" \
-H "Authorization: Bearer $SEREN_API_KEY" | jq获取标的详情:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/markets/symbols/BTC-USD" \
-H "Authorization: Bearer $SEREN_API_KEY" | jqDSL Discovery
DSL探索
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/catalog" \
-H "Authorization: Bearer $SEREN_API_KEY" | jqbash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/catalog" \
-H "Authorization: Bearer $SEREN_API_KEY" | jqValidate a Backtest
验证回测请求
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/validate" \
-H "Authorization: Bearer $SEREN_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"symbol": "BTC-USD",
"timeframe": "daily",
"start_at": "2020-01-01",
"initial_capital": 100000,
"execution": {
"side": "long",
"entry_mode": "next_bar_open"
},
"entry": {
"rules": [
{
"id": "golden_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_above",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "golden_cross"
}
},
"exit_signal": {
"rules": [
{
"id": "death_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_below",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "death_cross"
}
}
}' | jqbash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/validate" \
-H "Authorization: Bearer $SEREN_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"symbol": "BTC-USD",
"timeframe": "daily",
"start_at": "2020-01-01",
"initial_capital": 100000,
"execution": {
"side": "long",
"entry_mode": "next_bar_open"
},
"entry": {
"rules": [
{
"id": "golden_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_above",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "golden_cross"
}
},
"exit_signal": {
"rules": [
{
"id": "death_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_below",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "death_cross"
}
}
}' | jqExecute a Backtest
执行回测
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests" \
-H "Authorization: Bearer $SEREN_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"symbol": "BTC-USD",
"timeframe": "daily",
"start_at": "2020-01-01",
"initial_capital": 100000,
"execution": {
"side": "long",
"entry_mode": "next_bar_open"
},
"entry": {
"rules": [
{
"id": "golden_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_above",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "golden_cross"
}
},
"exit_signal": {
"rules": [
{
"id": "death_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_below",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "death_cross"
}
}
}' | jqThe response from is a compact stored-result summary. Use the returned or to fetch the full backtest result when needed.
POST /api/backtestsidlinks.full_result_pathbash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests" \
-H "Authorization: Bearer $SEREN_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"symbol": "BTC-USD",
"timeframe": "daily",
"start_at": "2020-01-01",
"initial_capital": 100000,
"execution": {
"side": "long",
"entry_mode": "next_bar_open"
},
"entry": {
"rules": [
{
"id": "golden_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_above",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "golden_cross"
}
},
"exit_signal": {
"rules": [
{
"id": "death_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_below",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "death_cross"
}
}
}' | jqPOST /api/backtestsidlinks.full_result_pathRetrieve a Stored Backtest Result
检索存储的回测结果
Use the returned in the compact response from or .
idPOST /api/backtestsPOST /api/backtests/minebash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/<BACKTEST_ID>" \
-H "Authorization: Bearer $SEREN_API_KEY" | jqRetrieve all trades:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/<BACKTEST_ID>/trades" \
-H "Authorization: Bearer $SEREN_API_KEY" | jqRetrieve paginated trades when needed:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/<BACKTEST_ID>/trades?limit=100&offset=0" \
-H "Authorization: Bearer $SEREN_API_KEY" | jqRetrieve the full equity curve:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/<BACKTEST_ID>/equity-curve" \
-H "Authorization: Bearer $SEREN_API_KEY" | jqRetrieve paginated equity curve when needed:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/<BACKTEST_ID>/equity-curve?limit=100&offset=0" \
-H "Authorization: Bearer $SEREN_API_KEY" | jq使用或接口返回的简洁响应中的。
POST /api/backtestsPOST /api/backtests/mineidbash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/<BACKTEST_ID>" \
-H "Authorization: Bearer $SEREN_API_KEY" | jq获取所有交易记录:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/<BACKTEST_ID>/trades" \
-H "Authorization: Bearer $SEREN_API_KEY" | jq当需要分页时,获取分页交易记录:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/<BACKTEST_ID>/trades?limit=100&offset=0" \
-H "Authorization: Bearer $SEREN_API_KEY" | jq获取完整权益曲线:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/<BACKTEST_ID>/equity-curve" \
-H "Authorization: Bearer $SEREN_API_KEY" | jq当需要分页时,获取分页权益曲线:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/<BACKTEST_ID>/equity-curve?limit=100&offset=0" \
-H "Authorization: Bearer $SEREN_API_KEY" | jqMine an Actionable Strategy
挖掘可执行策略
Minimal mining request:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/mine" \
-H "Authorization: Bearer $SEREN_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"symbol": "BTC-USD"
}' | jqMining returns:
symbolsignal_atfitness_metricfitness_valuemined_candidatesactionable_candidatesrankbacktest
backtestidkindcreated_atexpires_atrequestsummarylinks.full_result_pathlinks.trades_pathlinks.equity_curve_path
最简挖掘请求:
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/mine" \
-H "Authorization: Bearer $SEREN_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"symbol": "BTC-USD"
}' | jq挖掘接口返回以下内容:
symbolsignal_atfitness_metricfitness_valuemined_candidatesactionable_candidatesrankbacktest
backtestidkindcreated_atexpires_atrequestsummarylinks.full_result_pathlinks.trades_pathlinks.equity_curve_path
Batch Execution
批量执行
bash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/batch" \
-H "Authorization: Bearer $SEREN_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"requests": [
{
"symbol": "BTC-USD",
"timeframe": "daily",
"start_at": "2020-01-01",
"initial_capital": 100000,
"execution": {
"side": "long",
"entry_mode": "next_bar_open"
},
"entry": {
"rules": [
{
"id": "golden_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_above",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "golden_cross"
}
},
"exit_signal": {
"rules": [
{
"id": "death_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_below",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "death_cross"
}
}
}
]
}' | jqbash
curl -sS "$SEREN_PUBLISHER_BASE_URL/api/backtests/batch" \
-H "Authorization: Bearer $SEREN_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"requests": [
{
"symbol": "BTC-USD",
"timeframe": "daily",
"start_at": "2020-01-01",
"initial_capital": 100000,
"execution": {
"side": "long",
"entry_mode": "next_bar_open"
},
"entry": {
"rules": [
{
"id": "golden_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_above",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "golden_cross"
}
},
"exit_signal": {
"rules": [
{
"id": "death_cross",
"lhs": {
"indicator": {
"key": "sma",
"params": {
"period": 50,
"source": "close"
}
}
},
"operator": "crosses_below",
"rhs": {
"indicator": {
"key": "sma",
"params": {
"period": 200,
"source": "close"
}
}
}
}
],
"logic": {
"type": "rule",
"id": "death_cross"
}
}
}
]
}' | jqDSL Rules
DSL规则
- Keep rule ids short and stable. Use letters, numbers, underscores, or hyphens only.
- Use on
bars_agoorlhswhen you need to compare against an earlier bar. Omit it for the current bar.rhs - Use and
crosses_aboveonly when prior-bar behavior is intended.crosses_below - Prefer or
gteoverlteoreqfor floating-point comparisons.ne - Remember that uses parity semantics: it is true when an odd number of child nodes are true.
xor - is the maximum allowed
catalog.limits.max_bars_agovalue.bars_ago - The indicator only accepts
atr. Passingperiodtosourceis a validation error.atr - Indicator params are always required. The catalog lists no default value for them; omitting
periodreturns a 422.period - Add to any rule to invert its signal (fires when the condition is NOT met). Cannot be combined with
"negate": trueorcrosses_above— use the complementary operator instead. For compound negation, applycrosses_belowto individual rules and combine withnegate/anylogic nodes using De Morgan's laws.all
- 保持规则ID简短且稳定。仅可使用字母、数字、下划线或连字符。
- 当需要与之前的K线进行比较时,在或
lhs中使用rhs参数。当前K线无需使用该参数。bars_ago - 仅当需要参考前一根K线的行为时,使用和
crosses_above运算符。crosses_below - 对于浮点数比较,优先使用或
gte而非lte或eq。ne - 请注意运算符使用奇偶语义:当子节点中奇数个为真时,结果为真。
xor - 为
catalog.limits.max_bars_ago参数的最大允许值。bars_ago - 指标仅接受
atr参数。为period传递atr参数会触发验证错误。source - 指标的参数始终为必填项。目录中未为其设置默认值;省略
period参数会返回422错误。period - 可为任意规则添加来反转其信号(当条件不满足时触发)。该参数无法与
"negate": true或crosses_above运算符组合使用——请改用对应的互补运算符。对于复合否定,请为单个规则应用crosses_below参数,并使用德摩根定律通过negate/any逻辑节点组合。all
Common Pitfalls
常见误区
| Mistake | Fix |
|---|---|
Omitting | Every rule in |
| Guessing indicator defaults | Always provide |
Passing | ATR does not accept source; use |
Using | Use |
| Cross operators need one additional prior bar beyond the indicator lookback |
| Not allowed — cross operators fire on a single bar; their negation fires on ~99% of bars. Use the complementary operator instead |
| Validation error — step must be ≤ max |
| Validation error — short must be < long |
| Both are valid simultaneously; |
| |
| Logic node referencing undefined id | Logic node |
| No signals firing | Check |
| 错误操作 | 修复方案 |
|---|---|
规则中省略 | |
| 猜测指标的默认值 | 始终显式指定 |
为 | ATR指标不接受source参数;仅需传递 |
对浮点型指标使用 | 使用 |
使用 | 交叉运算符需要比指标回溯周期多一根K线的数据 |
为 | 该操作不被允许——交叉运算符仅在单根K线触发;其否定形式会在约99%的K线触发。请改用对应的互补运算符 |
| 该配置会触发验证错误——步长必须小于等于最大值 |
| 该配置会触发验证错误——短期周期必须小于长期周期 |
同时提供 | 两者可同时生效; |
在 | |
| 逻辑节点引用未定义的ID | 逻辑节点的 |
| 无信号触发 | 查看 |
Response Discipline
响应规范
- Prefer returning concise summaries unless the user asks for raw JSON.
- and
POST /api/backtestsboth return compact stored-result summaries first; do not assume the full backtest payload is in the initial response.POST /api/backtests/mine - For stored results, summarize the compact summary first and only fetch the full result, , or
tradeswhen the user needs that detail.equity_curve - Use for
?limit=&offset=ortradesonly when the result is large enough that incremental retrieval is useful.equity_curve - When showing example payloads, include rule ids explicitly.
- When the symbol is uncertain, use the market endpoints first instead of inventing tickers.
- When a backtest output looks surprising, compare ,
trades, andequity_curvebefore assuming the engine is wrong.diagnostics
- 除非用户明确要求原始JSON,否则优先返回简洁摘要。
- 和
POST /api/backtests接口均先返回简洁的存储结果摘要;请勿假设初始响应中包含完整回测负载。POST /api/backtests/mine - 对于存储的结果,先展示简洁摘要;仅当用户需要详细内容时,再获取完整结果、或
trades。equity_curve - 仅当结果集大到需要增量检索时,才为或
trades添加equity_curve参数。?limit=&offset= - 展示请求示例时,请显式包含规则ID。
- 当标的不确定时,先使用市场端点查询,而非自行编造代码。
- 当回测结果看起来异常时,请先对比、
trades和equity_curve字段,再假设引擎存在错误。diagnostics