auto_trade_sys/backend/database/add_partial_profit_exit_reasons.sql
薇薇安 16c4cfbdd8 a
2026-01-27 11:11:03 +08:00

43 lines
1.7 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 分步止盈状态细分添加新的exit_reason值支持
-- 执行时间2026-01-27
-- 1. 更新exit_reason字段注释说明新的状态值
ALTER TABLE `trades` MODIFY COLUMN `exit_reason` VARCHAR(50)
COMMENT '平仓原因: manual(手动), stop_loss(止损), take_profit(单次止盈), trailing_stop(移动止损), sync(同步), take_profit_partial_then_take_profit(第一目标止盈后第二目标止盈), take_profit_partial_then_stop(第一目标止盈后剩余仓位止损), take_profit_partial_then_trailing_stop(第一目标止盈后剩余仓位移动止损)';
-- 2. 验证字段长度是否足够VARCHAR(50)应该足够)
SELECT
COLUMN_NAME,
COLUMN_TYPE,
COLUMN_COMMENT
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'trades'
AND COLUMN_NAME = 'exit_reason';
-- 3. 查看当前exit_reason的分布情况用于验证
SELECT
exit_reason,
COUNT(*) as count,
ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM trades WHERE status = 'closed'), 2) as percentage
FROM
trades
WHERE
status = 'closed'
GROUP BY
exit_reason
ORDER BY
count DESC;
-- 说明:
-- 新的状态值:
-- - take_profit_partial_then_take_profit: 第一目标止盈50%仓位)后,剩余仓位第二目标止盈
-- - take_profit_partial_then_stop: 第一目标止盈50%仓位)后,剩余仓位止损(保本)
-- - take_profit_partial_then_trailing_stop: 第一目标止盈50%仓位)后,剩余仓位移动止损
--
-- 这些状态用于更准确地统计胜率和盈亏比:
-- - 第一目标止盈后剩余仓位止损,应该算作"部分成功"(第一目标已达成)
-- - 第一目标止盈后剩余仓位第二目标止盈,应该算作"完整成功"