Add key-level auto trade, AI analysis, and trading UX improvements.

Key monitors use 5m close triggers with WeChat alerts and box/convergence auto orders; add pending-order worker, structured WeChat notify, AI settings/messages, session clock, CTP margin sizing, and dual-layer position limits.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-28 10:36:56 +08:00
parent 0109b59f27
commit 840e88daad
33 changed files with 2514 additions and 143 deletions
+34 -2
View File
@@ -231,6 +231,8 @@ def monitor_source_label(raw: str) -> str:
"trend": "趋势回调",
"roll": "顺势加仓",
"ctp_sync": "CTP 柜台",
"箱体突破": "箱体突破",
"收敛突破": "收敛突破",
}
key = (raw or "manual").strip().lower()
return mapping.get(key, raw or "期货下单")
@@ -339,6 +341,36 @@ def write_trade_log(
refresh_stats_cache(conn, capital)
except Exception as exc:
logger.debug("stats refresh after close: %s", exc)
try:
from trade_notify import notify_trade_log_close
from trading_context import trading_mode_label
from app import get_setting, send_wechat_msg
from ai_worker import schedule_ai_event_analysis
from db_conn import DB_PATH
notify_trade_log_close(
send_wechat=send_wechat_msg,
get_setting=get_setting,
mode_label=trading_mode_label(get_setting),
capital=capital,
sym=sym,
symbol_name=symbol_name,
direction=direction,
entry=entry,
close_price=close_price,
sl=stop_loss if stop_loss is not None else None,
tp=take_profit if take_profit is not None else None,
lots=lots,
pnl_net=pnl_net,
equity_after=equity_after,
holding_minutes=minutes,
result=result,
monitor_type=monitor_type,
schedule_ai_fn=schedule_ai_event_analysis,
db_path=DB_PATH,
)
except Exception as exc:
logger.debug("close notify: %s", exc)
def _write_trade_log(
@@ -732,7 +764,7 @@ def check_sl_tp_on_tick(
pass
reason = None
if tp_f is not None and not mon.get("trailing_be") and _tp_triggered(direction, tp_f, mark, tick):
if tp_f is not None and _tp_triggered(direction, tp_f, mark, tick):
reason = "take_profit"
elif sl_f is not None and _sl_triggered(direction, sl_f, mark, tick):
reason = "stop_loss"
@@ -813,7 +845,7 @@ def check_monitors_locally(
pass
reason = None
if tp_f is not None and not mon.get("trailing_be") and _tp_triggered(direction, tp_f, mark, tick):
if tp_f is not None and _tp_triggered(direction, tp_f, mark, tick):
reason = "take_profit"
elif sl_f is not None and _sl_triggered(direction, sl_f, mark, tick):
reason = "stop_loss"