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 { listenPartialLossOnce } from "./function/event";
// Wait for first 20% loss level on any signal
listenPartialLossOnce(
(event) => event.level === 20,
(event) => console.log("20% loss reached:", event.data.id)
);
// Wait for 10% loss on ETHUSDT in live mode
const cancel = listenPartialLossOnce(
(event) => event.symbol === "ETHUSDT" && event.level === 10 && !event.backtest,
(event) => console.log("ETHUSDT hit 10% loss in live mode")
);
// Cancel if needed before event fires
cancel();
Subscribes to filtered partial loss level events with one-time execution.
Listens for events matching the filter predicate, then executes callback once and automatically unsubscribes. Useful for waiting for specific loss conditions.