开单计划增加决策理由;品种联想加速;复盘支持品种匹配

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-15 13:15:06 +08:00
parent db2443273f
commit eaf72a13fc
5 changed files with 196 additions and 43 deletions
+22 -6
View File
@@ -176,6 +176,7 @@ def init_db():
"ALTER TABLE key_monitors ADD COLUMN market_code TEXT",
"ALTER TABLE trade_records ADD COLUMN market_code TEXT",
"ALTER TABLE order_plans ADD COLUMN plan_date TEXT",
"ALTER TABLE order_plans ADD COLUMN decision_reason TEXT",
"ALTER TABLE key_monitors ADD COLUMN status TEXT DEFAULT 'active'",
"ALTER TABLE key_monitors ADD COLUMN archived_at TEXT",
"ALTER TABLE review_records ADD COLUMN direction TEXT",
@@ -188,6 +189,9 @@ def init_db():
"ALTER TABLE review_records ADD COLUMN initial_pnl REAL",
"ALTER TABLE review_records ADD COLUMN actual_pnl REAL",
"ALTER TABLE review_records ADD COLUMN is_emotion INTEGER DEFAULT 0",
"ALTER TABLE review_records ADD COLUMN symbol_name TEXT",
"ALTER TABLE review_records ADD COLUMN market_code TEXT",
"ALTER TABLE review_records ADD COLUMN sina_code TEXT",
]
for sql in migrations:
try:
@@ -321,6 +325,7 @@ def check_order_plans():
status = r["status"]
pid = r["id"]
name = r["symbol_name"] or sym
reason = r["decision_reason"] if "decision_reason" in r.keys() and r["decision_reason"] else ""
# 计划状态:价格进入决策区间则激活并通知
if status == "planned":
@@ -330,6 +335,7 @@ def check_order_plans():
f"【开单计划触发】{name} ({sym})\n"
f"方向:{'做多' if direction == 'long' else '做空'}\n"
f"决策区间:{zone_lower} ~ {zone_upper}\n"
f"决策理由:{reason}\n"
f"当前价:{p}\n"
f"止损:{stop_loss} 止盈:{take_profit}"
)
@@ -535,13 +541,14 @@ def add_plan():
conn.execute(
"""INSERT INTO order_plans
(symbol, symbol_name, market_code, sina_code, direction,
zone_upper, zone_lower, stop_loss, take_profit, plan_date)
VALUES (?,?,?,?,?,?,?,?,?,?)""",
zone_upper, zone_lower, stop_loss, take_profit, plan_date, decision_reason)
VALUES (?,?,?,?,?,?,?,?,?,?,?)""",
(
symbol, symbol_name, market_code, sina_code, direction,
float(d["zone_upper"]), float(d["zone_lower"]),
float(d["stop_loss"]), float(d["take_profit"]),
today_str(),
d.get("decision_reason", "").strip(),
),
)
conn.commit()
@@ -671,6 +678,14 @@ def add_review():
flash("请选择离场触发")
return redirect(url_for("records"))
symbol = d.get("symbol", "").strip()
symbol_name = d.get("symbol_name", "").strip()
market_code = d.get("market_code", "").strip()
sina_code = d.get("sina_code", "").strip()
if not symbol or not market_code:
flash("请从下拉列表选择品种(同花顺合约代码)")
return redirect(url_for("records"))
screenshot = ""
f = request.files.get("screenshot")
if f and f.filename:
@@ -705,7 +720,7 @@ def add_review():
if auto_kline and not screenshot:
try:
generated = generate_review_kline_chart(
symbol=d.get("symbol", "").strip(),
symbol=symbol,
periods=[d.get("kline_period1", "15m"), d.get("kline_period2", "1h")],
count=int(d.get("kline_count") or 300),
cutoff_label=d.get("kline_cutoff", "平仓时间"),
@@ -725,17 +740,18 @@ def add_review():
conn = get_db()
conn.execute(
"""INSERT INTO review_records
(open_time, close_time, symbol, timeframe, direction,
(open_time, close_time, symbol, symbol_name, market_code, sina_code,
timeframe, direction,
entry_price, stop_loss, take_profit, close_price, lots,
holding_duration, initial_pnl, actual_pnl, pnl,
open_type, expected_rr, actual_rr, exit_trigger, exit_supplement,
watch_after_breakeven, new_position_while_occupied, screenshot,
auto_kline, kline_period1, kline_period2, kline_count, kline_cutoff,
behavior_tags, is_emotion, notes)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""",
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""",
(
open_time, close_time,
d.get("symbol", "").strip(),
symbol, symbol_name, market_code, sina_code,
d.get("timeframe", "").strip(),
direction,
entry_price, stop_loss, take_profit, close_price, lots,