# GET /v1/xrpl/metrics/amm-flow

XRPL AMM flow metric: how a pair's AMM pool reserves and LP token supply changed over a past-ledger window, that change split into liquidity and trades, the LP token yield over the window (invariant growth per LP token, impermanent loss and the result against holding), the LP supply drain over the last hour, and the pool's 7-day stored baseline.

## Purpose

Compares the AMM pool of a pair, read as `/v1/xrpl/amm` reads it, now and at the start of a past-ledger window. The body opens with `asset_a` and `asset_b`, the queried pool assets in the canonical form the route reads, each with its readable text for a 40-hex code. `a` and `b` are two distinct assets, XRP or `CODE.issuer` (an MPT issuance id answers 400 naming the field, and `a` equal to `b` answers 400 naming `b`); `reserves` and `flows` are keyed in that request order. `window` is `1h`, `24h` (the default), `7d` or `30d`; any other value answers 400 naming it, with no ledger read. The window ends at the latest validated ledger (`to_ledger`, read through the same cache entry as `/v1/xrpl/ledger/latest`) and starts at `from_ledger` = `to_ledger` minus the window's seconds divided by the average ledger close time of 3.9967 seconds (measured over 650,000 mainnet ledgers), rounded down to a multiple of 100 ledgers so that requests share one cached read; one `ledger` read and one `amm_info` read at `from_ledger` give its close time and the pool there, and `window_range.seconds` is the real number of seconds between `from_close_time` and `to_close_time` (ISO 8601 UTC). `now_ledger` is the ledger index of the current pool read (`amm_info`): any admitted upstream answers it at its own validated ledger, so it may differ from `to_ledger`. Reserves are in the units of `/v1/xrpl/amm` (XRP in XRP) and the LP supply in LP tokens, named by `lp_supply.currency`, the LP token code of the current pool read (as `/v1/xrpl/amm` `lp_token.currency` gives it), with its readable text `lp_supply.currency_ascii` (`null` for an AMM LP code, which starts with 0x03): each `change` = now − start, and `lp_supply.change_pct` = (now − start) / start × 100. Each reserve ends with `per_lp_token_change_pct` = (now / lp_supply.now) / (start / lp_supply.start) × 100 − 100, the change of one LP token's claim on that reserve (each LP token is a proportional share of the pool, XLS-30), `null` whenever `start` is and when the current pool is empty (LP supply 0), as `/v1/xrpl/amm` serves no per-LP-token value for an empty pool. `flows` splits each reserve change in two: `liquidity` = start × (lp_supply.now / lp_supply.start) − start, the change from LP tokens issued or redeemed, taken at the window-start proportions, and `trades` = now − start × (lp_supply.now / lp_supply.start), the rest (swaps, fees and single-asset imbalance); liquidity + trades = change holds exactly before rounding. The split assumes every LP token change over the window happened at the window-start proportions, so a deposit or withdrawal made later at other proportions leaves the difference in `trades`; an auction-slot bid burns LP tokens while the reserves stay, which shows as a withdrawal in `liquidity` plus an equal inflow in `trades`. `trading_fee_pct` is the trading fee of the current pool in percent (TradingFee / 1000, as `/v1/xrpl/amm` gives it) and `start_trading_fee_pct` the same at `from_ledger`, from the `amm_info` read there, `null` whenever the pool at `from_ledger` is (no pool, an empty pool or a start ledger not available from the pinned provider). `yield` gives a liquidity provider's figures over the window from the same two pool reads, with no extra read (XLS-30, weights 0.5), every square root exact to 40 places, never a float, and the pool's own price only, with no external price: `yield.lp_token_growth_pct` = g × 100, with g = (√(A_now × B_now) / LP_now) / (√(A_start × B_start) / LP_start) − 1, A and B the two reserves and LP the LP supply at `from_ledger` (start) and now, the growth of the pool invariant per LP token; `yield.lp_token_growth_annualized_pct` = g × 31536000 / window_range.seconds × 100, that growth over a 365-day year, simple (not compounded); `yield.impermanent_loss_pct` = (2√r / (1 + r) − 1) × 100, with r = (B/A)_now / (B/A)_start the change of the pool's own price, the value of a 50/50 constant-product position against holding its start reserves, 0 at an unchanged price and negative otherwise; and `yield.lp_vs_hold_pct` = ((1 + g) × 2√r / (1 + r) − 1) × 100, one LP token's claim now against holding its claim at `from_ledger`, valued at the pool's current price (the growth and the impermanent loss multiplied, not added). `yield.lp_token_growth_annualized_pct` is served only for a window of `24h`, `7d` or `30d` (a 24-hour minimum: a 1-hour sample scaled to a year is noise); with `window=1h` it is `null` with `annualization_window_too_short`. Ledger close times are rounded to their `close_time_resolution` (10 seconds or more), so `window_range.seconds`, and with it the annualized figure, can be off by up to `yield.close_time_error_ratio` = the larger `close_time_resolution` of the two `ledger` headers the window already reads (at `from_ledger` and `to_ledger`, no extra read) / window_range.seconds, a fraction, `null` whenever the annualized figure is. When the `close_flags` of either header carry the no-consensus close time flag (0x01), that close time is not agreed, so `yield.lp_token_growth_annualized_pct` and `yield.close_time_error_ratio` are `null` with `close_time_no_consensus`, while the other `yield` figures are still served; these two reasons arise only when the yield is otherwise served. Every `yield` figure is `null` when `window_range` is, without a pool at `from_ledger` (an empty one counts as none) and when the current pool is empty (LP supply 0). `drain.lp_supply_change_1h_pct` = (LP supply now − LP supply 1 hour back) / LP supply 1 hour back × 100, from one more `ledger` and `amm_info` read 1 hour (3600 seconds) back, bucketed the same way, whatever the window (with `window=1h` it is the window start itself), and `drain.band` is `severe` for a drop of at least 15 %, `draining` for a drop of at least 5 %, else `normal` (an increase too). `drain.window_range` is the drain's own past-ledger window, in the shape of `window_range`, from that read 1 hour back to `to_ledger`; as its start is rounded down, its `seconds` are the real lookback of the drain (60 to about 67 minutes). A pair with no pool now answers 404 `not-found`, with no past read. Without a pool at `from_ledger`, or with an empty one there (LP supply 0), every `start` and `change`, every `per_lp_token_change_pct`, `lp_supply.change_pct`, `flows`, `start_trading_fee_pct` and every `yield` figure are `null` with `no_pool_at_window_start`; without a pool 1 hour back, or with an empty one there, `drain` is `null` with no reason of its own. When the ledger at the window start is not available from the pinned provider (the past read answers `lgrNotFound` or `lgrIdxsInvalid`: outside its `complete_ledgers` or in a gap inside them), `window_range` and every figure that needs it are `null` with `beyond_history`; `drain` keeps its own read and is `null` with `beyond_history` only when the ledger 1 hour back is not available either. The pool is reported as read, frozen or not. `baseline` compares the current pool with its stored 7-day series, which the service records every 15 minutes from one dedicated upstream for the registry stablecoins paired with XRP and with each other: the figures `reserve_a`, `reserve_b`, `lp_supply` and `trading_fee_pct` (the pool trading fee in percent, the stored fraction × 100, exact), with `reserve_a` and `reserve_b` in the canonical pair order of `/v1/xrpl/amm` whatever the request order (XRP/RLUSD puts RLUSD first), each with its stored `points` in the window of the 672 15-minute slots ending at the latest recorded slot, `gaps` (672 − points, the slots with no stored point), `median`, `mean` and `stddev` (the mean and the population standard deviation of the stored values, over the stored points), `live` and `zscore` = (live − mean) / population standard deviation of the stored values, rounded half-up to 2 decimals (`null` when that deviation is 0), where `live` is the same figure of the current pool, then `robust_zscore`, the modified z-score 0.6745 × (live − median) / MAD, where MAD is the median absolute deviation of the stored values from their median (each median the mean of the two middle values for an even count), from the stored median and MAD (at most 18 decimals, half-up) and rounded half-up to 2 decimals: an absolute value above 3.5 flags an outlier (NIST/SEMATECH e-Handbook 1.3.5.17), and it is `null` when the MAD is 0, and `truncated_points`, `null` for every figure here (it counts truncated book pages, which a pool figure does not read); the `median`, `mean`, `stddev` and `live` of `trading_fee_pct` are in percent, and its `zscore` and `robust_zscore` are the same as over the stored fractions. A figure with fewer than 288 stored slots (3 days) is warming up: its `median`, `mean`, `stddev`, `zscore` and `robust_zscore` are `null`, its `live` is still served, and `reasons` contains `warming_up`; `baseline` is `null` while every figure warms up. Any other pair has `baseline: null` with `not_tracked`, and a stored series that cannot be read gives `baseline: null` with `baseline_unavailable`; the other figures are still served. `reasons` lists `beyond_history`, `no_pool_at_window_start`, `close_time_no_consensus`, `annualization_window_too_short`, `warming_up`, `not_tracked` and `baseline_unavailable` in that order and is empty when every figure is computed. The past reads are pinned to that upstream and never fail over to another; another failure of a past read, with no last good answer left, fails the answer (503 `upstream-unavailable`). `meta` describes the current reads only, the latest ledger and the current pool; the past reads are reported in `window_range` and `drain.window_range`, the ledger of the current pool read in `now_ledger`, and the stored series in `baseline`. A past ledger never changes, so its reads are cached for 86400 seconds; the 7-day summary of the stored series is computed once per 15-minute slot, from the 672 slots ending at the latest recorded slot, and cached until that slot ends (a request made before the current slot is recorded gets the previous slot's summary). The changes, the split, the yield figures, the drain band and the z-scores are defined computations over the ledger and the stored series, not advice. Reserves and LP supplies are decimal strings as `/v1/xrpl/amm` gives them and their changes are exact decimal strings; `change_pct`, `per_lp_token_change_pct`, flows, the `yield` figures, `lp_supply_change_1h_pct` and medians are decimal strings of at most 18 decimals, rounded half-up, the trading fees exact decimal strings, and z-scores decimal strings rounded half-up to 2 decimals; ledger indexes, `now_ledger` among them, and the `seconds` of both windows are integers. An answer is fresh for 4 seconds, the policy of its latest-ledger read, the shorter of its two current reads. The example is computed from recorded mainnet reads of that upstream: the latest validated ledger 108267510 and the XRP/RLUSD pool of the same moment, and the start 108266600 of its `1h` window, also the 1-hour drain read, with no annualized yield on that `1h` window (`annualization_window_too_short`) and the stored baseline still warming up.

## When to use

To see how an XRPL AMM pool changed over the last hour, day, week or month: how much of each reserve change came from liquidity added or withdrawn at the pool's proportions and how much from trades, how much an LP token grew, its impermanent loss and its result against holding, and whether its LP token supply fell over the last hour.

## When not to use

To read a pool's current reserves, trading fee and spot prices (use `/v1/xrpl/amm/{a}/{b}`), or the cost of a trade against it (use `/v1/xrpl/slippage`).

## Parameters

| Name | In | Required | Description | Constraints | Example |
|---|---|---|---|---|---|
| `a` | query | yes | First asset of the pool. `XRP`, or `CODE.issuer`: `CODE` is a 3-character standard code or 40 hexadecimal digits, and `issuer` is a classic XRPL address. Standard codes are case-sensitive: `usd` and `USD` are different tokens, so send the exact code. A standard code uses letters, digits or `?!@#$%^&*<>(){}[]\|` and is never `XRP`; percent-encode the symbols in a URL (for example `%3F` for `?`). A 40-hex code is read in any case, and the 40-hex form of a standard code means that code. | `XRP`, or `CODE.issuer`: `CODE` is a 3-character standard code or 40 hexadecimal digits, and `issuer` is a classic XRPL address. Standard codes are case-sensitive: `usd` and `USD` are different tokens, so send the exact code. A standard code uses letters, digits or `?!@#$%^&*<>(){}[]\|` and is never `XRP`; percent-encode the symbols in a URL (for example `%3F` for `?`). A 40-hex code is read in any case, and the 40-hex form of a standard code means that code. | `XRP` |
| `b` | query | yes | Second asset of the pool, different from a. `XRP`, or `CODE.issuer`: `CODE` is a 3-character standard code or 40 hexadecimal digits, and `issuer` is a classic XRPL address. Standard codes are case-sensitive: `usd` and `USD` are different tokens, so send the exact code. A standard code uses letters, digits or `?!@#$%^&*<>(){}[]\|` and is never `XRP`; percent-encode the symbols in a URL (for example `%3F` for `?`). A 40-hex code is read in any case, and the 40-hex form of a standard code means that code. | `XRP`, or `CODE.issuer`: `CODE` is a 3-character standard code or 40 hexadecimal digits, and `issuer` is a classic XRPL address. Standard codes are case-sensitive: `usd` and `USD` are different tokens, so send the exact code. A standard code uses letters, digits or `?!@#$%^&*<>(){}[]\|` and is never `XRP`; percent-encode the symbols in a URL (for example `%3F` for `?`). A 40-hex code is read in any case, and the 40-hex form of a standard code means that code. | `524C555344000000000000000000000000000000.rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De` |
| `window` | query | no | Window back from the latest validated ledger: 1h, 24h, 7d or 30d (default 24h). | One of 1h, 24h, 7d or 30d; any other value is rejected with 400 | `1h` |

## Request example

```sh
curl -s "https://api.criptonlabs.com/v1/xrpl/metrics/amm-flow?a=XRP&b=524C555344000000000000000000000000000000.rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De&window=1h"
```

## Response example (200)

```json
{
  "asset_a": "XRP",
  "asset_b": "524C555344000000000000000000000000000000.rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De",
  "asset_b_currency_ascii": "RLUSD",
  "window_range": {
    "from_ledger": 108266600,
    "to_ledger": 108267510,
    "from_close_time": "2026-11-11T19:21:32.000Z",
    "to_close_time": "2026-11-11T20:22:51.000Z",
    "seconds": 3679
  },
  "now_ledger": 108267510,
  "reserves": {
    "a": {
      "start": "2008694.457538",
      "now": "2008813.180267",
      "change": "118.722729",
      "per_lp_token_change_pct": "0.005910442404740594"
    },
    "b": {
      "start": "2127715.674585221",
      "now": "2127602.29115091",
      "change": "-113.383434311",
      "per_lp_token_change_pct": "-0.005328880905720783"
    }
  },
  "lp_supply": {
    "currency": "03B245BE580EC4F4386A751C084489EC4B514A2F",
    "currency_ascii": null,
    "start": "1746725107.669615",
    "now": "1746725107.669615",
    "change": "0",
    "change_pct": "0"
  },
  "flows": {
    "a": {
      "liquidity": "0",
      "trades": "118.722729"
    },
    "b": {
      "liquidity": "0",
      "trades": "-113.383434311"
    }
  },
  "trading_fee_pct": "0.308",
  "start_trading_fee_pct": "0.308",
  "drain": {
    "lp_supply_change_1h_pct": "0",
    "band": "normal",
    "window_range": {
      "from_ledger": 108266600,
      "to_ledger": 108267510,
      "from_close_time": "2026-11-11T19:21:32.000Z",
      "to_close_time": "2026-11-11T20:22:51.000Z",
      "seconds": 3679
    }
  },
  "baseline": null,
  "yield": {
    "lp_token_growth_pct": "0.000290622846983335",
    "lp_token_growth_annualized_pct": null,
    "impermanent_loss_pct": "-0.000000157902067422",
    "lp_vs_hold_pct": "0.000290464944457013",
    "close_time_error_ratio": null
  },
  "reasons": [
    "annualization_window_too_short",
    "warming_up"
  ],
  "meta": {
    "ledger_index": 108267510,
    "ledger_state": "validated",
    "as_of": "2026-11-11T20:22:56.994Z",
    "age_seconds": 0,
    "cache": "miss",
    "stale": false
  }
}
```

## Errors

- 400 [invalid-parameters](https://api.criptonlabs.com/errors/invalid-parameters.md)
- 400 [bad-request](https://api.criptonlabs.com/errors/bad-request.md)
- 404 [not-found](https://api.criptonlabs.com/errors/not-found.md)
- 429 [rate-limited](https://api.criptonlabs.com/errors/rate-limited.md)
- 503 [upstream-unavailable](https://api.criptonlabs.com/errors/upstream-unavailable.md)

## Caching

Fresh for 4 seconds; on upstream failure the last good value is served for up to 60 seconds (`meta.stale` is `true`), then the service answers 503. See the [freshness guide](https://api.criptonlabs.com/docs/guides/freshness.md).

## Rate limit

Tier `expensive`. See the [rate-limits guide](https://api.criptonlabs.com/docs/guides/rate-limits.md).

## MCP tool

The MCP tool `xrpl_metrics_amm_flow` returns the same data. See the [MCP quickstart](https://api.criptonlabs.com/docs/guides/mcp-quickstart.md).
