Skip to content

fix(decision): align Prompt with validation for min position size and leverage - #99

Merged
xqliu merged 6 commits into
nextfrom
fix/94-binance-stop-loss-api-error
Nov 25, 2025
Merged

xqliu merged 6 commits into
nextfrom
fix/94-binance-stop-loss-api-error

Conversation

@xqliu

@xqliu xqliu commented Nov 25, 2025 •

Copy link
Copy Markdown
Collaborator

Pull Request - Backend | 后端 PR

💡 提示 Tip: 推荐 PR 标题格式 type(scope): description
例如: feat(trader): add new strategy | fix(api): resolve auth issue


📝 Description | 描述

English: | 中文:


🎯 Type of Change | 变更类型

  • 🐛 Bug fix | 修复 Bug
  • ✨ New feature | 新功能
  • 💥 Breaking change | 破坏性变更
  • ♻️ Refactoring | 重构
  • ⚡ Performance improvement | 性能优化
  • 🔒 Security fix | 安全修复
  • 🔧 Build/config change | 构建/配置变更

🔗 Related Issues | 相关 Issue

  • Closes # | 关闭 #
  • Related to # | 相关 #

📋 Changes Made | 具体变更

English: | 中文:


🧪 Testing | 测试

Test Environment | 测试环境

  • OS | 操作系统:
  • Go Version | Go 版本:
  • Exchange | 交易所: [if applicable | 如适用]

Manual Testing | 手动测试

  • Tested locally | 本地测试通过
  • Tested on testnet | 测试网测试通过(交易所集成相关)
  • Unit tests pass | 单元测试通过
  • Verified no existing functionality broke | 确认没有破坏现有功能

Test Results | 测试结果

Test output here | 测试输出

🔒 Security Considerations | 安全考虑

  • No API keys or secrets hardcoded | 没有硬编码 API 密钥
  • User inputs properly validated | 用户输入已正确验证
  • No SQL injection vulnerabilities | 无 SQL 注入漏洞
  • Authentication/authorization properly handled | 认证/授权正确处理
  • Sensitive data is encrypted | 敏感数据已加密
  • N/A (not security-related) | 不适用

⚡ Performance Impact | 性能影响

  • No significant performance impact | 无显著性能影响
  • Performance improved | 性能提升
  • Performance may be impacted (explain below) | 性能可能受影响

If impacted, explain | 如果受影响,请说明:


✅ Checklist | 检查清单

Code Quality | 代码质量

  • Code follows project style | 代码遵循项目风格
  • Self-review completed | 已完成代码自查
  • Comments added for complex logic | 已添加必要注释
  • Code compiles successfully | 代码编译成功 (go build)
  • Ran go fmt | 已运行 go fmt

Documentation | 文档

  • Updated relevant documentation | 已更新相关文档
  • Added inline comments where necessary | 已添加必要的代码注释
  • Updated API documentation (if applicable) | 已更新 API 文档

Git

  • Commits follow conventional format | 提交遵循 Conventional Commits 格式
  • Rebased on latest dev branch | 已 rebase 到最新 dev 分支
  • No merge conflicts | 无合并冲突

📚 Additional Notes | 补充说明

English: | 中文:


By submitting this PR, I confirm | 提交此 PR,我确认:

  • I have read the Contributing Guidelines | 已阅读贡献指南
  • I agree to the Code of Conduct | 同意行为准则
  • My contribution is licensed under AGPL-3.0 | 贡献遵循 AGPL-3.0 许可证

🌟 Thank you for your contribution! | 感谢你的贡献!

Fixes #94

币安 API 限制:STOP 和 TAKE_PROFIT(限价订单)不支持 closePosition=true 参数,
只有 STOP_MARKET 和 TAKE_PROFIT_MARKET 才支持。发送不兼容的参数组合会导致:
- 错误代码: -4136
- 错误信息: "Target strategy invalid for orderType STOP,closePosition true"

修改内容:
- trader/binance_futures.go: 移除 SetStopLoss 和 SetTakeProfit 中的 ClosePosition(true)
- trader/binance_futures_test.go: 改进 mock server 模拟 -4136 错误
- trader/binance_futures_test.go: 新增3个专项测试验证修复

现在使用:
- STOP + Price + Quantity(限价止损)
- TAKE_PROFIT + Price + Quantity(限价止盈)

测试覆盖:
- TestSetStopLoss_NoClosePosition: 验证不发送 closePosition 参数
- TestSetTakeProfit_NoClosePosition: 验证不发送 closePosition 参数
- TestSetStopLoss_WithClosePositionWouldFail: 证明旧代码会失败
重构测试代码,消除重复:
- 提取 setupMockServerWithParamCapture helper 函数
- 提取 createTestTrader helper 函数
- 合并 SetStopLoss 和 SetTakeProfit 测试为 table-driven test

代码减少:224 行 → 171 行(减少 53 行)
重复率降低:65.1% → 预计 <15%
测试覆盖保持不变
修复 SonarCloud 检测的问题:
1. 定义常量替代重复的字符串字面量
   - binanceOrderPath = "/fapi/v1/order"
   - binanceExchangeInfoPath = "/fapi/v1/exchangeInfo"

2. 重命名测试函数符合命名规范
   - TestStopLossAndTakeProfit_NoClosePosition → TestStopLossAndTakeProfitNoClosePosition
   - TestSetStopLoss_WithClosePositionWouldFail → TestSetStopLossWithClosePositionWouldFail

所有测试仍然通过,功能不变
… leverage

- Add getMinPositionSize(exchange) function for consistent min position size:
  - Binance: 100 USDT
  - Hyperliquid: 12 USDT
  - Aster: 10 USDT
- Update Prompt to display exchange-specific minimum position size
- Change leverage validation from auto-fallback to rejection (match Prompt wording)
- Add emphasis on position limit constraints in Prompt

This fixes the contract mismatch where Prompt said "≥12 USDT for all" but
validation used different values per exchange.
@github-actions

Copy link
Copy Markdown

🔧 已自动应用专用模板 | Auto-Applied Template

检测到您的PR主要包含 backend 相关的变更,系统已自动为您应用相应的模板。

Detected that your PR primarily contains backend changes. The appropriate template has been automatically applied.

文件统计 | File Statistics

  • 🔧 Go files: 9
  • 🎨 TypeScript files: 1

已应用模板 | Applied Template
.github/PULL_REQUEST_TEMPLATE/backend.md

✨ 您现在可以直接在PR描述中填写相关信息了!

✨ You can now fill in the relevant information in the PR description!

@xqliu

xqliu commented Nov 25, 2025

Copy link
Copy Markdown
Collaborator Author

@claude 用中文审查下

@xqliu xqliu closed this Nov 25, 2025
@xqliu xqliu reopened this Nov 25, 2025
@xqliu
xqliu merged commit 73007cb into next Nov 25, 2025
4 of 6 checks passed
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant