策略管理 API
模块: strategies
本模块包含 12 个API端点。
📋 端点列表
策略配置管理 (Custom Templates)
- 🔍
GET /api/v1/custom-templates/strategies/list- List Strategies (按名称分组) - 🔍
GET /api/v1/custom-templates/strategies/{template_name}/versions- Get Strategy Versions - 🔍
GET /api/v1/custom-templates/strategies/{template_name}/latest- Get Latest Strategy Version
策略元数据
- 🔍
GET /api/v1/strategies/- Get Available Strategies List - 🔍
GET /api/v1/strategies/{strategy_name}- Get Strategy Info - ➕
POST /api/v1/strategies/validate- Validate Strategy Configuration - 🔍
GET /api/v1/strategies/{strategy_name}/risk-config- Get Strategy Recommended Risk Configuration - 🔍
GET /api/v1/strategies/{strategy_name}/parameters- Get Strategy Parameters List - 🔍
GET /api/v1/strategies/{strategy_name}/template- Get Strategy Template Info - 🔍
GET /api/v1/strategies/metadata/all- Get All Strategies Metadata
技术指标 (Indicators)
- 🔍
GET /api/v1/indicators- List All Technical Indicators - 🔍
GET /api/v1/indicators/{indicator_id}- Get Indicator Detail
📖 详细说明
🔍 List Strategies
列出所有策略(按名称分组,返回最新版本)
Args: include_versions: 是否包含版本历史 current_user: Current authenticated user repository: CustomTemplateRepository instance
Returns: 策略列表
请求方式: GET /api/v1/custom-templates/strategies/list
查询参数:
include_versions(boolean) - 可选 -
响应:
// 数组: StrategyListResponse[]
- `id` (string) - **必填** -
- `user_id` (string) - **必填** -
- `template_name` (string) - **必填** -
- `description` (object) - **必填** -
- `channels_config` (array) - **必填** -
- `created_at` (string) - **必填** -
- `updated_at` (string) - **必填** -
- `current_version` (integer) - **必填** -
- `total_versions` (integer) - **必填** -
- `is_default` (boolean) - **必填** -
- `tags` (object) - **必填** -
- `versions` (object) - 可选 -
错误响应:
422: Validation Error
🔍 Get Strategy Versions
获取策略的所有版本
Args: template_name: 策略名称 current_user: Current authenticated user repository: CustomTemplateRepository instance
Returns: 所有版本列表
请求方式: GET /api/v1/custom-templates/strategies/{template_name}/versions
路径参数:
template_name(string) - 必填 -
响应:
// 数组: CustomTemplateResponse[]
- `id` (string) - **必填** -
- `user_id` (string) - **必填** -
- `template_name` (string) - **必填** -
- `description` (object) - **必填** -
- `channels_config` (array) - **必填** -
- `created_at` (string) - **必填** -
- `updated_at` (string) - **必填** -
- `version` (integer) - 可选 -
- `parent_id` (object) - 可选 -
- `is_default` (boolean) - 可选 -
- `tags` (object) - 可选 -
错误响应:
422: Validation Error
🔍 Get Latest Strategy Version
获取策略的最新版本
Args: template_name: 策略名称 current_user: Current authenticated user repository: CustomTemplateRepository instance
Returns: 最新版本的策略
请求方式: GET /api/v1/custom-templates/strategies/{template_name}/latest
路径参数:
template_name(string) - 必填 -
响应:
// 参考模型: CustomTemplateResponse
- `id` (string) - **必填** -
- `user_id` (string) - **必填** -
- `template_name` (string) - **必填** -
- `description` (object) - **必填** -
- `channels_config` (array) - **必填** -
- `created_at` (string) - **必填** -
- `updated_at` (string) - **必填** -
- `version` (integer) - 可选 -
- `parent_id` (object) - 可选 -
- `is_default` (boolean) - 可选 -
- `tags` (object) - 可选 -
错误响应:
422: Validation Error
🔍 Get Available Strategies List
获取可用策略列表
请求方式: GET /api/v1/strategies/
响应:
🔍 Get Strategy Info
获取策略详情
请求方式: GET /api/v1/strategies/{strategy_name}
路径参数:
strategy_name(string) - 必填 -
响应:
错误响应:
422: Validation Error
➕ Validate Strategy Configuration
验证策略配置
请求方式: POST /api/v1/strategies/validate
请求体:
// 参考模型: StrategyConfigRequest
- `strategy_name` (string) - **必填** -
- `config` (object) - **必填** -
响应:
// 参考模型: StrategyConfigResponse
- `valid` (boolean) - **必填** -
- `errors` (array) - 可选 -
- `warnings` (array) - 可选 -
- `config` (object) - 可选 -
错误响应:
422: Validation Error
🔍 Get Strategy Recommended Risk Configuration
获取策略推荐的风险配置
请求方式: GET /api/v1/strategies/{strategy_name}/risk-config
路径参数:
strategy_name(string) - 必填 -
响应:
错误响应:
422: Validation Error
🔍 Get Strategy Parameters List
获取策略参数定义
请求方式: GET /api/v1/strategies/{strategy_name}/parameters
路径参数:
strategy_name(string) - 必填 -
响应:
错误响应:
422: Validation Error
🔍 Get Strategy Template Info
获取策略配置模板
请求方式: GET /api/v1/strategies/{strategy_name}/template
路径参数:
strategy_name(string) - 必填 -
响应:
错误响应:
422: Validation Error
🔍 Get All Strategies Metadata
获取所有策略的元数据
Returns: Dict with all registered strategies and their metadata Format: { “strategies”: [ { “strategy_id”: “MomentumBreakoutStrategy”, “display_name”: “Momentum Breakout Strategy”, “category”: “Momentum”, “description”: “…”, “market_types”: [“US_STOCK”, “CN_STOCK”], “timeframes”: [“1m”, “5m”, “15m”], “min_history_bars”: 100, “risk_level”: “medium”, “parameters”: […] }, … ], “total”: 8 }
请求方式: GET /api/v1/strategies/metadata/all
响应:
📊 技术指标 API
🔍 List All Technical Indicators
获取所有可用的技术指标元数据列表
请求方式: GET /api/v1/indicators
响应:
// 数组: IndicatorMetadata[]
[
{
"id": "rsi",
"name": "RSI",
"display_name": "相对强弱指标",
"english_name": "Relative Strength Index",
"category": "momentum",
"description": "衡量价格变动速度和变化幅度的动量振荡器",
"parameters_count": 3
},
{
"id": "macd",
"name": "MACD",
"display_name": "移动平均收敛/发散",
"english_name": "Moving Average Convergence Divergence",
"category": "trend",
"description": "显示两条移动平均线之间关系的趋势跟踪动量指标",
"parameters_count": 4
}
]
🔍 Get Indicator Detail
获取单个技术指标的详细信息
请求方式: GET /api/v1/indicators/{indicator_id}
路径参数:
indicator_id(string) - 必填 - 指标ID(如 rsi, macd, bollinger_bands)
响应:
// 参考模型: IndicatorMetadata
{
"id": "rsi",
"name": "RSI",
"display_name": "相对强弱指标",
"english_name": "Relative Strength Index",
"category": "momentum",
"description": "RSI 是一种动量振荡器,用于衡量价格变动的速度和变化幅度。RSI 振荡于 0-100 之间,通常用于识别超买和超卖条件。",
"parameters": [
{
"name": "length",
"type": "int",
"default": 14,
"min": 2,
"max": 100,
"description": "计算周期"
},
{
"name": "scalar",
"type": "float",
"default": 100.0,
"description": "缩放因子"
},
{
"name": "drift",
"type": "int",
"default": 1,
"description": "差分周期"
}
],
"pandas_ta": {
"function": "ta.rsi(close, length=14, scalar=100, drift=1)",
"returns": "pd.Series",
"example": "df.ta.rsi(length=14)"
},
"interpretation": {
"overbought": "RSI > 70 表示超买,可能即将下跌",
"oversold": "RSI < 30 表示超卖,可能即将上涨",
"divergence": "价格与 RSI 背离可能预示趋势反转",
"centerline": "RSI 在 50 上方表示上升趋势占优"
}
}
错误响应:
404: Indicator not found - 指标不存在422: Validation Error
📁 指标元数据存储
技术指标元数据以 JSON 文件形式存储在 backend/core/trading/strategies/indicators/metadata/ 目录下。
当前可用指标:
| 指标ID | 文件名 | 类型 | 描述 |
|---|---|---|---|
rsi |
rsi.json | momentum | 相对强弱指标 |
macd |
macd.json | trend | MACD |
bollinger_bands |
bollinger_bands.json | volatility | 布林带 |
sma |
sma.json | trend | 简单移动平均线 |
ema |
ema.json | trend | 指数移动平均线 |
atr |
atr.json | volatility | 真实波幅 |
stoch |
stoch.json | momentum | 随机指标 |
obv |
obv.json | volume | 能量潮 |
vwap |
vwap.json | volume | 成交量加权平均价 |
adx |
adx.json | trend | 平均方向指数 |
添加新指标: 在 metadata/ 目录下创建新的 JSON 文件,参考 _template.md 格式。