Skip to content

Size a trade from a risk basis, with fee and buying-power modelling.

POST
/api/calculator
curl --request POST \
--url https://api.tradr.cloud/api/calculator \
--header 'Content-Type: application/json' \
--data '{ "balance": "example", "direction": "long", "dollarRisk": "example", "entryPrice": "example", "feeSchedule": {}, "manualFees": "example", "mode": "stock", "riskPercent": "example", "stopLoss": "example", "targetPrice": "example" }'

Authed and stateless — the whole calculation is a pure function of the request body (no DB read, no account id). Supply the trade shape (entryPrice, stopLoss, direction, mode) plus exactly one risk basis: a direct dollarRisk, OR a balance + riskPercent (the dollar risk is then derived as balance × riskPercent ÷ 100 at full precision). Supplying both bases, or neither, is a 400. In the percent basis the position size is also capped to what the balance can fund at entry (floor(balance ÷ (entry × multiplier))); the three percent-only response fields (derivedDollarRisk, sizingStatus, buyingPowerLimited) are absent from dollar-basis results. Non-sizing outcomes (non-positive balance, derived risk over the ceiling, insufficient risk, balance funds zero units) are valid 200s with positionSize: 0 and a sizingStatus discriminator — not 400s.

Media typeapplication/json

Provide exactly one risk basis — dollarRisk, or balance + riskPercent.

object
balance

Percent-basis balance to size against and cap against. Sign-agnostic finite decimal within the account-balance domain (a losing account’s balance can be ≤ 0). Percent basis requires both balance and riskPercent.

string
direction
required
string
Allowed values: long short
dollarRisk

Dollar-basis risk (positive decimal up to 99,999,999.99). Required in dollar mode; omit (or send empty ⇒ treated as absent) in percent mode.

string
entryPrice
required

Positive decimal up to 9,999,999.99.

string
feeSchedule

Optional brokerage fee schedule (mutually exclusive with manualFees).

object
manualFees

Optional flat fee estimate (mutually exclusive with feeSchedule).

string
mode
required
string
Allowed values: stock options
riskPercent

Percent of balance to risk (0 < p ≤ 100).

string
stopLoss
required

Positive decimal up to 9,999,999.99.

string
targetPrice

Optional positive decimal for R:R.

string

A CalculatorOutput. Always carries positionSize, perUnitRisk, actualDollarRisk, totalPositionValue; perUnitReward / riskRewardRatio when a target is set, and the fee fields when fees are supplied. Percent basis additionally echoes derivedDollarRisk (2dp, when balance > 0), sizingStatus (nothing-to-size-against | exceeds-maximum | buying-power-zero) on the zero-position outcomes, and buyingPowerLimited: true when the buying-power cap set the size.

Validation error — both/neither risk basis, riskPercent ∉ (0,100], bad balance/price format, or a structural price error.

Authentication required.