feat: Add trader enabled switch and fix critical bugs

New Features:
- Add 'enabled' field to trader config for selective startup
- Only enabled traders will be initialized and run
- Display skip messages for disabled traders in logs

Bug Fixes:
- Fix Hyperliquid account value calculation
  * AccountValue is total equity, no need to add TotalMarginUsed
  * Correctly calculate wallet balance without unrealized PnL
  * Fix available balance calculation (AccountValue - TotalMarginUsed)
- Fix frontend page refresh navigation issue
  * Use URL hash to persist page state across refreshes
  * Support browser back/forward buttons
  * Prevent Details page from reverting to Competition on refresh

Technical Changes:
- config/config.go: Add Enabled bool field to TraderConfig
- main.go: Skip disabled traders during initialization
- trader/hyperliquid_trader.go: Correct account value logic
- web/src/App.tsx: Implement hash-based routing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
tinkle
2025-10-30 21:07:43 +08:00
parent b83e027eb0
commit 007fa2567d
4 changed files with 69 additions and 14 deletions

19
main.go
View File

@@ -56,8 +56,16 @@ func main() {
// 创建TraderManager
traderManager := manager.NewTraderManager()
// 添加所有trader
// 添加所有启用的trader
enabledCount := 0
for i, traderCfg := range cfg.Traders {
// 跳过未启用的trader
if !traderCfg.Enabled {
log.Printf("⏭️ [%d/%d] 跳过未启用的 %s", i+1, len(cfg.Traders), traderCfg.Name)
continue
}
enabledCount++
log.Printf("📦 [%d/%d] 初始化 %s (%s模型)...",
i+1, len(cfg.Traders), traderCfg.Name, strings.ToUpper(traderCfg.AIModel))
@@ -74,9 +82,18 @@ func main() {
}
}
// 检查是否至少有一个启用的trader
if enabledCount == 0 {
log.Fatalf("❌ 没有启用的trader请在config.json中设置至少一个trader的enabled=true")
}
fmt.Println()
fmt.Println("🏁 竞赛参赛者:")
for _, traderCfg := range cfg.Traders {
// 只显示启用的trader
if !traderCfg.Enabled {
continue
}
fmt.Printf(" • %s (%s) - 初始资金: %.0f USDT\n",
traderCfg.Name, strings.ToUpper(traderCfg.AIModel), traderCfg.InitialBalance)
}