nofx icon indicating copy to clipboard operation
nofx copied to clipboard

feat(market): add OI time series and multi-timeframe data support (Part 1/3)

Open the-dev-z opened this issue 1 year ago • 4 comments

Pull Request - Backend | 后端 PR

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


📝 Description | 描述

English: Implement OI (Open Interest) time series data support and multi-timeframe data analysis, resolving the issue where AI cannot verify "OI increased >+3% in the last 4 hours" condition.

中文: 實現 OI(持倉量)時間序列數據支持與多時間框架數據分析,解決 AI 無法驗證「OI 近 4 小時上升 >+3%」條件的問題。


🎯 Type of Change | 变更类型

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

🔗 Related Issues | 相关 Issue

  • Related to #703 (Split into Part 1/3)
  • Based on latest upstream/dev (3112250)
  • Preserves hook module functionality (#784)

📋 Changes Made | 具体变更

English:

  • Added OI historical data caching (15-minute sampling, keeps 20 snapshots)
  • Implemented 4-hour OI change rate calculation (1-hour tolerance, cold-start friendly)
  • Added 15m/1h multi-timeframe K-line data
  • Integrated OI change rate into AI input (Format outputs "Change(4h): X.XX%")

中文:

  • OI 歷史數據緩存(15分鐘採樣,保留 20 個快照)
  • 計算 4 小時變化率(容差 1 小時,冷啟動友好)
  • 新增 15m/1h 多時間框架 K線數據
  • 整合到 AI 輸入(Format 輸出 "Change(4h): X.XX%")

Files Modified:

  • market/types.go: Added OISnapshot, extended OIData (Change4h, Historical)
  • market/monitor.go: StartOIMonitoring(), CalculateOIChange4h(), 15m/1h K-line data flow
  • market/data.go: Integrated OI change rate and multi-timeframe data
  • market/api_client.go: GetOpenInterest(), GetOpenInterestHistory(), preserved hook module ✅

🧪 Testing | 测试

Test Environment | 测试环境

  • OS | 操作系统: macOS 14.5
  • Go Version | Go 版本: Go 1.x
  • Exchange | 交易所: Binance Futures API compatible

Manual Testing | 手动测试

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

Test Results | 测试结果

✅ market package compiled successfully
✅ Full project compiled successfully
✅ Hook module functionality preserved

🔒 Security Considerations | 安全考虑

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

⚡ Performance Impact | 性能影响

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

If impacted, explain | 如果受影响,请说明: Uses sync.Map for concurrent safety with minimal overhead. 15-minute sampling is lightweight.


✅ Checklist | 检查清单

Code Quality | 代码质量

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

Documentation | 文档

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

Git

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

📚 Additional Notes | 补充说明

English: This is Part 1/3 of PR #703 split. Based on latest upstream/dev (3112250) and fully preserves hook module functionality.

中文: 這是 PR #703 的 Part 1/3 拆分。基於最新 upstream/dev (3112250),完整保留 hook 模組功能。


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

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

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

the-dev-z avatar Nov 09 '25 01:11 the-dev-z

🤖 Advisory Check Results

These are advisory checks to help improve code quality. They won't block your PR from being merged.

📋 PR Information

Title Format: ✅ Good - Follows Conventional Commits PR Size: 🟡 Medium (823 lines: +762 -61)

🔧 Backend Checks

Go Formatting: ⚠️ Needs formatting

Files needing formatting
auth/auth.go
bootstrap/bootstrap.go
config/database.go
config/database_test.go
crypto/crypto.go
main.go
market/api_client.go
market/data.go
trader/auto_trader.go

Go Vet: ✅ Good Tests: ✅ Passed

Fix locally:

go fmt ./...      # Format code
go vet ./...      # Check for issues
go test ./...     # Run tests

⚛️ Frontend Checks

Build & Type Check: ✅ Success

Fix locally:

cd web
npm run build  # Test build (includes type checking)

📖 Resources

Questions? Feel free to ask in the comments! 🙏


These checks are advisory and won't block your PR from being merged. This comment is automatically generated from pr-checks-run.yml.

github-actions[bot] avatar Nov 09 '25 01:11 github-actions[bot]

🤖 Advisory Check Results

These are advisory checks to help improve code quality. They won't block your PR from being merged.

📋 PR Information

Title Format: ✅ Good - Follows Conventional Commits PR Size: 🔴 Large (1058 lines: +997 -61)

💡 Suggestion: This is a large PR. Consider breaking it into smaller, focused PRs for easier review.

🔧 Backend Checks

Go Formatting: ⚠️ Needs formatting

Files needing formatting
auth/auth.go
bootstrap/bootstrap.go
config/database.go
config/database_test.go
crypto/crypto.go
main.go
market/api_client.go
market/data.go
trader/auto_trader.go

Go Vet: ✅ Good Tests: ✅ Passed

Fix locally:

go fmt ./...      # Format code
go vet ./...      # Check for issues
go test ./...     # Run tests

⚛️ Frontend Checks

Build & Type Check: ✅ Success

Fix locally:

cd web
npm run build  # Test build (includes type checking)

📖 Resources

Questions? Feel free to ask in the comments! 🙏


These checks are advisory and won't block your PR from being merged. This comment is automatically generated from pr-checks-run.yml.

github-actions[bot] avatar Nov 09 '25 03:11 github-actions[bot]

🤖 Advisory Check Results

These are advisory checks to help improve code quality. They won't block your PR from being merged.

📋 PR Information

Title Format: ✅ Good - Follows Conventional Commits PR Size: 🔴 Large (1089 lines: +1009 -80)

💡 Suggestion: This is a large PR. Consider breaking it into smaller, focused PRs for easier review.

🔧 Backend Checks

Go Formatting: ⚠️ Needs formatting

Files needing formatting
api/server.go
manager/trader_manager.go

Go Vet: ✅ Good Tests: ✅ Passed

Fix locally:

go fmt ./...      # Format code
go vet ./...      # Check for issues
go test ./...     # Run tests

⚛️ Frontend Checks

Build & Type Check: ✅ Success

Fix locally:

cd web
npm run build  # Test build (includes type checking)

📖 Resources

Questions? Feel free to ask in the comments! 🙏


These checks are advisory and won't block your PR from being merged. This comment is automatically generated from pr-checks-run.yml.

github-actions[bot] avatar Nov 10 '25 16:11 github-actions[bot]

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 13 committers have signed the CLA.

:white_check_mark: tinkle-community
:x: 0xEmberZz
:x: the-dev-z
:x: tinkle
:x: xqliu
:x: SkillingX
:x: hzb1115
:x: SkywalkerJi
:x: Icyoung
:x: web3gaoyutang
:x: livelybug
:x: 0xbigtang
:x: tangmengqiu


tinkle seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

cla-assistant[bot] avatar Dec 22 '25 16:12 cla-assistant[bot]