fix: 重启时查交易所验证持仓是否存在,幽灵仓位自动标记 closed
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
2f4d7869a9
commit
047571921e
@@ -1977,6 +1977,21 @@ func (t *Trader) restoreOpenPositions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pos.DBTradeID = tr.ID
|
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
|
t.positions[tr.Coin] = pos
|
||||||
// Prevent immediate re-trading of the same coin
|
// Prevent immediate re-trading of the same coin
|
||||||
t.lastTradeTime[tr.Coin] = tr.OpenedAt
|
t.lastTradeTime[tr.Coin] = tr.OpenedAt
|
||||||
|
|||||||
Reference in New Issue
Block a user