feat: 重构仓位轮训逻辑并修复多语言配置

主要改动:
1. 创建独立的 PositionCheckService 服务
   - 将仓位检查逻辑从 PositionPushService 中分离
   - 实现待赎回仓位检查和未卖出订单检查
   - 实现订单状态更新逻辑(FIFO策略)

2. 修改 PositionPushService
   - 后端启动时自动启动轮训任务
   - 每次轮训后推送全量数据给所有订阅的客户端
   - 调用 PositionCheckService 进行仓位检查

3. 自动赎回功能调整
   - 将自动赎回从跟单配置级别移到系统级别
   - 添加系统级自动赎回配置管理
   - 支持 Builder API Key 配置检查

4. 多语言配置修复
   - 修复 PositionCheckService 中的硬编码消息
   - 使用 MessageSource 获取多语言文本
   - 添加自动赎回和 Builder API Key 相关的多语言资源

5. 数据库迁移
   - V8: 添加跟单配置名称字段
   - V9: 将自动赎回配置移到系统配置表

6. 前端更新
   - 添加系统级自动赎回配置界面
   - 更新跟单配置管理界面
   - 添加 Builder API Key 配置界面
This commit is contained in:
WrBug
2025-12-07 02:06:19 +08:00
parent bfbbbdd1de
commit cb167d442f
31 changed files with 1544 additions and 121 deletions
@@ -47,11 +47,9 @@ polygon.rpc.url=${POLYGON_RPC_URL:https://polygon-rpc.com}
# Builder Relayer 配置(用于 Gasless 交易)
# 从 polymarket.com/settings?tab=builder 获取 Builder API 凭证
# Builder API Key、Secret、Passphrase 现在通过系统设置页面配置,存储在数据库中
# 如果未配置,将使用手动发送交易的方式(需要用户支付 gas)
polymarket.builder.relayer-url=${POLYMARKET_BUILDER_RELAYER_URL:https://relayer-v2.polymarket.com/}
polymarket.builder.api-key=${POLYMARKET_BUILDER_API_KEY:}
polymarket.builder.secret=${POLYMARKET_BUILDER_SECRET:}
polymarket.builder.passphrase=${POLYMARKET_BUILDER_PASSPHRASE:}
# 仓位推送配置
# 轮询间隔(毫秒),默认3秒
@@ -0,0 +1,19 @@
-- ============================================
-- V8: 添加跟单配置新字段
-- 1. config_name: 配置名(可选)
-- 2. push_failed_orders: 推送失败订单(默认关闭)
-- 3. auto_redeem: 自动赎回(默认开启)
-- ============================================
-- 添加配置名字段
ALTER TABLE copy_trading
ADD COLUMN config_name VARCHAR(255) NULL COMMENT '配置名(可选)';
-- 添加推送失败订单字段(默认关闭)
ALTER TABLE copy_trading
ADD COLUMN push_failed_orders BOOLEAN NOT NULL DEFAULT FALSE COMMENT '推送失败订单(默认关闭)';
-- 添加自动赎回字段(默认开启)
ALTER TABLE copy_trading
ADD COLUMN auto_redeem BOOLEAN NOT NULL DEFAULT TRUE COMMENT '自动赎回(默认开启)';
@@ -0,0 +1,30 @@
-- ============================================
-- V9: 将自动赎回从跟单配置迁移到系统配置
-- 1. 从 copy_trading 表中读取 auto_redeem 值,迁移到 system_config
-- 2. 移除 copy_trading.auto_redeem 字段
-- ============================================
-- 1. 初始化 auto_redeem 配置项到 system_config(如果不存在)
-- 默认值为 true(因为之前 copy_trading.auto_redeem 默认是 true
INSERT IGNORE INTO system_config (config_key, config_value, description, created_at, updated_at)
VALUES
('auto_redeem', 'true', '自动赎回(系统级别配置,默认开启)', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000);
-- 2. 如果 copy_trading 表中存在数据,检查是否有 auto_redeem = false 的配置
-- 如果所有配置都是 true,则保持 system_config 中的值为 true
-- 如果存在 false,则设置为 false(保守策略:只要有一个配置是 false,就设置为 false
UPDATE system_config
SET config_value = CASE
WHEN EXISTS (
SELECT 1 FROM copy_trading
WHERE auto_redeem = FALSE
) THEN 'false'
ELSE 'true'
END,
updated_at = UNIX_TIMESTAMP() * 1000
WHERE config_key = 'auto_redeem';
-- 3. 移除 copy_trading 表中的 auto_redeem 字段
ALTER TABLE copy_trading
DROP COLUMN auto_redeem;
@@ -16,6 +16,32 @@ notification.order.time=Time
notification.order.error_info=Error Information
notification.order.unknown_account=Unknown Account
notification.order.calculate_failed=Calculation Failed
notification.redeem.success=Position Redeemed Successfully
notification.redeem.info=Redeem Information
notification.redeem.transaction_hash=Transaction Hash
notification.redeem.total_value=Total Redeemed Value
notification.redeem.position_count=Position Count
notification.redeem.positions=Redeemed Positions
notification.redeem.account=Account
notification.redeem.time=Time
# Auto Redeem related notifications
notification.auto_redeem.disabled.title=Auto Redeem Disabled
notification.auto_redeem.disabled.account=Account
notification.auto_redeem.disabled.redeemable_positions=Redeemable Positions
notification.auto_redeem.disabled.total_value=Total Value
notification.auto_redeem.disabled.message=Please enable auto redeem in system settings.
notification.auto_redeem.disabled.positions_unit=
# Builder API Key related notifications
notification.builder_api_key.not_configured.title=Builder API Key Not Configured
notification.builder_api_key.not_configured.account=Account
notification.builder_api_key.not_configured.copy_trading_config=Copy Trading Config
notification.builder_api_key.not_configured.redeemable_positions=Redeemable Positions
notification.builder_api_key.not_configured.total_value=Total Value
notification.builder_api_key.not_configured.message=Please configure Builder API Key in system settings to enable auto redeem.
notification.builder_api_key.not_configured.positions_unit=
notification.builder_api_key.not_configured.unknown_config=Unnamed Config
# Common
common.unknown=Unknown
@@ -16,6 +16,32 @@ notification.order.time=时间
notification.order.error_info=错误信息
notification.order.unknown_account=未知账户
notification.order.calculate_failed=计算失败
notification.redeem.success=仓位赎回成功
notification.redeem.info=赎回信息
notification.redeem.transaction_hash=交易哈希
notification.redeem.total_value=赎回总价值
notification.redeem.position_count=仓位数量
notification.redeem.positions=赎回仓位
notification.redeem.account=账户
notification.redeem.time=时间
# 自动赎回相关通知
notification.auto_redeem.disabled.title=自动赎回未开启
notification.auto_redeem.disabled.account=账户
notification.auto_redeem.disabled.redeemable_positions=可赎回仓位
notification.auto_redeem.disabled.total_value=总价值
notification.auto_redeem.disabled.message=请在系统设置中开启自动赎回功能。
notification.auto_redeem.disabled.positions_unit=
# Builder API Key 相关通知
notification.builder_api_key.not_configured.title=Builder API Key 未配置
notification.builder_api_key.not_configured.account=账户
notification.builder_api_key.not_configured.copy_trading_config=跟单配置
notification.builder_api_key.not_configured.redeemable_positions=可赎回仓位
notification.builder_api_key.not_configured.total_value=总价值
notification.builder_api_key.not_configured.message=请在系统设置中配置 Builder API Key 以启用自动赎回功能。
notification.builder_api_key.not_configured.positions_unit=
notification.builder_api_key.not_configured.unknown_config=未命名配置
# 通用
common.unknown=未知
@@ -16,6 +16,32 @@ notification.order.time=時間
notification.order.error_info=錯誤信息
notification.order.unknown_account=未知賬戶
notification.order.calculate_failed=計算失敗
notification.redeem.success=倉位贖回成功
notification.redeem.info=贖回信息
notification.redeem.transaction_hash=交易哈希
notification.redeem.total_value=贖回總價值
notification.redeem.position_count=倉位數量
notification.redeem.positions=贖回倉位
notification.redeem.account=賬戶
notification.redeem.time=時間
# 自動贖回相關通知
notification.auto_redeem.disabled.title=自動贖回未開啟
notification.auto_redeem.disabled.account=賬戶
notification.auto_redeem.disabled.redeemable_positions=可贖回倉位
notification.auto_redeem.disabled.total_value=總價值
notification.auto_redeem.disabled.message=請在系統設置中開啟自動贖回功能。
notification.auto_redeem.disabled.positions_unit=
# Builder API Key 相關通知
notification.builder_api_key.not_configured.title=Builder API Key 未配置
notification.builder_api_key.not_configured.account=賬戶
notification.builder_api_key.not_configured.copy_trading_config=跟單配置
notification.builder_api_key.not_configured.redeemable_positions=可贖回倉位
notification.builder_api_key.not_configured.total_value=總價值
notification.builder_api_key.not_configured.message=請在系統設置中配置 Builder API Key 以啟用自動贖回功能。
notification.builder_api_key.not_configured.positions_unit=
notification.builder_api_key.not_configured.unknown_config=未命名配置
# 通用
common.unknown=未知