Relatick
Reference

Find best route

POST /public/v1/evm/{chain_id}/route

Compare shortlisted direct and one-intermediate-hop paths for an exact-input or exact-output swap. The router can split a fixed input across paths to return more output, or split a fixed output target to spend less input. A validated split can also fill an order when no single route can complete it.

This is a public endpoint. A Trading API key is optional; sending one raises your rate limit:

Authorization: Bearer <your_trading_api_key>

A key you send must be valid: an unknown key returns 401. Leave the header out if you don't have one.

Path parameters

Name
Type
Description
chain_id
integer
Numeric EVM chain id.

Request body

Field
Type
Required
Description
tokenIn
string
yes
Input token address. Must differ from tokenOut, non-zero.
tokenOut
string
yes
Output token address.
tradeType
string
no
exact_in or exact_out. Inferred when omitted: amountIn alone ⇒ exact_in, amountOut alone ⇒ exact_out. Required if you send both amounts.
amountIn
string
for exact_in
Exact input, raw units (base-10, positive).
amountOut
string
for exact_out
Exact output target, raw units.
maxRoutes
integer
no
Cap on routes in the plan, from 1 to 4; 0 is treated as 1 and larger values as 4. 1 = single best route (no split); omitted = 4.
poolAddress
string
no
Restrict routing to this one Relatick pool. Its tokens must match tokenIn/tokenOut; a success returns one direct route through it.

Request

# Route (exact-in) - single & split, one endpoint
curl -X POST "https://api.metric.xyz/public/v1/evm/1/route" \
  -H "Content-Type: application/json" \
  -d '{
    "tokenIn":  "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
    "tokenOut": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
    "tradeType": "exact_in",
    "amountIn": "50000000000000000",
    "maxRoutes": 4
  }'

Response

200 OK

{
  "tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
  "tokenOut": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
  "tradeType": "exact_in",
  "amountIn": "50000000000000000",
  "amountOut": "136120897",
  "effectivePriceX64": "50219747000",
  "priceImpactBestRoute": "0.000082",
  "candidatesConsidered": 8,
  "routes": [
    {
      "tradeType": "exact_in",
      "routeType": "direct",
      "amountIn": "50000000000000000",
      "amountOut": "136120897",
      "effectivePriceX64": "50219747000",
      "priceImpactE6": "82",
      "legs": [
        {
          "tradeType": "exact_in",
          "poolAddress": "0xF85AfbADeCC7F23Dd173ed706f07d9C7e2473e24",
          "pair": "WETH/USDC",
          "zeroForOne": true,
          "tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
          "tokenOut": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
          "amountIn": "50000000000000000",
          "amountOut": "136120897",
          "effectivePriceX64": "50219747000",
          "priceImpactE6": "82",
          "priceLimitX64": "0"
        }
      ]
    }
  ]
}
Field
Type
Description
tokenIn / tokenOut
string
Echoed endpoints (lowercased).
tradeType
string
Echoed; tells you which side was fixed.
amountIn
string
For exact_in, the request; for exact_out, the computed required input.
amountOut
string
For exact_in, the total computed output. For exact_out, the requested output.
effectivePriceX64
string
Blended execution price for the whole plan: amountOut × 2^64 / amountIn, in raw token units (see below).
priceImpactBestRoute
string
Price impact of the best single quote or the full-size single-route estimate used for split planning. If neither exists, this is the highest impact among the routes in the simulated split. A decimal fraction ("0.0135" = 1.35%).
candidatesConsidered
integer
Number of candidate paths selected for consideration before fetching depth.
routes
array
One entry per allocated route (≥1; multiple ⇒ split).

effectivePriceX64 is output per input, in the trade's direction (tokenOut per tokenIn), scaled by 2^64. It is not decimal-normalized, unlike bidAdj/askAdj. To get a human-readable price, compute effectivePriceX64 / 2^64 × 10^(tokenIn decimals − tokenOut decimals). In the example, 50219747000 / 2^64 ≈ 2.72e-9 USDC base units per wei, so × 10^(18 − 6) gives ≈ 2,722 USDC per WETH.

Response fields

Each routes[] entry

Field
Type
Description
tradeType
string
Echoed.
routeType
string
direct or one_hop.
amountIn / amountOut
string
Amounts allocated to this route (raw units).
effectivePriceX64
string
This route's execution price, same format.
priceImpactE6
string
The largest priceImpactE6 among this route's legs, E6 (10000 = 1%).
legs
array
Per-leg execution params.

Each leg

Field
Type
Description
tradeType
string
Echoed.
poolAddress
string
Pool to swap against.
pair
string
Pool pair label.
zeroForOne
boolean
Swap direction for this leg.
tokenIn / tokenOut
string
Leg tokens. For one-hop, leg 2 amountIn = leg 1 amountOut.
amountIn / amountOut
string
Leg amounts (raw units).
effectivePriceX64
string
Leg execution price, same format.
priceImpactE6
string
Leg price impact in E6 from the published level of the last bin reached. A partially available bin uses its published cutoff. Use effectivePriceX64 for the average.
priceLimitX64
string
No-limit sentinel for the onchain swap: 0 when zeroForOne, 2^128−1 otherwise.

Routing and splitting

These details are internal and not returned in the response.

  1. 1.Rank direct and one-hop paths using bid/ask depth. Use the same pool snapshot to price the finalists in the swap engine when it is available. Plans with snapshots for every leg take priority when they can fill the order. The router can fall back to depth estimates for older cache entries.
  2. 2.Use the best single quote in the group as the split reference. If no single can fill, use a full-size depth estimate from that group when one exists. A reference below the split threshold prevents splitting in that group.
  3. 3.Use marginal prices to plan a split within the configured limits and reprice its legs. For each simulated leg, the last traded bin and any output in a partially available bin must fit within the published depth.
  4. 4.Return a split when it improves the single quote. A split with snapshots for every leg can also fill an order when no full-size single-route reference exists.

Errors

Status
Meaning
400
Invalid body, tokenIn == tokenOut, zero address, non-positive amount, missing amountIn/amountOut for the tradeType, or both amounts sent without a tradeType.
401
Invalid API key: an Authorization header was sent with an unknown key.
404
Unknown chainId: <id>: the chain is not served by the API.
422
no_route (no eligible direct/one-hop path), insufficient_liquidity (no candidate had enough depth), or token_disabled (tokenIn or tokenOut is disabled by Relatick).
429
Rate limited. A valid key gets a higher limit. Wait for the time in Retry-After.
500
Internal error loading pool data. Retry.
502
An upstream data source failed. Retry.
503
Routing exceeded the 5s deadline.

A 422 body carries a machine-readable code:

{
  "code": "insufficient_liquidity",
  "error": "no candidate route had enough depth to fill the requested amount"
}

Last updated 29 days ago