From 1532b55d77e9afb83cdc38e76347f4c02b698007 Mon Sep 17 00:00:00 2001 From: tinkle-community Date: Mon, 19 Jan 2026 15:50:53 +0800 Subject: [PATCH] fix(sync): always query REALIZED_PNL to detect closed positions Previously Method 4 (REALIZED_PNL) only ran when symbolMap was empty. This caused fully-closed positions to be missed if other symbols were detected. Now REALIZED_PNL is always queried to catch positions that: - Have no active position (fully closed) - Were missed by COMMISSION detection (VIP users, BNB fee discount) --- trader/binance_order_sync.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/trader/binance_order_sync.go b/trader/binance_order_sync.go index 0c0d14ac..bd63367c 100644 --- a/trader/binance_order_sync.go +++ b/trader/binance_order_sync.go @@ -100,18 +100,17 @@ func (t *FuturesTrader) SyncOrdersFromBinance(traderID string, exchangeID string symbolMap[s] = true } - // Method 4: FALLBACK - Query REALIZED_PNL income to find symbols with closed trades + // Method 4: ALWAYS query REALIZED_PNL income to find symbols with closed trades // This catches trades that COMMISSION missed (VIP users, BNB fee discount) - if len(symbolMap) == 0 { - logger.Infof(" 🔍 No symbols found, trying REALIZED_PNL fallback...") - pnlSymbols, err := t.GetPnLSymbols(lastSyncTime) - if err != nil { - logger.Infof(" ⚠️ Failed to get PnL symbols: %v", err) - } else { - logger.Infof(" 📋 REALIZED_PNL symbols found: %d - %v", len(pnlSymbols), pnlSymbols) - for _, s := range pnlSymbols { - symbolMap[s] = true - } + // IMPORTANT: Must run always, not just when symbolMap is empty, + // because a position might be fully closed (no active position) but have PnL + pnlSymbols, err := t.GetPnLSymbols(lastSyncTime) + if err != nil { + logger.Infof(" ⚠️ Failed to get PnL symbols: %v", err) + } else { + logger.Infof(" 📋 REALIZED_PNL symbols found: %d - %v", len(pnlSymbols), pnlSymbols) + for _, s := range pnlSymbols { + symbolMap[s] = true } }