Skip to content

Conversation

@dfkai
Copy link

@dfkai dfkai commented Nov 6, 2025

📝 Description | 描述

English: Fixed critical UI crashes and API routing configuration issues that prevented proper functionality in admin mode. This PR resolves three interconnected bugs: AILearning component crashes due to null pointer access, equity-history API 404 errors due to incorrect route configuration, and competition API unavailability in admin mode.

中文: 修复了管理员模式下阻止正常功能的关键UI崩溃和API路由配置问题。此PR解决了三个相互关联的bug:由于空指针访问导致的AILearning组件崩溃、由于路由配置错误导致的equity-history API 404错误,以及管理员模式下竞赛API不可用的问题。


🎯 Type of Change | 变更类型

  • 🐛 Bug fix | 修复 Bug
  • ✨ New feature | 新功能
  • 💥 Breaking change | 破坏性变更
  • 📝 Documentation update | 文档更新
  • 🎨 Code style update | 代码样式更新
  • ♻️ Refactoring | 重构
  • ⚡ Performance improvement | 性能优化
  • ✅ Test update | 测试更新
  • 🔧 Build/config change | 构建/配置变更
  • 🔒 Security fix | 安全修复

🔗 Related Issues | 相关 Issue

  • Related to user-reported issues: "获取历史数据失败" and "加载AI学习数据失败"
  • 相关用户报告问题:"获取历史数据失败"和"加载AI学习数据失败"

📋 Changes Made | 具体变更

English:

  • Frontend (web/src/App.tsx): Added null safety check for selectedTrader before rendering AILearning component to prevent runtime crashes
  • Backend (api/server.go): Moved /api/equity-history from public to protected routes to ensure proper authentication context
  • Backend (api/server.go): Moved public competition APIs outside admin mode conditional to ensure availability in all deployment modes

中文:

  • 前端 (web/src/App.tsx): 在渲染AILearning组件前添加selectedTrader空值检查,防止运行时崩溃
  • 后端 (api/server.go): 将/api/equity-history从公开路由移动到受保护路由,确保正确的认证上下文
  • 后端 (api/server.go): 将公开竞赛API移出管理员模式条件判断,确保在所有部署模式下都可用

🧪 Testing | 测试

  • Tested locally | 本地测试通过
  • Tests pass | 测试通过
  • Verified no existing functionality broke | 确认没有破坏现有功能

Test Results | 测试结果:

  • ✅ AILearning component no longer crashes | AILearning组件不再崩溃
  • ✅ EquityChart loads historical data properly | EquityChart正确加载历史数据
  • ✅ Competition page works in admin mode | 竞赛页面在管理员模式下正常工作
  • ✅ No console 404 errors | 无控制台404错误
  • ✅ All existing features remain functional | 所有现有功能保持正常

✅ Checklist | 检查清单

Code Quality | 代码质量

  • Code follows project style | 代码遵循项目风格
  • Self-review completed | 已完成代码自查
  • Comments added for complex logic | 已添加必要注释

Documentation | 文档

  • Updated relevant documentation | 已更新相关文档

Git

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

📚 Additional Notes | 补充说明

English:

Root Cause Analysis | 根本原因分析

  1. Timing Issue: selectedTrader was undefined during async data loading, causing property access errors
  2. Route Misconfiguration: handleEquityHistory required authentication context but was placed in public routes
  3. Conditional Logic Error: Admin mode check prevented public APIs from being registered

Security Considerations | 安全考虑

  • equity-history API now properly requires authentication
  • Public competition APIs remain unauthenticated as designed
  • No new security vulnerabilities introduced

Backward Compatibility | 向后兼容性

  • All changes are backward compatible
  • No breaking changes to existing API contracts
  • Maintains existing functionality while fixing bugs

中文:

根本原因分析

  1. 时序问题: 异步数据加载期间selectedTrader为undefined,导致属性访问错误
  2. 路由配置错误: handleEquityHistory需要认证上下文但被放置在公开路由中
  3. 条件逻辑错误: 管理员模式检查阻止了公开API的注册

安全考虑

  • equity-history API现在正确地需要认证
  • 公开竞赛API按设计保持无需认证
  • 未引入新的安全漏洞

向后兼容性

  • 所有更改都向后兼容
  • 对现有API契约无破坏性更改
  • 在修复bug的同时保持现有功能

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! | 感谢你的贡献!

dfkai added 2 commits November 6, 2025 15:44
Add null check to prevent runtime error when accessing trader_id property
Move equity-history to protected routes and make competition APIs available in admin mode
dfkai added 4 commits November 6, 2025 19:37
## 🎯 修改目标
优化仓位大小配置,提高资金利用效率,否则无论如何调整杠杆或者加大减小资金都面临较大波动风险

## 📊 主要改进
- 最多持仓币种数:3个 → 4个
- 山寨币仓位系数:0.8x-1.5x → 0.2x-0.5x  
- BTC/ETH仓位系数:5x-10x → 0.5x-1.5x
- 保证金使用率上限:90% → 95%

## ✅ 解决的问题
1. **小账户适配**:400美金账户从只能开1个币种提升到4个币种
2. **资金利用率**:大账户资金利用率从20-30%提升到85-95%
3. **风险分散**:支持多币种分散持仓,降低单币种风险
4. **全仓模式优化**:适配全仓模式的风险特征

## 📈 预期效果
- 400美金账户:可稳定开4个币种
- 2000美金账户:资金利用率提升300%
- 10000美金账户:从资金浪费到高效利用

## 🔧 技术细节
- 同步修改提示词生成和验证逻辑,确保一致性
- 保持风险回报比1:3等核心风控不变
- 适配全仓模式的保证金共享特性

测试环境:Docker部署,多个资金规模验证通过
@xqliu
Copy link
Contributor

xqliu commented Nov 8, 2025

admin 模式已删除,本 PR 请帮忙关闭 @hzb1115
hzb1115
@tangmengqiu
tangmengqiu
@SkywalkerJi
SkywalkerJi
@Icyoung
Icyoung

@hzb1115
Copy link
Member

hzb1115 commented Nov 11, 2025

已移除admin相关功能

@hzb1115 hzb1115 closed this Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants