How does an AI trading agent size a crypto position?
How does an AI trading agent size a crypto position? The honest answer for most agents in 2026 is: it doesn't. It picks a direction, the prompt says "use sensible risk", and the model writes a fixed dollar amount or a fixed percentage of equity. That works until the first week where realized volatility triples and the fixed size becomes a margin call.
A sizing rule that survives contact with crypto needs three numbers, and all three are observable rather than guessed:
- How far the stop sits, in price units that scale with the coin's recent range. That is the Average True Range (ATR), a smoothed average of each bar's true range.
- How much of the normal size this coin deserves right now, given its own realized vol versus a target. That is a vol-target multiplier.
- How much gross exposure the whole book should run, given market-wide volatility stress. That is a gross exposure scalar.
This post walks through where each comes from on the CryptoDataAPI, with exact field names, and ends with a Python function that combines them. Every value is taken from the API as served; nothing here requires the agent to estimate volatility itself.
Step 1: ATR on the execution-truth bars (/hyperliquid/candles?atr=14)
The Hyperliquid candle route computes a Wilder ATR for you when you add atr=<period>. The formula is the classic one: true range is max(high-low, |high-prev_close|, |low-prev_close|), the first ATR is the mean of the first N true ranges, and every later bar is (prev_ATR x (N-1) + TR) / N. That is the same recursion TradingView's ta.atr uses, so an agent and a human looking at a chart agree.
curl "https://cryptodataapi.com/api/v1/hyperliquid/candles?coin=SOL&interval=4h&limit=200&atr=14" \
-H "X-API-Key: cdk_live_your_key"
Representative response excerpt (illustrative values):
{
"candles": [
{"timestamp": 1763064000000, "open": 141.20, "high": 143.85, "low": 139.90,
"close": 142.60, "volume": 812345.0, "atr": 3.41},
...
],
"count": 200,
"atr_period": 14,
"forming_bar_timestamp": 1763078400000
}
Three details matter for sizing:
atrisnullfor the first N bars of the window. Pull about 10x the period (limit=200foratr=14) so the last value has converged.forming_bar_timestampnames the last bar when it has not closed yet (nullonce it has). Drop that bar and itsatrfor a completed-bar size; otherwise a half-formed bar with a small range shrinks your stop.- These are Hyperliquid's own bars, not a blended index. If the order executes on Hyperliquid, size it from this series. Coin names are Hyperliquid's (
kPEPE, notPEPE), and an unknown parameter or coin is a 400 rather than a silent default.
Any key can read this route. Hyperliquid itself keeps only about 5,000 bars per interval, so a 4h window with limit=200 is comfortably inside retention.
Step 2: the per-coin vol-target multiplier (/quant/coins/risk)
ATR tells you where the stop goes. It does not tell you whether this coin should carry a full-size position at all. That is what vol_target_multiplier on /quant/coins/risk answers for the whole quant universe in one call (Pro tier).
curl "https://cryptodataapi.com/api/v1/quant/coins/risk?horizon=24h" \
-H "X-API-Key: cdk_live_your_key"
{
"as_of": "2026-11-14T08:15:00Z",
"horizon": "24h",
"items": [
{
"symbol": "SOL",
"regime": {"label": "range", "confidence": 0.62},
"vol_target_multiplier": 0.86,
"vol_pctile_30": 71.0,
"rv_24h": 68.4,
"probabilities": {"...": "volatility / liquidation_risk / funding / open_interest buckets"},
"meta": {"status": "ok", "insufficient_history": false, "new_listing": false}
}
],
"count": 180,
"universe_size": 180
}
The multiplier is absolute, not relative: it is 60 / realized_vol, clamped to [0.25, 3.0], where 60% annualized is the vol level a 1.0x position is sized for. A coin running 120% realized vol gets 0.5; a coin at 30% gets 2.0; anything at or above 240% pins to the 0.25 floor. Because it is absolute, a chronically wild meme perp sits at the floor permanently, which is the point.
The companion fields tell you how much to trust it:
vol_pctile_30: where today's vol sits in the coin's own 30-day distribution. A multiplier of 0.5 at the 95th percentile is a shock; the same 0.5 at the 40th percentile is just a volatile coin.rv_24h: live intraday realized vol.nullon backfilled or illiquid names, which means "no intraday read", not "zero vol".meta.insufficient_history/meta.new_listing: the coin still appears so you can mark it ineligible, rather than vanishing from the list.
Values match the per-symbol /quant/coins/{symbol} and /volatility/regime/{symbol} routes exactly. This is a batched view, not a second model.
Step 3: the market-wide gross scalar (gross_exposure_multiplier)
Per-coin sizing still lets an agent run full gross across twenty coins on the day the whole market enters a vol shock. The third number is a single scalar for the book: gross_exposure_multiplier, in [0.5, 1.0].
It is derived from composite_score, a 0-100 breadth gauge of how much of the universe sits in expanding or shock volatility regimes. At or below the 50 baseline the multiplier is 1.0; it ramps linearly down to 0.5 at a composite of 100. sentiment labels the same score: stressed (70 and above), elevated (55-69), normal (45-54), calm (30-44) and dormant (below 30, the dangerously quiet compressed state).
Two routes serve it:
/volatility/regime/score(Pro Plus):composite_score,sentiment,target_vol(the 60 behind the per-coin multiplier),gross_exposure_multiplier,median_vol_pctile_30and the regime aggregate./volatility/index(every plan): the samecomposite_score,sentimentandgross_exposure_multiplier, next to the headlinecvi_realized_30, a volume-weighted annualized 30-day realized vol across the universe.
curl "https://cryptodataapi.com/api/v1/volatility/index" \
-H "X-API-Key: cdk_live_your_key"
So a free key already has the gross scalar. The per-coin multiplier is the Pro part.
The sizing formula, end to end (Python)
Put the three together without double counting. The vol-target multiplier and gross scalar set the size; the ATR sets the stop; a risk budget then caps the size if the stop is too far.
import httpx
BASE = "https://cryptodataapi.com/api/v1"
H = {"X-API-Key": "cdk_live_your_key"}
def size_position(coin, equity_usd, base_fraction=0.10, stop_atr=2.0,
max_risk_fraction=0.01, horizon="24h"):
c = httpx.get(f"{BASE}/hyperliquid/candles",
params={"coin": coin, "interval": "4h", "limit": 200, "atr": 14},
headers=H, timeout=30).json()
bars = c["candles"]
if c.get("forming_bar_timestamp") is not None:
bars = bars[:-1] # completed bars only
last = bars[-1]
if last["atr"] is None:
return None # not enough bars for a converged ATR
atr, price = last["atr"], last["close"]
risk = httpx.get(f"{BASE}/quant/coins/risk", params={"horizon": horizon},
headers=H, timeout=30).json()
row = next((i for i in risk["items"] if i["symbol"] == coin), None)
if row is None or row["meta"]["insufficient_history"] or row["meta"]["new_listing"]:
return None # ineligible, do not size
vol_mult = row["vol_target_multiplier"] # 0.25 .. 3.0
vix = httpx.get(f"{BASE}/volatility/index", headers=H, timeout=30).json()
gross_mult = vix["gross_exposure_multiplier"] # 0.5 .. 1.0
notional = equity_usd * base_fraction * vol_mult * gross_mult
stop_distance = stop_atr * atr
units = notional / price
risk_at_stop = units * stop_distance
budget = equity_usd * max_risk_fraction
if risk_at_stop > budget: # shrink until the stop fits the budget
units = budget / stop_distance
notional = units * price
return {"coin": coin, "units": units, "notional_usd": notional,
"stop_distance": stop_distance, "atr": atr,
"vol_target_multiplier": vol_mult,
"gross_exposure_multiplier": gross_mult}
Read it top to bottom as the agent would. Equity times a base fraction is the "normal" size. The per-coin multiplier scales it for this coin's realized vol, the gross scalar for the market's. The ATR stop then asks whether losing to that stop would exceed one percent of equity, and if so the size shrinks to fit. Returning None is a deliberate output: no size is a valid answer when the inputs are missing.
ATR stop sizing vs vol targeting: what each one does
| ATR-based stop sizing | Vol-target multiplier | Gross exposure scalar | |
|---|---|---|---|
| Input | atr on /hyperliquid/candles?atr=14 | vol_target_multiplier on /quant/coins/risk | gross_exposure_multiplier on /volatility/index or /volatility/regime/score |
| Answers | Where is the stop, and how many units lose exactly my risk budget there? | Should this coin get a full, half or triple position relative to a 60% vol target? | Should the whole book be at full gross today? |
| Scope | One coin, one trade | One coin, standing scalar | Whole universe, one number |
| Range | Unbounded (depends on stop multiple) | 0.25 to 3.0, absolute | 0.5 to 1.0 |
| Fails when | You size from a forming bar or a null ATR | You read the 0.25 floor as "cheap" rather than "dangerous" | You apply it per coin as well as per book |
| Tier | Any key | Pro | Any key (index) / Pro Plus (score) |
Use all three, once each. The common bug is to let the agent apply a vol haircut to the base size and widen the stop and apply the gross scalar twice because two prompts mention it. Keep the formula in code, not in the prompt.
Five mistakes that show up in agent sizing logs
- Sizing from the forming bar. The last bar in a trailing pull is usually open. Its range is partial, so its
atris biased low and the stop lands too close. Checkforming_bar_timestamp. - Treating
nullas zero.atr: nullon early bars andrv_24h: nullon illiquid coins both mean "not computed". A zero ATR produces a division by zero or an infinite position. The null-is-not-zero post covers the same failure elsewhere in the API. - Reading the 0.25 floor as a bargain. A pinned multiplier means realized vol is at or above 240%. The
vol_pctile_30andregimefields are the shock gate; the multiplier is a cap, not a signal. - Fetching the full risk list once an hour per coin.
/quant/coins/riskreturns the whole universe in one call. Cache it per cycle and look coins up locally. - Ignoring fees in the stop. Hyperliquid taker fees come from
/hyperliquid/meta(fees.perps.taker). A stop at 2 ATR on a 1m chart can be inside one round trip of fees; use a bar size where ATR comfortably exceeds the fee.
How to use this in a bot (and when not to)
Use it as the last step of a trade decision, after direction and eligibility are settled. Pull candles with ATR on the execution timeframe, read the risk list once per cycle, read the volatility index once per cycle, and compute size in code. Log the four inputs (atr, vol_target_multiplier, gross_exposure_multiplier, equity) with every order so a bad size can be traced to a bad input.
Do not use it as a signal. A high multiplier is not a reason to buy; it says the coin is quiet. The 60% target is a universe-wide default, not a tuned parameter for your book. Replace base_fraction and stop_atr with your own values and keep the API numbers as inputs.
Know the limits. ATR on Hyperliquid candles is bounded by Hyperliquid's own retention, about 5,000 bars per interval. The risk list is Pro, and coins flagged insufficient_history or new_listing should get no size at all. Values are point-in-time: a coin's multiplier an hour ago is in /quant/history (Pro Plus), not in the live route.
For an MCP-connected agent the same fields arrive through the tools behind claude mcp add --transport http cryptodataapi https://cryptodataapi.com/mcp. The docs list the full response shapes, and pricing covers the Pro split.
Frequently asked questions
How does an AI trading agent size a crypto position?
Three observed numbers replace a guess: an ATR from /hyperliquid/candles?atr=14 sets the stop distance, vol_target_multiplier from /quant/coins/risk scales the base size for the coin's realized vol, and gross_exposure_multiplier from /volatility/index scales the whole book for market-wide vol stress. A risk budget then caps units so the loss at the stop stays within, for example, 1% of equity.
What is vol_target_multiplier and what range does it take?
It is 60 divided by the coin's annualized realized volatility, clamped to 0.25 to 3.0. A coin at 120% vol gets 0.5, a coin at 30% gets 2.0, and anything at or above 240% pins to the 0.25 floor. It is absolute, not relative to the coin's own history.
Does the API compute ATR for me?
Yes. Adding atr=14 (any period from 2 to 200) to /hyperliquid/candles returns a Wilder ATR on every bar as atr, null for the first N bars. forming_bar_timestamp tells you whether the last bar is still open so you can drop it.
Is gross_exposure_multiplier available on a free key?
Yes. /volatility/index serves composite_score, sentiment and gross_exposure_multiplier on every plan. The trimmed /volatility/regime/score route that adds target_vol and the regime aggregate is Pro Plus.



