Function investedCostToPercent

Convert an absolute dollar amount to a percentage of the invested position cost. Use the result as the percent argument to commitPartialProfit / commitPartialLoss.

const percent = investedCostToPercent(150, 300); // 50
await commitPartialProfit("BTCUSDT", percent);
  • Parameters

    • dollarAmount: number

      Dollar value to close (e.g. 150)

    • investedCost: number

      Total invested cost from getPositionInvestedCost (e.g. 300)

    Returns number

    Percentage of the position to close (0–100)