auto_trade_sys/backend/database/add_created_at_to_trades.sql
薇薇安 3ce8493af2 feat(account, stats_dashboard, binance_client, position_manager): 增强开仓时间记录与条件单错误处理
在 `account.py` 中新增 `created_at` 字段以记录开仓时间,并在 `StatsDashboard.jsx` 中更新展示逻辑,优先显示开仓时间或创建时间。`binance_client.py` 中引入 `AlgoOrderPositionUnavailableError` 异常处理,确保在条件单被拒时记录警告信息。`position_manager.py` 中优化了止损单挂单失败的处理逻辑,提升了系统的稳定性与风险控制能力。
2026-02-21 00:24:45 +08:00

21 lines
1.1 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.

-- 为 trades 表增加 created_at创建时间字段仅当不存在时
-- 用于持仓/订单展示「开仓时间」时至少有创建时间可显示;与 init.sql 中定义一致。
-- MySQL 5.7+:通过 procedure 判断后添加,避免重复执行报错
DELIMITER //
DROP PROCEDURE IF EXISTS add_created_at_to_trades_if_missing//
CREATE PROCEDURE add_created_at_to_trades_if_missing()
BEGIN
IF (SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'trades' AND COLUMN_NAME = 'created_at') = 0 THEN
ALTER TABLE trades
ADD COLUMN created_at INT UNSIGNED NULL COMMENT '创建时间Unix时间戳秒数' AFTER status;
UPDATE trades SET created_at = COALESCE(entry_time, UNIX_TIMESTAMP()) WHERE created_at IS NULL;
ALTER TABLE trades
MODIFY COLUMN created_at INT UNSIGNED NOT NULL DEFAULT (UNIX_TIMESTAMP()) COMMENT '创建时间Unix时间戳秒数';
END IF;
END//
DELIMITER ;
CALL add_created_at_to_trades_if_missing();
DROP PROCEDURE IF EXISTS add_created_at_to_trades_if_missing;