Commit Graph

16 Commits

Author SHA1 Message Date
Icyoung 52f3985408 Merge branch 'dev' into feat/auto-balance-sync 2025-11-05 16:01:57 +08:00
ZhouYongyou 7091f76ca8 feat(trader): add automatic balance sync every 10 minutes
## 功能说明
自动检测交易所余额变化,无需用户手动操作
## 核心改动
1. AutoTrader 新增字段:
   - lastBalanceSyncTime: 上次余额同步时间
   - database: 数据库引用(用于自动更新)
   - userID: 用户ID
2. 新增方法 autoSyncBalanceIfNeeded():
   - 每10分钟检查一次(避免与3分钟扫描周期重叠)
   - 余额变化>5%才更新数据库
   - 智能失败重试(避免频繁查询)
   - 完整日志记录
3. 集成到交易循环:
   - 在 runCycle() 中第3步自动调用
   - 先同步余额,再获取交易上下文
   - 不影响现有交易逻辑
4. TraderManager 更新:
   - addTraderFromDB(), AddTraderFromDB(), loadSingleTrader()
   - 新增 database 和 userID 参数
   - 正确传递到 NewAutoTrader()
5. Database 新增方法:
   - UpdateTraderInitialBalance(userID, id, newBalance)
   - 安全更新初始余额
## 为什么选择10分钟?
1. 避免与3分钟扫描周期重叠(每30分钟仅重叠1次)
2. API开销最小化:每小时仅6次额外调用
3. 充值延迟可接受:最多10分钟自动同步
4. API占用率:0.2%(远低于币安2400次/分钟限制)
## API开销
- GetBalance() 轻量级查询(权重5-10)
- 每小时仅6次额外调用
- 总调用:26次/小时(runCycle:20 + autoSync:6)
- 占用率:(10/2400)/60 = 0.2% 
## 用户体验
- 充值后最多10分钟自动同步
- 完全自动化,无需手动干预
- 前端数据实时准确
## 日志示例
- 🔄 开始自动检查余额变化...
- 🔔 检测到余额大幅变化: 693.00 → 3693.00 USDT (433.19%)
-  已自动同步余额到数据库
- ✓ 余额变化不大 (2.3%),无需更新
2025-11-04 20:51:14 +08:00
sue 616c350835 fix(trader): add missing HyperliquidTestnet configuration in loadSingleTrader
修复了 loadSingleTrader 函数中缺失的 HyperliquidTestnet 配置项,
确保 Hyperliquid 交易所的测试网配置能够正确传递到 trader 实例。
Changes:
- 在 loadSingleTrader 中添加 HyperliquidTestnet 字段配置
- 代码格式优化(空格对齐)
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-11-04 19:02:39 +08:00
icy 8e76be5a29 Resolve merge conflicts with dev branch
Resolved conflicts in:
- api/server.go: Preserved beta_mode config and user permission checks
- manager/trader_manager.go: Kept optimized concurrent competition data with caching
Maintained all performance optimizations while merging new features from dev.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-11-04 01:36:54 +08:00
hzb1115 62ebd58a1f style(backend): go fmt code 2025-11-03 17:22:11 +00:00
icy 82fcb690fe Optimize /api/competition endpoint performance with concurrent data fetching and caching
## Performance Improvements:
- **Concurrent Processing**: Replace serial GetAccountInfo() calls with parallel goroutines
- **Timeout Control**: Add 3-second timeout per trader to prevent blocking
- **30-second Cache**: Implement competition data cache to reduce API calls
- **Error Handling**: Graceful degradation when API calls fail or timeout
## API Changes:
- Reduce top traders from 10 to 5 for better chart performance
- Update /api/equity-history-batch to use top 5 traders by default
- Add detailed logging for cache hits and performance monitoring
## Expected Performance Gains:
- First request: ~85% faster (from 25s to 3s for 50 traders)
- Cached requests: ~99.96% faster (from 25s to 10ms)
- Better user experience with consistent response times
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-11-03 23:45:09 +08:00
icy 5af5c0b517 Enhance leaderboard and security for trader management
Features:
- Limit leaderboard to top 50 traders sorted by PnL percentage
- Add top 10 traders endpoint for performance comparison
- Create batch equity history endpoint to optimize frontend performance
- Add public trader config endpoint without sensitive data
Security:
- Add user ownership validation for start/stop trader operations
- Prevent users from controlling other users' traders
- Maintain consistent error messages for security
Performance:
- Reduce API calls from 10 to 1 for performance comparison page
- Add data limits and error handling for batch operations
- Sort traders by performance across all endpoints
API Changes:
- GET /api/traders - now returns top 50 sorted traders
- GET /api/top-traders - new endpoint for top 10 traders
- GET /api/equity-history-batch - batch endpoint for multiple trader histories
- GET /api/traders/:id/public-config - public config without secrets
- POST /api/traders/:id/start - now validates user ownership
- POST /api/traders/:id/stop - now validates user ownership
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: tinkle-community <tinklefund@gmail.com>
2025-11-03 20:14:39 +08:00
SkywalkerJi 5ad135310f Supports custom system prompts and custom models. 2025-11-01 19:45:54 +08:00
SkywalkerJi 7542f9df49 * Fixed the custom model URL.
*   Added functionality for custom model names.
2025-11-01 16:09:15 +08:00
icy d1d9810075 竞赛fix、交易员新增参数 2025-11-01 02:17:11 +08:00
icy 142863f554 Add MarginMode configration 2025-10-31 13:14:24 +08:00
icy 72e14c1f0d rename fix 2025-10-31 04:07:14 +08:00
icy ceb2f7b435 account system、custom prompt 2025-10-31 03:42:01 +08:00
icy 82beac0920 sync fork 2025-10-30 20:51:22 +08:00
nobody 0164ac6cc0 feat: Add Hyperliquid exchange support with unified trader interface
Major changes:
- Add full Hyperliquid trading support (long/short, leverage, SL/TP)
- Create unified Trader interface for multi-exchange support
- Implement automatic precision handling for orders and prices
- Fix balance calculation and unrealized P&L display
- Add comprehensive configuration guide in README
New features:
- Support for both Binance and Hyperliquid exchanges
- Automatic order size precision based on szDecimals
- Price formatting with 5 significant figures
- Non-custodial trading with Ethereum private key
- Seamless exchange switching via configuration
Technical details:
- Add trader/interface.go for unified trader interface
- Add trader/hyperliquid_trader.go for Hyperliquid implementation
- Update manager and auto_trader to support multiple exchanges
- Add go-hyperliquid SDK dependency
- Fix precision errors (float_to_wire, invalid price)
Fixes:
- Correct calculation of wallet balance and unrealized P&L
- Proper handling of AccountValue vs TotalRawUsd
- Frontend display issues for total equity and P&L
Documentation:
- Add Hyperliquid setup guide in README
- Update config.json.example with both exchanges
- Add troubleshooting section for common errors
Tested with live trading on Hyperliquid mainnet.
No breaking changes - backward compatible with existing configs.
2025-10-29 20:00:30 +08:00
tinkle-community 5aa50d35d7 Initial commit: NOFX AI Trading System
- Multi-AI competition mode (Qwen vs DeepSeek)
- Binance Futures integration
- AI self-learning mechanism
- Professional web dashboard
- Complete risk management system
2025-10-28 15:47:34 +08:00