Function commitPartialLossCost

  • Executes partial close at loss level by absolute dollar amount (moving toward SL).

    Convenience wrapper around commitPartialLoss that converts a dollar amount to a percentage of the invested position cost automatically. Price must be moving toward stop loss (in loss direction).

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

    Parameters

    • symbol: string

      Trading pair symbol

    • dollarAmount: number

      Dollar value of position to close (e.g. 100 closes $100 worth)

    Returns Promise<boolean>

    Promise - true if partial close executed, false if skipped or no position

    Error if currentPrice is not in loss direction:

    • LONG: currentPrice must be < priceOpen
    • SHORT: currentPrice must be > priceOpen
    import { commitPartialLossCost } from "backtest-kit";

    // Close $100 of a $300 position (~33%) at loss
    const success = await commitPartialLossCost("BTCUSDT", 100);
    if (success) {
    console.log('Partial loss executed');
    }