User flows and examples / Quotes
Price vs quote
Maxy prices a swap with two calls, the way swap APIs split them. GET /price is for showing an amount while the user browses or types. GET /quote is for the order about to be placed: it names who pays and who receives, and comes with an id and an expiry. This page is for anyone building the screen between "how much?" and "confirm".
| Price | Quote | Order | |
|---|---|---|---|
| Call | GET /price | GET /quote | POST /orders |
| SDK | swap.price() | swap.quote() | swap.createOrder() |
| When | While the user browses or types | When the user moves to confirm | After the user signed |
| Needs | The pair, an amount, your key | Also fromAddress and toAddress | The quote's order and the signatures |
| Gives | toAmount, formatted | The same, plus quoteId, expiresAt, issues, steps | orderId, and the escrow transaction where the route has one |
| Id | None | quoteId, which becomes the order id | orderId, the signed intent's hash |
| Reserves anything | No | No | The escrow does, once it lands |
| Expiry | When to refresh | When POST /orders stops accepting it | The intent's own deadline |
Get a price
Call it as often as you like: the same question within 3 seconds is one read, and price reads have ten times the rate limit of other calls. It needs no wallet. BASE and KEY are as on Get a price.
curl -sG -H "x-maxy-key: $MAXY_API_KEY" "$BASE/price" --data-urlencode "from=ETH on base" -d to=BTC -d amount=0.004 | jq '{toAmount, formatted}'
Expiry: when to refresh, for a price. When POST /orders stops accepting it, for a quote.
A price answers at any size above the route's minimum (546 sats buying BTC; below it, 422 amount_out_of_range). liquidityAvailable: false, with a message, means no price can be made for that amount now. A price also carries expiresAt: on a price it marks when to refresh, and it reserves nothing.
Get a quote
Ask once, when the user moves to confirm. A quote is valid for 60 seconds: that is how long it can be used, not how long it takes to arrive. expiresAt is in Unix seconds, and expiresAtIso is the same moment. Count down against the Date header of Maxy's answer, not the device's clock, and quote again 5 seconds before it closes. The wallet and the Bitcoin address are as on Get a quote.
curl -s -D headers.txt -G "$BASE/quote" -H "x-maxy-key: $MAXY_API_KEY" --data-urlencode "from=ETH on base" -d to=BTC -d amount=0.004 \ -d fromAddress="$WALLET" -d toAddress="$MY_BTC_ADDRESS" > quote.json jq '{quoteId, toAmount, expiresAt}' quote.json grep -i '^date:' headers.txt
Count down against the date header's clock, not the device's.
const q = new URLSearchParams({ from: 'ETH on base', to: 'BTC', amount: '0.004', fromAddress: account.address, toAddress: btcAddress }); const res = await fetch(`${BASE}/quote?${q}`, { headers: { 'x-maxy-key': KEY } }); const quote = await res.json(); const skew = Date.parse(res.headers.get('date')!) - Date.now(); // the server's clock, not the device's const secondsLeft = () => Math.floor((quote.expiresAt * 1000 - (Date.now() + skew)) / 1000); console.log(quote.quoteId, quote.toAmount, secondsLeft()); // quote again when it falls under 5
On a settler route the quote's amounts are executable: toAmountMin equals toAmount; a route ending in a swap or bridge leg quotes a lower toAmountMin, the leg's slippage allowance. It also carries what the order needs: steps to sign and send, and issues for what is short (balance, allowance, orderCap). Over your key's cap the amounts still show, and steps is null. React's useQuote gives secondsLeft for you.
When it runs out
An order from a quote older than 60 seconds is refused before anything is sent: 409 quote_expired, with a fresh quote in details.freshQuote. Show the new amount and ask the user to sign again. Once signed, the order has its own deadlines: a solver must commit within 2 hours of the quote.
| Code | HTTP | Cause | Do |
|---|---|---|---|
quote_expired | 409 | Over 60 seconds since the quote | Quote again, sign again |
quote_mismatch | 409 | The escrow would lock more than the quote and its price band allow | Quote again |
invalid_input | 400 | A quote without fromAddress or toAddress | Send both, or use /price |
Which key
Both calls take your key. A secret key works from your server. A publishable key (mxk_pk_…) works from a browser page, on the origins Maxy issued it for: it can get prices, quotes and status, and place the user's own signed order, but not list orders, register webhooks or manage keys. From a server, use the secret key: Keys and limits.
Many at once
POST /quotes/batch takes up to 20 requests. A request that names both addresses is a quote; the others are prices. Each result has its own status, so one failing does not fail the rest.
curl -s -X POST "$BASE/quotes/batch" -H "x-maxy-key: $MAXY_API_KEY" -H "content-type: application/json" \ -d '{"requests":[{"from":"ETH on base","to":"BTC","amount":"0.004"},{"from":"USDC on base","to":"BTC","amount":"10"}]}' \ | jq -c '.results[] | {index, status, toAmount: .quote.toAmount}'
Next, the wallet signs the quote's steps: Sign. What is inside the amount: Fees and pricing.