fix: 重启时查交易所验证持仓是否存在,幽灵仓位自动标记 closed

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
jackyu66git
2026-05-05 03:23:44 +08:00
co-authored by Claude Opus 4.7
parent 2f4d7869a9
commit 047571921e
+15
View File
@@ -1977,6 +1977,21 @@ func (t *Trader) restoreOpenPositions() {
}
}
pos.DBTradeID = tr.ID
// Verify position still exists on exchange — if not, mark as closed
posMissing := false
if t.bitget != nil && (pos.LongLeg.Exchange == ExBitget || pos.ShortLeg.Exchange == ExBitget) {
bgSymbol := tr.Coin + "USDT"
if bgSize, _ := t.bitget.CheckPosition(bgSymbol); bgSize <= 0 {
log.Printf("[Trader] Trade %d (%s): Bitget position not found on exchange, marking as closed", tr.ID, tr.Coin)
posMissing = true
}
}
if posMissing {
t.db.SetTradeStatus(tr.ID, "closed")
continue
}
t.positions[tr.Coin] = pos
// Prevent immediate re-trading of the same coin
t.lastTradeTime[tr.Coin] = tr.OpenedAt