feat(crypto-tail): 尾盘策略收益与胜率:轮询未结算订单并回写收益

- 新增 V35 迁移:trigger 表增加 condition_id/resolved/winner_outcome_index/realized_pnl/settled_at
- 新增 CryptoTailSettlementService:每 10s 轮询 success 未结算订单,Gamma+链上查结算,优先用 CLOB 订单实际成交价与成交量算收益
- 防重叠:与订单轮询一致使用 Job+CoroutineScope,上一轮未结束则跳过
- 策略/触发 DTO 暴露 totalRealizedPnl、胜率及单笔 resolved/realizedPnl

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
WrBug
2026-02-14 05:22:56 +08:00
co-authored by Cursor
parent 2238370088
commit 0efd4a5fc3
6 changed files with 332 additions and 18 deletions
@@ -0,0 +1,13 @@
-- ============================================
-- V35: 尾盘策略触发记录 - 结算与收益字段
-- 用于轮询服务:扫描 success 但未结算的订单,查链上结算结果并回写收益
-- ============================================
ALTER TABLE crypto_tail_strategy_trigger
ADD COLUMN condition_id VARCHAR(66) DEFAULT NULL COMMENT '市场 conditionId(用于查链上结算)' AFTER order_id,
ADD COLUMN resolved TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否已结算: 0=未结算, 1=已结算',
ADD COLUMN winner_outcome_index INT DEFAULT NULL COMMENT '市场赢家 outcome 索引(结算后写入)',
ADD COLUMN realized_pnl DECIMAL(20, 8) DEFAULT NULL COMMENT '已实现盈亏 USDC(赢为正,输为负)',
ADD COLUMN settled_at BIGINT DEFAULT NULL COMMENT '结算时间(毫秒时间戳)';
CREATE INDEX idx_trigger_settlement ON crypto_tail_strategy_trigger (status, resolved);