fix(simple): dedupe exit retries per scan
This commit is contained in:
parent
349cdae4a6
commit
e50e906866
@ -273,6 +273,7 @@ async function main() {
|
||||
simpleWorkerRunning = true;
|
||||
try {
|
||||
const entries = (await listManualEntries()).filter((entry) => entry.active && isSimpleWorkflowEntry(entry));
|
||||
const processedSimpleExitKeys = new Set<string>();
|
||||
for (const entry of entries) {
|
||||
const symbol = String(entry.symbol || '').trim().toUpperCase();
|
||||
if (!symbol) continue;
|
||||
@ -339,6 +340,22 @@ async function main() {
|
||||
}
|
||||
|
||||
const linkedTradeId = String(entry.linked_trade_id || '').trim();
|
||||
const exitDedupKey = linkedTradeId ? `${symbol}::${linkedTradeId}` : symbol;
|
||||
if (processedSimpleExitKeys.has(exitDedupKey)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const exitLifecycle = ctx.executor.getExitLifecycle(symbol);
|
||||
if (
|
||||
exitLifecycle.state === 'initiated'
|
||||
|| exitLifecycle.state === 'order_placed'
|
||||
|| exitLifecycle.state === 'verifying'
|
||||
|| exitLifecycle.state === 'quarantined'
|
||||
) {
|
||||
processedSimpleExitKeys.add(exitDedupKey);
|
||||
continue;
|
||||
}
|
||||
|
||||
const activePosition = linkedTradeId
|
||||
? ctx.executor.getActivePosition(symbol, linkedTradeId)
|
||||
: ctx.executor.getActivePosition(symbol);
|
||||
@ -370,9 +387,11 @@ async function main() {
|
||||
const exitResult = await ctx.manualTrader.executeExit(symbol, currentPrice, 'Simple target hit', linkedTradeId || undefined);
|
||||
if (!exitResult.success) {
|
||||
logger.warn(`[SimpleWorker] Exit trigger failed for ${symbol}: ${exitResult.error || 'unknown error'}`);
|
||||
processedSimpleExitKeys.add(exitDedupKey);
|
||||
continue;
|
||||
}
|
||||
|
||||
processedSimpleExitKeys.add(exitDedupKey);
|
||||
await saveManualEntryForUser(entry.user_id, {
|
||||
...entry,
|
||||
profile_id: entry.profile_id || ctx.profileId,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user