Compare commits

..

8 Commits

Author SHA1 Message Date
WrBug 7b4e702da9 ci(close-issue): add Telegram notification when AI-fixed issue is closed
- Get issue details (title, url) for TG message
- Send TG via TELEGRAM_BOT_TOKEN/TELEGRAM_CHAT_ID (same as docker-build)
- Use GH_TOKEN from GITHUB_TOKEN for gh CLI

Made-with: Cursor
2026-03-10 12:39:33 +08:00
WrBug e32697e7ee ci: add workflow to close issue when PR is merged
- Trigger on pull_request closed (merged) to main
- Parse issue number from PR body (Closes #N) or branch name (ai_fix/N_xxx)
- Close linked issue via GitHub API if still open

Made-with: Cursor
2026-03-10 12:34:35 +08:00
WrBug d8a75fc8dd fix: #35 [Bug] / 价差策略按比例买入,购买的价值小于1usdc时,会下单失败 2026-03-10 12:18:03 +08:00
WrBug 915d4570df Update AI bug report template to bilingual (English/Chinese) 2026-03-10 02:39:50 +08:00
WrBug 48d6e82f43 Add AI bug report template 2026-03-10 02:30:26 +08:00
WrBug 0fb015f6d3 Merge pull request #33 from WrBug/dev
Release v2.3.3: 加密价差策略与尾盘监控优化
2026-02-25 21:34:54 +08:00
WrBug a0c2d7995b Merge pull request #32 from WrBug/dev
Release v2.3.2: 尾盘策略多市场与币安按需订阅
2026-02-20 23:50:10 +08:00
WrBug 7c1f8df590 Merge pull request #31 from WrBug/dev
feat: 账户设置、尾盘策略与文档整理
2026-02-18 03:29:38 +08:00
3 changed files with 372 additions and 29 deletions
+201
View File
@@ -0,0 +1,201 @@
---
name: 🤖 Bug Report for AI Fix / AI Bug 报告
description: Bug 报告模板(提交后请手动添加 'fix via ai' 标签触发自动修复)
title: '[Bug] / '
assignees: []
body:
- type: markdown
attributes:
value: |
## Bug Report Template 🐛
本模板用于报告 PolyHermes 项目的 bug。
⚠️ **Important / 重要提示**
- After submission, if you need AI auto-fix, please manually add the `fix via ai` label
/ 提交后,如需 AI 自动修复,请手动添加 `fix via ai` 标签
- AI fixes will be on the `fix_issues_by_ai` branch / AI 修复将在 `fix_issues_by_ai` 分支上进行
- All AI fixes require human review before merging / 所有 AI 修复需要人工审核后才能合并
- Security vulnerabilities, database migrations, major changes are not recommended for AI auto-fix
/ 涉及安全漏洞、数据库迁移、重大变更等问题不建议使用 AI 自动修复
---
本模板用于报告 PolyHermes 项目的 bug。
This template is for reporting bugs in the PolyHermes project.
- type: textarea
id: description
attributes:
label: 📝 Bug Description / Bug 描述
description: Clearly and concisely describe the bug / 清晰简洁地描述这个 bug
placeholder: Describe the bug you encountered / 描述你遇到的问题...
validations:
required: true
- type: dropdown
id: type
attributes:
label: 🎯 Bug Type / 问题类型
description: Select the type of bug / 选择问题类型
options:
- Frontend bug (UI/UX/interaction) / 前端 bug (UI/UX/交互问题)
- Backend bug (API/logic/data) / 后端 bug (API/逻辑/数据处理)
- Database issue / 数据库问题
- Performance issue / 性能问题
- Configuration/Deployment / 配置/部署问题
- Documentation / 文档问题
- Other / 其他
validations:
required: true
- type: dropdown
id: scope
attributes:
label: 📍 Affected Scope / 影响范围
description: Select the scope of impact / 选择问题影响范围
options:
- Specific page/function only / 仅影响特定页面/功能
- Entire system / 影响整个系统
- Specific user role / 影响特定用户角色
- Only in specific environment / 仅在特定环境下重现
validations:
required: true
- type: textarea
id: steps
attributes:
label: 🔍 Steps to Reproduce / 复现步骤
description: Provide clear, detailed steps to reproduce the bug / 提供清晰、详细的步骤来重现这个 bug
placeholder: |
1. Visit page: `...` / 访问页面:`...`
2. Click button: `...` / 点击按钮:`...`
3. Input data: `...` / 输入数据:`...`
4. Submit form: `...` / 提交表单:`...`
5. Observe error: `...` / 观察到错误:`...`
validations:
required: true
- type: dropdown
id: frequency
attributes:
label: Reproduction Frequency / 复现频率
options:
- Always reproducible (100%) / 总是能复现 (100%)
- Frequently reproducible (50%+) / 经常能复现 (50%+)
- Occasionally reproducible (<50%) / 偶尔能复现 (<50%)
- Hard to reproduce / 很难复现
validations:
required: true
- type: textarea
id: expected
attributes:
label: 💻 Expected Behavior / 预期行为
description: Describe what you expected to happen / 描述你期望发生什么
placeholder: What should happen / 应该发生什么...
validations:
required: true
- type: textarea
id: actual
attributes:
label: ❌ Actual Behavior / 实际行为
description: Describe what actually happened / 描述实际发生了什么
placeholder: What actually happened / 实际发生了什么...
validations:
required: true
- type: textarea
id: screenshots
attributes:
label: 📸 Screenshots / Recordings / 截图/录屏
description: If applicable, add screenshots or recordings to illustrate the problem (drag and drop files here)
/ 如果适用,添加截图或录屏来说明问题(可以拖拽文件到这里)
placeholder: Add screenshots or recordings / 添加截图或录屏...
- type: textarea
id: environment
attributes:
label: 🌐 Environment / 环境
description: Provide relevant environment information / 提供相关环境信息
value: |
**Browser (for frontend issues) / 浏览器(前端问题):**
- Browser: ______ / 浏览器:______
- Browser version: ______ / 浏览器版本:______
- Operating System: ______ / 操作系统:______
**Backend Environment (for backend issues) / 后端环境(后端问题):**
- Node.js version: ______ / Node.js 版本:______
- Database version: ______ / 数据库版本:______
- Docker version (if used): ______ / Docker 版本(如果使用):______
- Other relevant dependencies: ______ / 其他相关依赖版本:______
validations:
required: false
- type: textarea
id: related-files
attributes:
label: 📁 Related Files / Code / 相关文件/代码
description: Provide relevant file paths or code snippets / 提供可能涉及的文件路径或相关代码片段
placeholder: |
Possibly related files / 可能涉及的文件:
- frontend/src/components/...
- backend/src/main/kotlin/...
Error logs / 错误日志:
```
Paste error logs here / 粘贴错误日志
```
validations:
required: false
- type: textarea
id: suggestions
attributes:
label: 🎯 Fix Suggestions (Optional) / 修复建议(可选)
description: If you have fix ideas, describe them briefly / 如果你有修复思路,可以在这里简单描述
placeholder: |
Suggest adding ZZZ check in the YYY method of file XXX
/ 建议在 XXX 文件的 YYY 方法中,添加 ZZZ 检查
...
- type: dropdown
id: priority
attributes:
label: 🚨 Priority / 优先级
options:
- 🔴 High - Blocking core functionality, affects user experience / 高 - 阻塞核心功能,影响用户体验
- 🟡 Medium - Limited functionality but not blocking / 中 - 功能受限但不阻塞
- 🟢 Low - Minor issue, doesn't affect usage / 低 - 小问题,不影响使用
validations:
required: true
- type: textarea
id: additional
attributes:
label: 📝 Additional Information / 补充说明
description: Any other information that helps AI understand and fix the issue / 任何其他有助于 AI 理解和修复问题的信息
placeholder: |
- Was this bug introduced recently? / 这个 bug 是最近引入的吗?
- Is it related to a specific PR or commit? / 是否与某个特定的 PR 或 commit 相关?
- Does it only occur with specific datasets or users? / 是否只在特定数据集或特定用户情况下出现?
/ ...
Any other context / 其他任何上下文信息...
- type: checkboxes
id: ai-fix-approval
attributes:
label: 🤖 AI Auto-Fix Confirmation / AI 自动修复确认
description: If you need AI to auto-fix this issue, check the options below (remember to add 'fix via ai' label after submission)
/ 如需 AI 自动修复此 issue,请勾选下方选项(提交后记得添加 'fix via ai' 标签)
options:
- label: |
I understand the AI auto-fix workflow and agree to manually review the AI-created PR
/ 我已了解 AI 自动修复的工作流程,并同意在 AI 创建 PR 后进行人工审核
required: false
- label: |
This issue is suitable for AI auto-fix (not a security vulnerability, not a database migration, not a major change)
/ 此问题适合 AI 自动修复(非安全漏洞、非数据库迁移、非重大变更)
required: false
@@ -0,0 +1,127 @@
# PR 合并后自动关闭关联的 Issue
# 当 PR 从 ai_fix/N_xxx 分支合并到 main 时,关闭 #N 对应的 Issue(若 PR 描述中未含 Closes #N 则通过分支名解析)
# 关闭后发送 Telegram 通知(复用 TELEGRAM_BOT_TOKEN / TELEGRAM_CHAT_ID
name: Close issue on PR merge
on:
pull_request:
types: [closed]
branches: [main]
jobs:
close-issue:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: read
steps:
- name: Get PR info
id: pr
run: |
# 从 PR body 查找 Closes #N / Fixes #N(若已有则 GitHub 已自动关 issue,本 step 仅做解析)
BODY="${{ github.event.pull_request.body }}"
HEAD_REF="${{ github.event.pull_request.head.ref }}"
# 优先从 PR 描述解析
ISSUE_NUM=$(echo "$BODY" | grep -oE '(Closes|Fixes|Resolves) #([0-9]+)' | head -1 | grep -oE '[0-9]+')
if [ -z "$ISSUE_NUM" ]; then
# 从分支名解析 ai_fix/N_xxx
ISSUE_NUM=$(echo "$HEAD_REF" | sed -n 's|^ai_fix/\([0-9]*\)_.*|\1|p')
fi
if [ -z "$ISSUE_NUM" ]; then
echo "ISSUE_NUMBER=" >> $GITHUB_OUTPUT
echo "skip=true" >> $GITHUB_OUTPUT
echo "未从 PR 描述或分支名解析到 Issue 编号,跳过关闭"
exit 0
fi
echo "ISSUE_NUMBER=$ISSUE_NUM" >> $GITHUB_OUTPUT
echo "skip=false" >> $GITHUB_OUTPUT
echo "解析到 Issue #$ISSUE_NUM"
- name: Get issue details
if: steps.pr.outputs.skip != 'true'
id: issue
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ISSUE_NUM="${{ steps.pr.outputs.ISSUE_NUMBER }}"
# 获取 issue 标题与 URL(用于 TG 消息)
JSON=$(gh issue view "$ISSUE_NUM" --json title,url 2>/dev/null || echo '{"title":"","url":""}')
TITLE=$(echo "$JSON" | jq -r '.title')
ISSUE_URL=$(echo "$JSON" | jq -r '.url')
echo "title<<EOF" >> $GITHUB_OUTPUT
echo "$TITLE" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "url=$ISSUE_URL" >> $GITHUB_OUTPUT
- name: Close issue
if: steps.pr.outputs.skip != 'true'
uses: actions/github-script@v7
with:
script: |
const issueNumber = parseInt('${{ steps.pr.outputs.ISSUE_NUMBER }}', 10);
if (!issueNumber || isNaN(issueNumber)) {
console.log('No valid issue number, skip');
return;
}
const { data: issue } = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
if (issue.state === 'open') {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: 'closed'
});
console.log(`Issue #${issueNumber} closed.`);
} else {
console.log(`Issue #${issueNumber} already closed.`);
}
- name: Send Telegram notification
if: steps.pr.outputs.skip != 'true'
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
run: |
# 与 docker-build 一致:未配置则跳过
if [ -z "$TELEGRAM_BOT_TOKEN" ] || [ -z "$TELEGRAM_CHAT_ID" ]; then
echo "⚠️ Telegram Bot Token 或 Chat ID 未配置,跳过通知"
exit 0
fi
ISSUE_NUM="${{ steps.pr.outputs.ISSUE_NUMBER }}"
ISSUE_TITLE="${{ steps.issue.outputs.title }}"
ISSUE_URL="${{ steps.issue.outputs.url }}"
PR_URL="${{ github.event.pull_request.html_url }}"
# 与 docker-build 相同的 HTML 消息格式
MESSAGE="✅ <b>AI 修复的 Issue 已关闭</b>"$'\n'$'\n'"🔢 <b>Issue:</b> #${ISSUE_NUM} ${ISSUE_TITLE}"$'\n'"📎 <a href=\"${ISSUE_URL}\">查看 Issue</a>"$'\n'"🔗 <a href=\"${PR_URL}\">查看 PR</a>"
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-H "Content-Type: application/json" \
-d "$(jq -n \
--arg chat_id "$TELEGRAM_CHAT_ID" \
--arg text "$MESSAGE" \
'{chat_id: $chat_id, text: $text, parse_mode: "HTML", disable_web_page_preview: false}')" > /tmp/telegram_response.json
if [ $? -eq 0 ]; then
RESPONSE=$(cat /tmp/telegram_response.json)
if echo "$RESPONSE" | grep -q '"ok":true'; then
echo "✅ Telegram 通知发送成功"
else
echo "❌ Telegram 通知发送失败: $RESPONSE"
exit 0
fi
else
echo "❌ 发送 Telegram 消息时发生错误"
exit 0
fi
@@ -43,6 +43,9 @@ private const val SPREAD_MAX_PRICE_ADJUSTMENT = "0.02"
/** 数量小数位数,与 OrderSigningService 的 roundConfig.size 一致 */
private const val SIZE_DECIMAL_SCALE = 2
/** 单笔下单最小 USDC 金额(平台限制),RATIO 模式计算值低于此值时按此值下单 */
private val MIN_ORDER_USDC = BigDecimal("1")
/**
* 周期内预置上下文:账户、解密凭证、费率、签名类型、CLOB 客户端;不含预签订单。
* 触发时 FIXED/RATIO 均按 outcomeIndex 计算 size 并签名提交。
@@ -151,7 +154,7 @@ class CryptoTailStrategyExecutionService(
}
val signatureType = orderSigningService.getSignatureTypeForWalletType(account.walletType)
if (strategy.amountMode.uppercase() != "RATIO" && strategy.amountValue < BigDecimal("1")) return null
if (strategy.amountMode.uppercase() != "RATIO" && strategy.amountValue < MIN_ORDER_USDC) return null
val ctx = PeriodContext(
strategy = strategy,
@@ -334,29 +337,36 @@ class CryptoTailStrategyExecutionService(
val ctx = getOrInvalidatePeriodContext(strategy, periodStartUnix)
if (ctx != null) {
val amountUsdc = when (strategy.amountMode.uppercase()) {
var availableBalanceForRatio = BigDecimal.ZERO
var amountUsdc = when (strategy.amountMode.uppercase()) {
"RATIO" -> {
val balanceResult = accountService.getAccountBalance(ctx.account.id)
val availableBalance =
balanceResult.getOrNull()?.availableBalance?.toSafeBigDecimal() ?: BigDecimal.ZERO
availableBalanceForRatio = availableBalance
availableBalance.multiply(strategy.amountValue).divide(BigDecimal("100"), 18, RoundingMode.DOWN)
}
else -> strategy.amountValue
}
if (amountUsdc < BigDecimal("1")) {
saveTriggerRecord(
strategy,
periodStartUnix,
marketTitle,
outcomeIndex,
triggerPrice,
amountUsdc,
null,
"fail",
"投入金额不足"
)
return
if (amountUsdc < MIN_ORDER_USDC) {
val amountMode = strategy.amountMode.uppercase()
if (amountMode == "RATIO" && availableBalanceForRatio >= MIN_ORDER_USDC) {
amountUsdc = MIN_ORDER_USDC
} else {
saveTriggerRecord(
strategy,
periodStartUnix,
marketTitle,
outcomeIndex,
triggerPrice,
amountUsdc,
null,
"fail",
"投入金额不足"
)
return
}
}
val tokenId = tokenIds.getOrNull(outcomeIndex) ?: run {
@@ -514,23 +524,28 @@ class CryptoTailStrategyExecutionService(
val balanceResult = accountService.getAccountBalance(account.id)
val availableBalance = balanceResult.getOrNull()?.availableBalance?.toSafeBigDecimal() ?: BigDecimal.ZERO
val amountUsdc = when (strategy.amountMode.uppercase()) {
var amountUsdc = when (strategy.amountMode.uppercase()) {
"RATIO" -> availableBalance.multiply(strategy.amountValue).divide(BigDecimal("100"), 18, RoundingMode.DOWN)
else -> strategy.amountValue
}
if (amountUsdc < BigDecimal("1")) {
saveTriggerRecord(
strategy,
periodStartUnix,
marketTitle,
outcomeIndex,
triggerPrice,
amountUsdc,
null,
"fail",
"投入金额不足"
)
return
if (amountUsdc < MIN_ORDER_USDC) {
val amountMode = strategy.amountMode.uppercase()
if (amountMode == "RATIO" && availableBalance >= MIN_ORDER_USDC) {
amountUsdc = MIN_ORDER_USDC
} else {
saveTriggerRecord(
strategy,
periodStartUnix,
marketTitle,
outcomeIndex,
triggerPrice,
amountUsdc,
null,
"fail",
"投入金额不足"
)
return
}
}
val tokenId = tokenIds.getOrNull(outcomeIndex) ?: run {