📝 docs(tsl-api): resolve backtesting return contract

This commit is contained in:
csh
2026-08-25 13:16:45 +08:00
parent d1568c02cd
commit 9c8d77e1c4
7 changed files with 834 additions and 56 deletions
@@ -98,11 +98,46 @@
},
{
"api": "tsBackTesting.FGroupType",
"role": "candidate_mode_discriminator",
"role": "return_schema_discriminator",
"contract_evidence_required": true,
"evidence": [
"module/ts-backtesting.md#fgrouptype"
]
},
{
"api": "tsBackTesting.FRateType",
"role": "ratio_allocation_mode",
"evidence": [
"module/ts-backtesting.md#fratetype"
]
},
{
"api": "tsBackTesting.FPriceType",
"role": "execution_price_mode",
"evidence": [
"module/ts-backtesting.md#fpricetype"
]
},
{
"api": "tsBackTesting.FFeeType",
"role": "fee_input_mode",
"evidence": [
"module/ts-backtesting.md#ffeetype"
]
},
{
"api": "tsBackTesting.FOpenVolType",
"role": "quantity_open_size_mode",
"evidence": [
"module/ts-backtesting.md#fopenvoltype"
]
},
{
"api": "tsBackTesting.FCloseVolType",
"role": "quantity_close_size_mode",
"evidence": [
"module/ts-backtesting.md#fclosevoltype"
]
}
],
"hooks": [
@@ -198,10 +233,394 @@
"contracts": [
{
"id": "ts-backtesting-trade-order",
"status": "incomplete",
"status": "resolved",
"callback": "tsBackTesting.GetTradeOrder",
"reason": "The reference states target holdings or trade details but does not yet define the mode-specific record fields.",
"required_next_step": "Resolve the configuration-to-return-schema mapping before generating callback fields.",
"mode_discriminator": {
"api": "tsBackTesting.FGroupType"
},
"return_schemas": [
{
"id": "ratio-target-holdings",
"when": {
"FGroupType": "1"
},
"result_kind": "target_holdings",
"record_shape": "table_array",
"fields": [
{
"name": "截止日",
"type": "date_time",
"required": true,
"pdf_non_empty": true
},
{
"name": "代码",
"type": "string",
"required": true,
"pdf_non_empty": true
},
{
"name": "方向",
"type": "integer",
"required": false,
"default": "1",
"pdf_non_empty": true,
"values": {
"0": "short",
"1": "long"
}
},
{
"name": "比例(%)",
"type": "numeric",
"pdf_non_empty": true,
"required_when": [
{
"field": "FRateType",
"equals": [
"-1"
]
}
]
},
{
"name": "成交价",
"type": "numeric",
"pdf_non_empty": false,
"required_when": [
{
"field": "FPriceType",
"equals": [
"-1"
]
}
],
"description": "Provide when FPriceType=-1; otherwise the framework selects the execution price."
},
{
"name": "乘数",
"type": "numeric",
"required": false,
"pdf_non_empty": false,
"default": "1_or_instrument_default"
},
{
"name": "保证金比例(%)",
"type": "numeric",
"required": false,
"pdf_non_empty": false,
"default": "100_or_instrument_default"
},
{
"name": "开仓费率(%)",
"type": "numeric",
"required": false,
"pdf_non_empty": true,
"used_when": [
{
"field": "FFeeType",
"equals": [
"1"
]
}
],
"fallback": "tsBackTesting.StockFee"
},
{
"name": "平仓费率(%)",
"type": "numeric",
"required": false,
"pdf_non_empty": true,
"used_when": [
{
"field": "FFeeType",
"equals": [
"1"
]
}
],
"fallback": "tsBackTesting.StockFee"
}
],
"alternate_returns": [
{
"type": "empty_array",
"meaning": "clear_all_positions"
},
{
"type": "non_array",
"meaning": "skip_current_rebalance",
"documented_examples": [
-1,
1
]
}
],
"evidence": [
"module/ts-backtesting.md#gettradeorderv_end_t"
]
},
{
"id": "quantity-trade-details",
"when": {
"FGroupType": "2"
},
"result_kind": "trade_details",
"record_shape": "table_array",
"fields": [
{
"name": "截止日",
"type": "date_time",
"required": true,
"pdf_non_empty": true
},
{
"name": "代码",
"type": "string",
"required": true,
"pdf_non_empty": true
},
{
"name": "方向",
"type": "integer",
"required": false,
"default": "1",
"pdf_non_empty": true,
"values": {
"0": "short",
"1": "long"
}
},
{
"name": "动作",
"type": "integer",
"required": true,
"compat_default": "0",
"pdf_non_empty": true,
"values": {
"0": "open",
"1": "close",
"32": "build_option_group",
"33": "unlock_option_group"
}
},
{
"name": "成交量",
"type": "numeric",
"pdf_non_empty": true,
"required_when": [
{
"field": "FOpenVolType",
"equals": [
"1"
],
"record_when": {
"动作": [
"0"
]
}
},
{
"field": "FCloseVolType",
"equals": [
"1"
],
"record_when": {
"动作": [
"1"
]
}
}
],
"record_required_when": {
"动作": [
"32",
"33"
]
}
},
{
"name": "成交价",
"type": "numeric",
"pdf_non_empty": true,
"required_when": [
{
"field": "FPriceType",
"equals": [
"-1"
]
}
],
"record_required_when": {
"动作": [
"32",
"33"
]
},
"record_constraint_when": {
"动作": {
"32": "greater_than_zero",
"33": "greater_than_zero"
}
}
},
{
"name": "资金",
"type": "numeric",
"required_when": [
{
"field": "FOpenVolType",
"equals": [
"2"
],
"record_when": {
"动作": [
"0"
]
}
}
]
},
{
"name": "剩余资金占比(%)",
"type": "numeric",
"required_when": [
{
"field": "FOpenVolType",
"equals": [
"3"
],
"record_when": {
"动作": [
"0"
]
}
}
]
},
{
"name": "平仓数量占比(%)",
"type": "numeric",
"required_when": [
{
"field": "FCloseVolType",
"equals": [
"2"
],
"record_when": {
"动作": [
"1"
]
}
}
]
},
{
"name": "乘数",
"type": "numeric",
"required": false,
"pdf_non_empty": false,
"default": "1_or_instrument_default"
},
{
"name": "保证金比例(%)",
"type": "numeric",
"required": false,
"pdf_non_empty": false,
"default": "100_or_instrument_default"
},
{
"name": "费率(%)",
"type": "numeric",
"pdf_non_empty": true,
"used_when": [
{
"field": "FFeeType",
"equals": [
"1"
]
}
],
"record_value_when": {
"动作": {
"32": 0,
"33": 0
}
},
"fallback": "tsBackTesting.StockFee"
},
{
"name": "费用",
"type": "numeric",
"pdf_non_empty": false,
"required_when": [
{
"field": "FFeeType",
"equals": [
"2"
]
}
],
"record_value_when": {
"动作": {
"32": 0,
"33": 0
}
}
},
{
"name": "组 ID",
"type": "string",
"pdf_non_empty": true,
"required": false,
"applies_when": "option_group_strategy",
"required_in_extension": true,
"description": "Required as a non-empty shared identifier for option-group rows; empty for ungrouped single-leg rows."
},
{
"name": "组合类型",
"type": "string",
"pdf_non_empty": false,
"required": false,
"applies_when": "option_group_strategy",
"description": "Option strategy identifier such as CNSJC or STD; may be empty for single-leg or unrecognized combinations."
}
],
"record_rules": [
{
"when": "option_group_strategy",
"rule": "Return all component contracts for a group; rows in the same group share 组 ID, 动作, and 成交量."
},
{
"when": {
"动作": [
"0",
"32",
"33"
]
},
"rule": "Option-group opening, construction, and unlock records use a concrete 成交量; action 1 may instead use 平仓数量占比(%)."
},
{
"when": {
"动作": [
"0"
]
},
"rule": "Option-group opening (action 0) uses FOpenVolType=1; fixed-amount and remaining-funds modes are not supported for this action."
}
],
"alternate_returns": [
{
"type": "empty_array",
"meaning": "no_trade_at_current_time"
}
],
"evidence": [
"module/ts-backtesting.md#gettradeorderv_end_t"
]
}
],
"evidence": [
"module/ts-backtesting.md#gettradeorderv_end_t"
]