diff --git a/trader.go b/trader.go index 2ccb314..2ce78f7 100644 --- a/trader.go +++ b/trader.go @@ -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