Function commitPartialProfitCost

  • Executes partial close at profit level by absolute dollar amount (moving toward TP).

    Convenience wrapper around commitPartialProfit that converts a dollar amount to a percentage of the invested position cost automatically. Price must be moving toward take profit (in profit 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. 150 closes $150 worth)

    Returns Promise<boolean>

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

    Error if currentPrice is not in profit direction:

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

    // Close $150 of a $300 position (50%) at profit
    const success = await commitPartialProfitCost("BTCUSDT", 150);
    if (success) {
    console.log('Partial profit executed');
    }