mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-11 14:56:57 +08:00
fix(api): add balance sync endpoint with smart detection
## Summary - Add POST /traders/:id/sync-balance endpoint (Option B) - Add smart detection showing balance change percentage (Option C) - Fix balance display bug caused by commit2b9c4d2## Changes ### api/server.go - Add handleSyncBalance() handler - Query actual exchange balance via trader.GetBalance() - Calculate change percentage for smart detection - Update initial_balance in database - Reload trader into memory after update ### config/database.go - Add UpdateTraderInitialBalance() method - Update traders.initial_balance field ## Root Cause Commit2b9c4d2auto-queries exchange balance at trader creation time, but never updates after user deposits more funds, causing: - Wrong initial_balance (400 USDT vs actual 3000 USDT) - Wrong P&L calculations (-2598.55 USDT instead of actual) ## Solution Provides manual sync API + smart detection to update initial_balance when user deposits funds after trader creation. Co-Authored-By: tinkle-community <tinklefund@gmail.com>
This commit is contained in:
@@ -853,6 +853,12 @@ func (d *Database) UpdateTraderCustomPrompt(userID, id string, customPrompt stri
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateTraderInitialBalance 更新交易员初始余额(用于同步交易所实际余额)
|
||||
func (d *Database) UpdateTraderInitialBalance(userID, id string, newBalance float64) error {
|
||||
_, err := d.db.Exec(`UPDATE traders SET initial_balance = ? WHERE id = ? AND user_id = ?`, newBalance, id, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteTrader 删除交易员
|
||||
func (d *Database) DeleteTrader(userID, id string) error {
|
||||
_, err := d.db.Exec(`DELETE FROM traders WHERE id = ? AND user_id = ?`, id, userID)
|
||||
|
||||
Reference in New Issue
Block a user