From d9270ad6b4fad68861edc52d5b1bdd5ccb970f5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Sun, 25 Jan 2026 09:12:22 +0800 Subject: [PATCH] a --- trading_system/position_manager.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/trading_system/position_manager.py b/trading_system/position_manager.py index 0a7756b..1e6358c 100644 --- a/trading_system/position_manager.py +++ b/trading_system/position_manager.py @@ -2878,6 +2878,19 @@ class PositionManager: should_close = True exit_reason = 'take_profit' + # 计算持仓时间(用于日志) + entry_time = position_info.get('entryTime') + hold_time_minutes = 0 + if entry_time: + try: + if isinstance(entry_time, datetime): + hold_time_sec = int((get_beijing_time() - entry_time).total_seconds()) + else: + hold_time_sec = int(time.time() - (float(entry_time) if isinstance(entry_time, (int, float)) else 0)) + hold_time_minutes = hold_time_sec / 60.0 + except Exception: + hold_time_minutes = 0 + # 详细诊断日志:记录平仓时的所有关键信息 logger.info("=" * 80) logger.info(f"{symbol} [实时监控-平仓诊断日志] ===== 触发止盈平仓 =====")