TRADEHUBTESTNET

All tools

size_position_by_risk

Size a position by risk · read-only, idempotent · scopes: read

Turns "risk 1% of equity, stop 2% below" into a size in the base coin, rounded down to the venue step and capped by every limit (this agent's, the person's and TradeHub's). Reads equity, mark and contract rules itself: no need for get_my_account_balances or get_perp_contract_rules first. Use before every preview_perp_order. Not an order: nothing is sent. Inputs: symbol, stop_loss (USD) or stop_pct with side, risk_pct or risk_usd (default: the most allowed), venue, entry_price (default: mark), leverage. Next: preview_perp_order with the returned size_base, stop_loss and leverage.

Call it

MCP tools/call

{"name": "size_position_by_risk", "arguments": {"symbol": "BTC"}}

REST

POST /v1/sizing
{"symbol": "BTC"}

Inputs

NameMeaning (* required)
symbol *Base coin, e.g. BTC
stop_lossStop-loss price, USD per coin; below entry for a long, above for a short. Or give stop_pct and side instead
stop_pctStop distance from entry as a fraction (0.02 = 2%), instead of stop_loss; needs side
sidebuy = long, sell = short; needed with stop_pct
venueVenue: sandbox, hyperliquid, okx, bybit or binance. Omitted: the agent's only venue, else hyperliquid, else your only connected venue, else sandbox
entry_pricePlanned entry, USD per coin; omitted: the mark
risk_pctLoss at stop as a fraction of equity (0.01 = 1%); omitted with risk_usd also omitted: the largest your limits allow
risk_usdLoss at stop in USD (instead of risk_pct)
notional_usdOr the position's value in USD ("buy $200 worth"), instead of risk_pct / risk_usd; still capped by the risk limits
leverageLeverage for the margin estimate, e.g. 5

Returns

FieldMeaning and unit
venueVenue name
symbolBase coin
sidebuy (long) or sell (short), from the stop's side of entry
entry_priceEntry used, USD per coin (the mark when not given)
stop_lossStop-loss used, USD per coin
size_baseSuggested size, in the base coin (e.g. BTC), not USD, rounded down to the venue's size step; pass it to preview_perp_order as size_base
notional_usdsize_base x entry, USD
risk_usdLoss if the stop fills, USD
risk_pct_of_equityrisk_usd / equity, as a fraction
margin_usdMargin needed at the given leverage, USD
leverageLeverage assumed
equity_usdEquity used for the calculation (the venue's book), USD
capped_byWhich limit made the size smaller than asked, if any
within_limitsFalse if even the capped size cannot pass (e.g. below the venue minimum)

Rejections: error codes, each with what to do.

TradeHub never asks for withdrawal permissions.