API 文档
QuantMind 提供 RESTful API,支持策略管理、回测执行、模型推理等核心功能。
基础信息
| Base URL | http://localhost:8000/api/v1 |
| 数据格式 | JSON |
| 字符编码 | UTF-8 |
在线 API 文档
QuantMind 后端基于 FastAPI 构建,提供完整的交互式 API 文档:
- Swagger UI:http://localhost:8000/docs - 交互式调试
- ReDoc:http://localhost:8000/redoc - 美观的文档界面
认证方式
API 使用 Bearer Token 认证,在请求头中携带 Access Token:
http
Authorization: Bearer <access_token>
X-Tenant-Id: <tenant_id>
获取 Token
POST
/auth/login
用户登录获取 Access Token
请求体
json
{
"username": "user@example.com",
"password": "your_password"
}
响应
json
{
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"refresh_token": "eyJhbGciOiJIUzI1NiIs...",
"token_type": "bearer",
"expires_in": 3600
}
回测接口
创建回测任务
POST
/backtest/run
提交回测任务并返回任务 ID
请求体
json
{
"strategy_type": "topk_dropout",
"start_date": "2023-01-01",
"end_date": "2023-12-31",
"initial_capital": 1000000,
"universe": "csi300",
"strategy_params": {
"topk": 30,
"n_drop": 5
}
}
响应
json
{
"backtest_id": "bt_20240101_abc123",
"status": "running",
"created_at": "2024-01-01T10:00:00Z"
}
查询回测结果
GET
/backtest/{backtest_id}/result
获取回测任务的结果
响应
json
{
"backtest_id": "bt_20240101_abc123",
"status": "completed",
"metrics": {
"total_return": 0.156,
"annual_return": 0.156,
"sharpe_ratio": 1.42,
"max_drawdown": -0.082,
"win_rate": 0.583
},
"equity_curve": [...],
"trades": [...]
}
模型接口
获取模型列表
GET
/models
获取当前租户下的所有模型
模型推理
POST
/inference/predict
使用指定模型进行预测
请求体
json
{
"model_id": "model_qlib_v1",
"date": "2024-01-15",
"universe": "all"
}
响应
json
{
"status": "success",
"predictions": [
{"symbol": "SH600519", "score": 0.85},
{"symbol": "SZ000858", "score": 0.78},
...
],
"generated_at": "2024-01-15T18:00:00Z"
}
数据接口
获取因子数据
GET
/data/features
获取指定日期的因子数据
查询参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
date |
string | 是 | 日期,格式 YYYY-MM-DD |
symbols |
string | 否 | 股票代码,逗号分隔 |
features |
string | 否 | 因子名称,逗号分隔 |
错误码
| 状态码 | 说明 |
|---|---|
400 |
请求参数错误 |
401 |
未授权,Token 无效或过期 |
403 |
禁止访问,权限不足 |
404 |
资源不存在 |
429 |
请求频率超限 |
500 |
服务器内部错误 |