Fix Gate mark/PnL/TP-SL snapshot and intraday order UI

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-06 22:04:19 +08:00
parent 5e4f885f80
commit d4a76f05d2
10 changed files with 315 additions and 50 deletions
+69 -5
View File
@@ -19,6 +19,10 @@ ENTRY_MODEL_BIG_DIV_A = "big_div_a"
ENTRY_MODEL_BIG_DIV_B = "big_div_b"
ENTRY_MODEL_SMALL_DIV = "small_div"
ENTRY_CATEGORY_INTRADAY = "intraday"
ENTRY_MODEL_LIQUIDITY_FALSE_BREAK = "liquidity_false_break"
ENTRY_MODEL_STRUCTURE_BREAKOUT = "structure_breakout"
VALID_ENTRY_MODEL_CODES = frozenset(
{
ENTRY_MODEL_LAUNCH_A,
@@ -29,6 +33,15 @@ VALID_ENTRY_MODEL_CODES = frozenset(
}
)
INTRADAY_ENTRY_MODEL_CODES = frozenset(
{
ENTRY_MODEL_LIQUIDITY_FALSE_BREAK,
ENTRY_MODEL_STRUCTURE_BREAKOUT,
}
)
ALL_ENTRY_MODEL_CODES = VALID_ENTRY_MODEL_CODES | INTRADAY_ENTRY_MODEL_CODES
ENTRY_CATEGORY_LABELS: dict[str, str] = {
ENTRY_CATEGORY_REVERSAL: "反转",
ENTRY_CATEGORY_TREND: "顺势",
@@ -90,11 +103,33 @@ _ENTRY_SPECS: Tuple[Tuple[str, str, str, str, str], ...] = (
),
)
_INTRADAY_ENTRY_SPECS: Tuple[Tuple[str, str, str, str, str], ...] = (
(
ENTRY_MODEL_LIQUIDITY_FALSE_BREAK,
"假破",
ENTRY_CATEGORY_INTRADAY,
"trend",
"流动性扫单 → 假突破验证 → 5m N 字 → 15m 顶/底分型",
),
(
ENTRY_MODEL_STRUCTURE_BREAKOUT,
"结构突破",
ENTRY_CATEGORY_INTRADAY,
"trend",
"15m 结构有效突破(收盘确认)",
),
)
_CODE_TO_LABEL = {code: label for code, label, _, _, _ in _ENTRY_SPECS}
_CODE_TO_LABEL.update({code: label for code, label, _, _, _ in _INTRADAY_ENTRY_SPECS})
_CODE_TO_STYLE = {code: style for code, _, _, style, _ in _ENTRY_SPECS}
_CODE_TO_STYLE.update({code: style for code, _, _, style, _ in _INTRADAY_ENTRY_SPECS})
_CODE_TO_CATEGORY = {code: cat for code, _, cat, _, _ in _ENTRY_SPECS}
_CODE_TO_CATEGORY.update({code: cat for code, _, cat, _, _ in _INTRADAY_ENTRY_SPECS})
_LABEL_TO_CODE = {label: code for code, label, _, _, _ in _ENTRY_SPECS}
_LABEL_TO_CODE.update({label: code for code, label, _, _, _ in _INTRADAY_ENTRY_SPECS})
_CODE_TO_HELP = {code: help for code, _, _, _, help in _ENTRY_SPECS}
_CODE_TO_HELP.update({code: help for code, _, _, _, help in _INTRADAY_ENTRY_SPECS})
_CATEGORY_ORDER: Tuple[str, ...] = (
ENTRY_CATEGORY_REVERSAL,
@@ -134,6 +169,13 @@ def entry_model_options() -> Tuple[EntryModelOption, ...]:
)
def intraday_entry_model_options() -> Tuple[EntryModelOption, ...]:
return tuple(
EntryModelOption(code=code, label=label, category=cat, trade_style=style, help=help)
for code, label, cat, style, help in _INTRADAY_ENTRY_SPECS
)
def entry_model_categories() -> list[dict[str, Any]]:
"""两级 UI:反转 / 顺势 / 波段 → 子选项。"""
opts = entry_model_options()
@@ -168,7 +210,7 @@ def entry_model_category(code: Optional[str]) -> str:
def normalize_entry_model_code(raw: Optional[str]) -> str:
v = (raw or "").strip().lower()
if v in VALID_ENTRY_MODEL_CODES:
if v in ALL_ENTRY_MODEL_CODES:
return v
label = (raw or "").strip()
if label in _LABEL_TO_CODE:
@@ -227,10 +269,13 @@ def parse_manual_order_style_fields(
) -> Tuple[str, Optional[str], Optional[str]]:
"""返回 (trade_style, entry_model_code|None, error_message|None)。"""
if is_intraday_trading_profile(policy):
trade_style = (form.get("trade_style") or default_trade_style or "trend").strip().lower()
if trade_style not in ("trend", "swing"):
trade_style = "trend"
return trade_style, None, None
entry_model = normalize_entry_model_code(form.get("entry_model"))
if entry_model in INTRADAY_ENTRY_MODEL_CODES:
return "trend", entry_model, None
raw_style = (form.get("trade_style") or "").strip().lower()
if raw_style in ("trend", "swing"):
return raw_style, None, None
return "", None, "请选择开仓类型(假破 / 结构突破)"
entry_model = normalize_entry_model_code(form.get("entry_model"))
if not entry_model:
@@ -280,12 +325,31 @@ def enrich_entry_model_display(item: dict) -> dict:
return item
def open_position_button_label(policy: TradePolicy, sizing_mode: str) -> str:
from lib.trade.position_sizing_lib import mode_label_zh
mode_txt = mode_label_zh(sizing_mode)
if is_intraday_trading_profile(policy):
return f"开仓(日内·{mode_txt}"
return f"开仓({mode_txt}"
def order_entry_template_context(policy: TradePolicy) -> dict:
profile = order_entry_profile(policy)
opts = entry_model_options()
intraday_opts = intraday_entry_model_options()
return {
"order_entry_profile": profile,
"intraday_discipline": profile == PROFILE_INTRADAY,
"intraday_entry_model_options": [
{
"code": o.code,
"label": o.label,
"trade_style": o.trade_style,
"help": o.help,
}
for o in intraday_opts
],
"entry_model_options": [
{
"code": o.code,