Function getPositionPnlPercent

  • Returns the unrealized PNL percentage for the current pending signal at current market price.

    Accounts for partial closes, DCA entries, slippage and fees (delegates to toProfitLossDto).

    Returns null if no pending signal exists.

    Automatically detects backtest/live mode from execution context. Automatically fetches current price via getAveragePrice.

    Parameters

    • symbol: string

      Trading pair symbol

    Returns Promise<number>

    Promise resolving to PNL percentage or null

    import { getPositionPnlPercent } from "backtest-kit";

    const pnlPct = await getPositionPnlPercent("BTCUSDT");
    // LONG at 100, current=105: pnlPct ≈ 5
    // LONG at 100, current=95: pnlPct ≈ -5