Function listenPartialProfitOnce

  • Subscribes to filtered partial profit 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 profit conditions.

    Parameters

    • filterFn: (event: PartialProfitContract) => boolean

      Predicate to filter which events trigger the callback

    • fn: (event: PartialProfitContract) => void

      Callback function to handle the filtered event (called only once)

    Returns () => void

    Unsubscribe function to cancel the listener before it fires

    import { listenPartialProfitOnce } from "./function/event";

    // Wait for first 50% profit level on any signal
    listenPartialProfitOnce(
    (event) => event.level === 50,
    (event) => console.log("50% profit reached:", event.data.id)
    );

    // Wait for 30% profit on BTCUSDT
    const cancel = listenPartialProfitOnce(
    (event) => event.symbol === "BTCUSDT" && event.level === 30,
    (event) => console.log("BTCUSDT hit 30% profit")
    );

    // Cancel if needed before event fires
    cancel();