API JSON 範例全集¶
這一頁的目的是提供「足夠具體的 request / response 範例」,讓前端、整合方或重構者能快速對照系統實際資料形狀。
注意:
- 這不是 Swagger 的替代品
- 這裡更偏向「最常用 JSON 範例集合」
- 若欄位與舊文件衝突,以目前程式實作為準
一般回測¶
POST /set_strategy¶
Request:
{
"strategy_name": "BollingerATRStrategyV4"
}
Response:
{
"code": 200,
"message": "success",
"data": {
"strategy_name": "BollingerATRStrategyV4"
}
}
POST /set_ticker¶
Request:
{
"new_ticker": "TXFR1"
}
Response:
{
"code": 200,
"message": "商品設置成功",
"data": {
"ticker": "TXFR1"
}
}
POST /set_timeframe¶
Request:
{
"timeframe_minutes": 5
}
Response:
{
"code": 200,
"message": "时间周期设置成功",
"data": {
"timeframe_minutes": 5
}
}
POST /set_time_range¶
Request:
{
"start_time": "2025-01-01 00:00:00",
"end_time": "2025-06-30 23:59:59"
}
Response:
{
"code": 200,
"message": "时间范围设置成功",
"data": {
"start_time": "2025-01-01 00:00:00",
"end_time": "2025-06-30 23:59:59"
}
}
GET /get_params¶
Response:
{
"code": 200,
"message": "success",
"data": {
"init_window": 25,
"std": 2.0,
"in_std": 0.5,
"atr_window": 10,
"max_fluctuation": 0.75,
"min_fluctuation": 0.05,
"min_window": 10,
"max_window": 60,
"window_step": 1,
"k": 3,
"entry_type": "CLOSE",
"calc_timing": "CLOSE",
"price_offset_long": 10,
"price_offset_short": 10,
"stop_loss_offset_long": 10,
"stop_loss_offset_short": 10,
"stop_loss_flip": false
}
}
POST /set_params¶
Request:
{
"init_window": 30,
"std": 2.2,
"k": 4
}
Response:
{
"code": 200,
"message": "success"
}
GET /state¶
Response 只展示外層骨架:
{
"strategy": {
"params": {
"window": 25
}
},
"indicators": {
"series": {
"MA": [null, null, 22455.2],
"Upper": [null, null, 22488.1]
},
"current_index": 1234
},
"broker": {
"init_cash": 1000000,
"cash": 982450.0,
"positions": {
"TXFR1": {
"long": 0,
"short": 1
}
},
"avg_cost": {
"TXFR1": {
"long": 0.0,
"short": 22480.0
}
},
"order_history": {
"TXFR1": [
{
"type": "sell",
"direction": "short",
"price": 22480.0,
"size": 1,
"fee": 50,
"timestamp": "2025-01-02 09:15:00",
"message": "新建空倉"
}
]
}
},
"data_feed": {
"symbol": "TXFR1",
"interval": "5min",
"data": [
{
"datetime": "2025-01-02 09:00:00",
"open": 22400.0,
"high": 22420.0,
"low": 22395.0,
"close": 22410.0,
"volume": 1523.0
}
],
"current_index": 1234
},
"analysis": {
"total_pnl": 12500.0,
"total_trades": 18,
"win_rate": 61.11,
"profit_factor": 1.84,
"max_drawdown_pct": 3.2
}
}
策略與參數管理¶
POST /set_params_for_combination¶
Request:
{
"ticker": "TXFR1",
"timeframe_minutes": 5,
"strategy_name": "BollingerATRStrategyV3",
"params": {
"init_window": 20,
"std": 2.0
}
}
Response:
{
"code": 200,
"message": "参数设置成功",
"data": {
"ticker": "TXFR1",
"timeframe_minutes": 5,
"strategy_name": "BollingerATRStrategyV3",
"params": {
"init_window": 20,
"std": 2.0
}
}
}
GET /get_params_for_combination¶
Response:
{
"code": 200,
"message": "success",
"data": {
"ticker": "TXFR1",
"timeframe_minutes": 5,
"strategy_name": "BollingerATRStrategyV3",
"params": {
"init_window": 20,
"std": 2.0
}
}
}
最佳化¶
POST /optimization/tasks¶
Request:
{
"ticker": "TXFR1",
"timeframe_minutes": 5,
"start_time": "2025-01-01 00:00:00",
"end_time": "2025-06-30 23:59:59",
"strategy_name": "BollingerATRStrategyV4",
"base_params": {
"init_window": 25,
"std": 2.0,
"in_std": 0.5,
"atr_window": 10,
"k": 3
},
"param_ranges": {
"init_window": { "start": 15, "end": 35, "step": 5 },
"std": { "start": 1.5, "end": 2.5, "step": 0.25 }
}
}
Response:
{
"code": 200,
"message": "任務建立成功,共 25 個參數組合",
"data": {
"id": "a1b2c3d4",
"ticker": "TXFR1",
"timeframe_minutes": 5,
"start_time": "2025-01-01 00:00:00",
"end_time": "2025-06-30 23:59:59",
"strategy_name": "BollingerATRStrategyV4",
"base_params": {
"init_window": 25
},
"param_ranges": {
"init_window": { "start": 15, "end": 35, "step": 5 }
},
"status": "pending",
"progress": 0,
"total_combinations": 25,
"completed_combinations": 0,
"results": null,
"error_message": null,
"created_at": "2026-04-01T10:30:00",
"updated_at": "2026-04-01T10:30:00"
}
}
GET /optimization/tasks¶
Response:
{
"code": 200,
"message": "success",
"data": {
"tasks": [
{
"id": "a1b2c3d4",
"ticker": "TXFR1",
"timeframe_minutes": 5,
"start_time": "2025-01-01 00:00:00",
"end_time": "2025-06-30 23:59:59",
"strategy_name": "BollingerATRStrategyV4",
"status": "running",
"progress": 36,
"total_combinations": 25,
"completed_combinations": 9,
"results": null,
"error_message": null,
"created_at": "2026-04-01 18:30:00",
"updated_at": "2026-04-01T10:33:10"
}
],
"total": 1,
"limit": 50,
"offset": 0
}
}
GET /optimization/tasks/{task_id}/progress¶
Response:
{
"code": 200,
"message": "success",
"data": {
"id": "a1b2c3d4",
"status": "running",
"progress": 72,
"completed_combinations": 18,
"total_combinations": 25,
"error_message": null,
"updated_at": "2026-04-01T10:36:20"
}
}
GET /optimization/tasks/{task_id}/results¶
Response:
{
"code": 200,
"message": "success",
"data": {
"task_info": {
"id": "a1b2c3d4",
"ticker": "TXFR1",
"timeframe_minutes": 5,
"start_time": "2025-01-01 00:00:00",
"end_time": "2025-06-30 23:59:59",
"strategy_name": "BollingerATRStrategyV4",
"param_ranges": {
"init_window": { "start": 15, "end": 35, "step": 5 }
}
},
"results": [
{
"params": {
"init_window": 25,
"std": 2.0
},
"analysis": {
"total_pnl": 123456.7,
"total_trades": 45,
"win_count": 30,
"loss_count": 15,
"win_rate": 66.67,
"profit_factor": 2.67,
"max_drawdown_pct": 3.5
},
"success": true
}
],
"total": 25,
"limit": 50,
"offset": 0,
"has_more": false,
"sort_by": "total_pnl",
"sort_order": "desc"
}
}
備註¶
POST /notes/add¶
Request:
{
"ticker": "TXFR1",
"timeframe_minutes": 5,
"datetime": "2025-01-15 10:30:00",
"side": "short",
"msg": "這段訊號品質很好",
"strategy_name": "BollingerATRStrategyV4",
"params": {
"init_window": 25,
"std": 2.0
}
}
Response:
{
"code": 200,
"message": "备注添加成功",
"note_id": "2c6e5d9a-1f31-4b2d-8c9a-123456789abc"
}
訓練¶
GET /api/training/chart_data¶
Response:
{
"code": 200,
"message": "success",
"data": {
"ticker": "TXFR1",
"start_time": "2025-01-01 00:00:00",
"end_time": "2025-01-31 23:59:59",
"timeframe_minutes": 5,
"data_feed": {
"data": [
{
"datetime": "2025-01-02 09:00:00",
"open": 22400.0,
"high": 22420.0,
"low": 22395.0,
"close": 22410.0,
"volume": 1523
}
]
}
}
}
POST /api/training/param_range¶
Request:
{
"ticker": "TXFR1",
"timeframe_minutes": 5,
"start_time": "2025-01-10 09:00:00",
"end_time": "2025-01-10 11:00:00",
"params": {
"strategy_name": "BollingerATRStrategyV4",
"init_window": 25,
"std": 2.0
},
"color": "rgba(255, 99, 132, 0.15)",
"notes": "測試區間"
}
多區段回測¶
POST /multi_params/segments¶
Request:
{
"ticker": "TXFR1",
"start_date": "2025-01-01",
"end_date": "2025-03-31",
"params": {
"std": 2.0,
"min_window": 20
}
}
Response:
{
"code": 200,
"message": "創建成功",
"data": {
"id": 1,
"ticker": "TXFR1",
"start_date": "2025-01-01",
"end_date": "2025-03-31",
"params": {
"std": 2.0,
"min_window": 20
},
"created_at": "2026-04-01T10:30:00",
"updated_at": "2026-04-01T10:30:00"
}
}