← Cookbook

⚠️ partial

Recipe 16 — Bulk price lookups in a pipeline

Status: ⚠️ partial What ships Day-0: sequential client.swap.quote(...) loop What's deferred: POST /v1/swap/quotes:batch endpoint (M6+)

There's no batch endpoint Day-0. Use a bounded-concurrency loop over the single-quote endpoint. Watch your rate-limit tier (Free=10 RPS, Pro=60 RPS; TZ-3 §26.7) and configure client_config.max_retries=0 if you'd rather fail fast than queue behind 429 retries.

import asyncio

async def quote_pair(client, pair):
    return await client.swap.quote(
        from_chain=1, to_chain=1,
        from_token=pair[0], to_token=pair[1],
        from_amount="1000000",
    )

pairs = [(USDC, USDT), (USDC, DAI), (WETH, USDC)]
sem = asyncio.Semaphore(5)  # cap concurrency at 5 to fit Pro RPS budget
async def bounded(pair):
    async with sem:
        return await quote_pair(client, pair)
quotes = await asyncio.gather(*[bounded(p) for p in pairs])
const pairs = [
  [USDC, USDT],
  [USDC, DAI],
  [WETH, USDC],
];
const concurrency = 5;
const queue = [...pairs];
const out: SwapQuote[] = [];
await Promise.all(
  Array.from({ length: concurrency }, async () => {
    while (queue.length > 0) {
      const pair = queue.shift()!;
      out.push(
        await client.swap.quote({
          from_chain: 1,
          to_chain: 1,
          from_token: pair[0],
          to_token: pair[1],
          from_amount: '1000000',
        }),
      );
    }
  }),
);

When the batch endpoint ships in M6+, the SDK will gain client.swap.quotes_batch(pairs=[...]) returning a single response.

Source: cookbook/recipes/16-bulk-price-lookups/README.md