This commit is contained in:
aaron 2026-02-28 14:42:27 +08:00
parent b26f7713b4
commit 99d9199d8d
4 changed files with 24 additions and 7 deletions

View File

@ -214,9 +214,13 @@ class CryptoAgent:
emoji = "🛑" emoji = "🛑"
status_text = "止损平仓" status_text = "止损平仓"
color = "red" color = "red"
elif status == 'closed_be': elif status == 'closed_ts':
emoji = "📈" emoji = "📈"
status_text = "移动止损" status_text = "移动止盈"
color = "green"
elif status == 'closed_be':
emoji = "🔒"
status_text = "保本止损"
color = "orange" color = "orange"
else: else:
emoji = "📤" emoji = "📤"

View File

@ -193,6 +193,10 @@ async def price_monitor_loop():
emoji = "🎯" emoji = "🎯"
status_text = "止盈平仓" status_text = "止盈平仓"
color = "green" color = "green"
elif status == 'closed_ts':
emoji = "📈"
status_text = "移动止盈"
color = "green"
elif status == 'closed_sl': elif status == 'closed_sl':
emoji = "🛑" emoji = "🛑"
status_text = "止损平仓" status_text = "止损平仓"

View File

@ -14,6 +14,7 @@ class OrderStatus(str, Enum):
CLOSED_TP = "closed_tp" # 止盈平仓 CLOSED_TP = "closed_tp" # 止盈平仓
CLOSED_SL = "closed_sl" # 止损平仓 CLOSED_SL = "closed_sl" # 止损平仓
CLOSED_BE = "closed_be" # 保本止损平仓 CLOSED_BE = "closed_be" # 保本止损平仓
CLOSED_TS = "closed_ts" # 移动止盈平仓
CLOSED_MANUAL = "closed_manual" # 手动平仓 CLOSED_MANUAL = "closed_manual" # 手动平仓
CANCELLED = "cancelled" # 已取消 CANCELLED = "cancelled" # 已取消

View File

@ -587,8 +587,10 @@ class PaperTradingService:
exit_price = order.take_profit exit_price = order.take_profit
elif current_price <= order.stop_loss: elif current_price <= order.stop_loss:
triggered = True 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 new_status = OrderStatus.CLOSED_BE
else: else:
new_status = OrderStatus.CLOSED_SL new_status = OrderStatus.CLOSED_SL
@ -601,8 +603,10 @@ class PaperTradingService:
exit_price = order.take_profit exit_price = order.take_profit
elif current_price >= order.stop_loss: elif current_price >= order.stop_loss:
triggered = True 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 new_status = OrderStatus.CLOSED_BE
else: else:
new_status = OrderStatus.CLOSED_SL 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 '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})") logger.info(f"订单{status_text}: {db_order.order_id} | {db_order.symbol} | 盈亏: {pnl_percent:+.2f}% (${pnl_amount:+.2f})")
return result return result
@ -1075,6 +1079,7 @@ class PaperTradingService:
OrderStatus.CLOSED_TP, OrderStatus.CLOSED_TP,
OrderStatus.CLOSED_SL, OrderStatus.CLOSED_SL,
OrderStatus.CLOSED_BE, OrderStatus.CLOSED_BE,
OrderStatus.CLOSED_TS,
OrderStatus.CLOSED_MANUAL OrderStatus.CLOSED_MANUAL
]) ])
).all() ).all()
@ -1354,6 +1359,7 @@ class PaperTradingService:
OrderStatus.CLOSED_TP, OrderStatus.CLOSED_TP,
OrderStatus.CLOSED_SL, OrderStatus.CLOSED_SL,
OrderStatus.CLOSED_BE, OrderStatus.CLOSED_BE,
OrderStatus.CLOSED_TS,
OrderStatus.CLOSED_MANUAL OrderStatus.CLOSED_MANUAL
]) ])
) )
@ -1376,6 +1382,7 @@ class PaperTradingService:
OrderStatus.CLOSED_TP, OrderStatus.CLOSED_TP,
OrderStatus.CLOSED_SL, OrderStatus.CLOSED_SL,
OrderStatus.CLOSED_BE, OrderStatus.CLOSED_BE,
OrderStatus.CLOSED_TS,
OrderStatus.CLOSED_MANUAL OrderStatus.CLOSED_MANUAL
]) ])
) )
@ -1516,6 +1523,7 @@ class PaperTradingService:
OrderStatus.CLOSED_TP, OrderStatus.CLOSED_TP,
OrderStatus.CLOSED_SL, OrderStatus.CLOSED_SL,
OrderStatus.CLOSED_BE, OrderStatus.CLOSED_BE,
OrderStatus.CLOSED_TS,
OrderStatus.CLOSED_MANUAL OrderStatus.CLOSED_MANUAL
]) ])
).all() ).all()