Back to Strategies
Confidence-Filtered Signal with Cooldown & Notification
Code Reaction by 0xsDp5JzBDn·2026-07-02
// Expected payload sent to this reaction:
// {
// "signal": "BUY", // "BUY" | "SELL"
// "confidence": 0.87, // 0–1 score from the sending system
// "source": "my-lstm-model" // free-text identifier for the sender
// }
const payload = JSON.parse($.Request.data);
const state = await $.Storage.get() || { lastSignalAt: 0 };
const now = Date.now();
const COOLDOWN_MS = 5 * 60 * 1000; // 5 minutes
if (now - state.lastSignalAt < COOLDOWN_MS) {
// Still cooling down from the last signal — ignore duplicates
} else if (payload.signal === "BUY" && payload.confidence >= 0.8) {
await $.Strategy.action($.Action.LONG, { id: payload.source, dilution: false });
state.lastSignalAt = now;
await $.Http.post($.Env.NOTIFY_URL, { text: `LONG opened via ${payload.source}` });
} else if (payload.signal === "SELL" && $.Strategy.lastTrigger.action !== $.Action.EXIT) {
await $.Strategy.action($.Action.EXIT);
state.lastSignalAt = now;
await $.Http.post($.Env.NOTIFY_URL, { text: `Position exited via ${payload.source}` });
}
await $.Storage.set(state);