Function partialProfit

  • Executes partial close at profit level (moving toward TP).

    Closes a percentage of the active pending position at profit. Price must be moving toward take profit (in profit direction).

    Automatically detects backtest/live mode from execution context.

    Parameters

    • symbol: string

      Trading pair symbol

    • percentToClose: number

      Percentage of position to close (0-100, absolute value)

    Returns Promise<boolean>

    Promise - true if partial close executed, false if skipped

    Error if currentPrice is not in profit direction:

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

    // Close 30% of LONG position at profit
    const success = await partialProfit("BTCUSDT", 30);
    if (success) {
    console.log('Partial profit executed');
    }