Files
nofx/manager
ZhouYongyou e8f05d1761 feat(trader): add automatic balance sync every 30 minutes
## Summary
Automatically sync trader's initial_balance when exchange balance changes
significantly (>5%), eliminating the need for manual intervention after
deposits/withdrawals.

## Changes

### trader/auto_trader.go
- Add fields: lastBalanceSyncTime, database, userID
- Add autoSyncBalanceIfNeeded() method:
  * Check every 30 minutes (配合3分钟扫描周期,约10次扫描触发一次)
  * Query exchange balance via trader.GetBalance()
  * Update if change >5%
  * Log changes with emoji indicators
- Integrate into runCycle() before trading decisions

### manager/trader_manager.go
- Update NewAutoTrader() calls to pass database and userID
- Update method signatures:
  * addTraderFromDB()
  * AddTraderFromDB()
  * loadSingleTrader()

## Configuration

- Check interval: 30 minutes
- Change threshold: 5%
- Automatic detection and update

## Benefits

 完全自动化,无需手动调用API
 30分钟检查间隔,及时又不频繁
 智能判断(变化>5%才更新)
 充值/提现后自动更新initial_balance
 前端P&L显示自动修正

## Example Logs

🔄 [DS-BF] 开始自动检查余额变化...
🔔 [DS-BF] 检测到余额大幅变化: 693.00 → 3000.00 USDT (333.33%)
 [DS-BF] 已自动同步余额到数据库

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 20:31:40 +08:00
..