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;
|
simpleWorkerRunning = true;
|
||||||
try {
|
try {
|
||||||
const entries = (await listManualEntries()).filter((entry) => entry.active && isSimpleWorkflowEntry(entry));
|
const entries = (await listManualEntries()).filter((entry) => entry.active && isSimpleWorkflowEntry(entry));
|
||||||
|
const processedSimpleExitKeys = new Set<string>();
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
const symbol = String(entry.symbol || '').trim().toUpperCase();
|
const symbol = String(entry.symbol || '').trim().toUpperCase();
|
||||||
if (!symbol) continue;
|
if (!symbol) continue;
|
||||||
@ -339,6 +340,22 @@ async function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const linkedTradeId = String(entry.linked_trade_id || '').trim();
|
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
|
const activePosition = linkedTradeId
|
||||||
? ctx.executor.getActivePosition(symbol, linkedTradeId)
|
? ctx.executor.getActivePosition(symbol, linkedTradeId)
|
||||||
: ctx.executor.getActivePosition(symbol);
|
: ctx.executor.getActivePosition(symbol);
|
||||||
@ -370,9 +387,11 @@ async function main() {
|
|||||||
const exitResult = await ctx.manualTrader.executeExit(symbol, currentPrice, 'Simple target hit', linkedTradeId || undefined);
|
const exitResult = await ctx.manualTrader.executeExit(symbol, currentPrice, 'Simple target hit', linkedTradeId || undefined);
|
||||||
if (!exitResult.success) {
|
if (!exitResult.success) {
|
||||||
logger.warn(`[SimpleWorker] Exit trigger failed for ${symbol}: ${exitResult.error || 'unknown error'}`);
|
logger.warn(`[SimpleWorker] Exit trigger failed for ${symbol}: ${exitResult.error || 'unknown error'}`);
|
||||||
|
processedSimpleExitKeys.add(exitDedupKey);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processedSimpleExitKeys.add(exitDedupKey);
|
||||||
await saveManualEntryForUser(entry.user_id, {
|
await saveManualEntryForUser(entry.user_id, {
|
||||||
...entry,
|
...entry,
|
||||||
profile_id: entry.profile_id || ctx.profileId,
|
profile_id: entry.profile_id || ctx.profileId,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user