> For the complete documentation index, see [llms.txt](https://docs.metric.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.metric.xyz/integrate/integrate-metric-liquidity/via-api.md).

# Via API

## 1. Discover Available Pools

Query the [metadata endpoint](/reference/api/metadata.md) to retrieve:

* Supported trading pairs
* Pool addresses
* Quoter and token addresses

Route only to pools whose `priceProviderStatus` is `healthy` and whose `pauseLevel` is `0`.

***

## 2. Fetch Current Bid / Ask and Depth

Request the current [bid and ask prices](/reference/api/retrieve-batch-bid-and-ask.md) for up to 100 pools on one chain in a single `POST /public/v1/evm/{chain_id}/bid_ask/batch` call. No key is needed; a Trading API key raises the rate limit.

* Each pool gets the same quote as the single-pool [bid / ask endpoint](/reference/api/retrieve-current-bid-and-ask.md), or an `error` if that pool can't be quoted
* Depth is returned in addition to prices (pass `"depth": false` to skip it). Use it to [estimate what an order fills for](/reference/api/retrieve-current-bid-and-ask.md#estimating-a-fill)
* Returned prices are already normalized for use with Metric’s contracts

Check each side's price, not only `priceProviderStatus`: a pool can refuse one direction while staying `healthy`, and that side then carries the [unavailable sentinel](/reference/api/retrieve-current-bid-and-ask.md#unavailable-prices). This check needs depth, so keep it on if you rely on it.

***

## 3. Size the Trade

Pick one:

* **Your own routing:** walk each pool's depth for your order size, as described in [Estimating a fill](/reference/api/retrieve-current-bid-and-ask.md#estimating-a-fill).
* **Metric's routing:** call [Find best route](/reference/api/find-best-route.md). It runs the same depth walk across direct and one-hop paths and can split the order. Pass `poolAddress` to size the trade against a single pool.

Both give the same amounts for the same depth snapshot.

***

## 4. Execute the Trade

Use the [Router's](/reference/smart-contracts/swapping-via-router.md) `exactInput*` / `exactOutput*` entrypoints, or call [`swap` on the pool](/reference/smart-contracts/swapping-directly-via-pool.md).

* Supports both **exact-input** and **exact-output** swaps
* Uses the same [Q64 price format](/reference/glossary.md#price-formats-and-units) for bid, ask, and price limits
* [Price limits](/reference/glossary.md#pricelimitx64) protect execution against excessive slippage

Depth is an estimate. Set your protection from it:

* **Exact input:** `amountOutMinimum = estimatedOut × (1 − slippageTolerance)`
* **Exact output:** `amountInMaximum = estimatedIn × (1 + slippageTolerance)`

For the exact amount, quote with `MetricOmmSwapQuoter` before sending. Pools with extensions can refuse a trade that depth shows as fillable. To catch this, simulate the transaction with your real `from` address (see [Why a swap reverts](/integrate/integrate-metric-liquidity.md#why-a-swap-reverts)).

***

On Ethereum, where to send the transaction matters; see [Freshness and ordering](/how-pools-work/freshness-and-ordering.md#for-integrators).
