diff --git a/backend/app/crypto_agent/crypto_agent.py b/backend/app/crypto_agent/crypto_agent.py index fd127c1..e7d46e4 100644 --- a/backend/app/crypto_agent/crypto_agent.py +++ b/backend/app/crypto_agent/crypto_agent.py @@ -214,9 +214,13 @@ class CryptoAgent: emoji = "🛑" status_text = "止损平仓" color = "red" - elif status == 'closed_be': + elif status == 'closed_ts': emoji = "📈" - status_text = "移动止损" + status_text = "移动止盈" + color = "green" + elif status == 'closed_be': + emoji = "🔒" + status_text = "保本止损" color = "orange" else: emoji = "📤" diff --git a/backend/app/main.py b/backend/app/main.py index 852903c..a38e471 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -193,6 +193,10 @@ async def price_monitor_loop(): emoji = "🎯" status_text = "止盈平仓" color = "green" + elif status == 'closed_ts': + emoji = "📈" + status_text = "移动止盈" + color = "green" elif status == 'closed_sl': emoji = "🛑" status_text = "止损平仓" diff --git a/backend/app/models/paper_trading.py b/backend/app/models/paper_trading.py index c09f14e..363ae15 100644 --- a/backend/app/models/paper_trading.py +++ b/backend/app/models/paper_trading.py @@ -14,6 +14,7 @@ class OrderStatus(str, Enum): CLOSED_TP = "closed_tp" # 止盈平仓 CLOSED_SL = "closed_sl" # 止损平仓 CLOSED_BE = "closed_be" # 保本止损平仓 + CLOSED_TS = "closed_ts" # 移动止盈平仓 CLOSED_MANUAL = "closed_manual" # 手动平仓 CANCELLED = "cancelled" # 已取消 diff --git a/backend/app/services/paper_trading_service.py b/backend/app/services/paper_trading_service.py index 23d31ed..3c50706 100644 --- a/backend/app/services/paper_trading_service.py +++ b/backend/app/services/paper_trading_service.py @@ -587,8 +587,10 @@ class PaperTradingService: exit_price = order.take_profit elif current_price <= order.stop_loss: triggered = True - # 通过标记判断是否是保本止损 - if getattr(order, 'breakeven_triggered', 0) == 1: + # 优先级:移动止盈 > 保本止损 > 普通止损 + if getattr(order, 'trailing_stop_triggered', 0) == 1: + new_status = OrderStatus.CLOSED_TS + elif getattr(order, 'breakeven_triggered', 0) == 1: new_status = OrderStatus.CLOSED_BE else: new_status = OrderStatus.CLOSED_SL @@ -601,8 +603,10 @@ class PaperTradingService: exit_price = order.take_profit elif current_price >= order.stop_loss: triggered = True - # 通过标记判断是否是保本止损 - if getattr(order, 'breakeven_triggered', 0) == 1: + # 优先级:移动止盈 > 保本止损 > 普通止损 + if getattr(order, 'trailing_stop_triggered', 0) == 1: + new_status = OrderStatus.CLOSED_TS + elif getattr(order, 'breakeven_triggered', 0) == 1: new_status = OrderStatus.CLOSED_BE else: new_status = OrderStatus.CLOSED_SL @@ -670,7 +674,7 @@ class PaperTradingService: 'signal_grade': db_order.signal_grade.value if db_order.signal_grade else None } - status_text = {"closed_tp": "止盈", "closed_sl": "止损", "closed_be": "移动止损"}.get(status.value, "平仓") + status_text = {"closed_tp": "止盈", "closed_sl": "止损", "closed_be": "保本止损", "closed_ts": "移动止盈"}.get(status.value, "平仓") logger.info(f"订单{status_text}: {db_order.order_id} | {db_order.symbol} | 盈亏: {pnl_percent:+.2f}% (${pnl_amount:+.2f})") return result @@ -1075,6 +1079,7 @@ class PaperTradingService: OrderStatus.CLOSED_TP, OrderStatus.CLOSED_SL, OrderStatus.CLOSED_BE, + OrderStatus.CLOSED_TS, OrderStatus.CLOSED_MANUAL ]) ).all() @@ -1354,6 +1359,7 @@ class PaperTradingService: OrderStatus.CLOSED_TP, OrderStatus.CLOSED_SL, OrderStatus.CLOSED_BE, + OrderStatus.CLOSED_TS, OrderStatus.CLOSED_MANUAL ]) ) @@ -1376,6 +1382,7 @@ class PaperTradingService: OrderStatus.CLOSED_TP, OrderStatus.CLOSED_SL, OrderStatus.CLOSED_BE, + OrderStatus.CLOSED_TS, OrderStatus.CLOSED_MANUAL ]) ) @@ -1516,6 +1523,7 @@ class PaperTradingService: OrderStatus.CLOSED_TP, OrderStatus.CLOSED_SL, OrderStatus.CLOSED_BE, + OrderStatus.CLOSED_TS, OrderStatus.CLOSED_MANUAL ]) ).all()