validateTpSl
Validate a candidate TP/SL pair against the handler’s published rules. Pure and framework-agnostic — a Node script or a Vue app can share it with the React form. The SDK does not throw here; the caller decides whether to surface, block, or proceed.
Checks, in order:
- Sign rule — TP above/below the reference price per side; SL the opposite.
minPriceDistancePercent—|target − open| / open × 100must clear the floor.minProfitStopLossSpreadPercent— when both sides are set, the absolute TP↔SL spread as a percent of the reference price must clear the floor.
import { validateTpSl } from "@symmio/trading-core";
const result = validateTpSl({
takeProfitPrice: "150",
stopLossPrice: "80",
openPrice: "100",
positionType: PositionType.LONG,
pricePrecision: 4,
config: tpslConfig,
});
if (!result.ok) {
console.log(result.tpError, result.slError);
}Parameters
A single ValidateTpSlInputs object:
openPricestringrequiredReference price the distance/spread rules are measured against (decimal string).
positionTypePositionTyperequiredQuote direction (LONG / SHORT).
pricePrecisionnumberrequiredMarket price precision — used to render the “should be above/below X” hint.
Live handler /configs/ data.
takeProfitPricestringoptionalTP trigger price (decimal string). Omit when only setting an SL.
stopLossPricestringoptionalSL trigger price (decimal string). Omit when only setting a TP.
isOpenPositionbooleanoptionalWhen true, error text says “current price” instead of “open price”.
Returns
{ ok: true } when every supplied side passes; otherwise { ok: false } with per-side tpError / slError strings.
Related
ValidateTpSlInputs— the input shape.TpSlValidation— the outcome shape.getTpSlConfig— source of theconfigrules.