Predicate to filter which events trigger the callback
Callback function to handle the filtered event (called only once)
Unsubscribe function to cancel the listener before it fires
import { listenSignalOnce } from "./function/event";
// Wait for first take profit hit
listenSignalOnce(
(event) => event.action === "closed" && event.closeReason === "take_profit",
(event) => {
console.log("Take profit hit! PNL:", event.pnl.pnlPercentage);
}
);
// Wait for any signal to close on BTCUSDT
const cancel = listenSignalOnce(
(event) => event.action === "closed" && event.signal.symbol === "BTCUSDT",
(event) => console.log("BTCUSDT signal closed")
);
// Cancel if needed before event fires
cancel();
Subscribes to filtered signal events with one-time execution.
Listens for events matching the filter predicate, then executes callback once and automatically unsubscribes. Useful for waiting for specific signal conditions.