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:

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:

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:

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:

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 sizingVol-target multiplierGross exposure scalar
Inputatr on /hyperliquid/candles?atr=14vol_target_multiplier on /quant/coins/riskgross_exposure_multiplier on /volatility/index or /volatility/regime/score
AnswersWhere 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?
ScopeOne coin, one tradeOne coin, standing scalarWhole universe, one number
RangeUnbounded (depends on stop multiple)0.25 to 3.0, absolute0.5 to 1.0
Fails whenYou size from a forming bar or a null ATRYou read the 0.25 floor as "cheap" rather than "dangerous"You apply it per coin as well as per book
TierAny keyProAny 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

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.