Skip to content

Fetch Prices

Ryze runs a price proxy that serves the execution prices used by the protocol. Use it to get the same blended Pyth + CEX prices that power swap quotes.

Price Proxy URLs

EnvironmentURL
Mainnethttps://mainnet.proxy.ryze.pro
Testnethttps://sepolia.proxy.ryze.pro

The proxy is a drop-in replacement for hermes.pyth.network with the same SSE and REST interface, but returns the blended execution prices Ryze actually uses.

One-Shot: Latest Prices

Fetch the most recent prices in a single request:

bash
curl "https://mainnet.proxy.ryze.pro/v2/updates/price/latest?ids[]=ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace&ids[]=eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a"
json
{
  "parsed": [
    {
      "id": "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
      "price": {
        "price": "160025000000",
        "conf": "0",
        "expo": -8,
        "publish_time": 1713200000
      },
      "ema_price": { ... },
      "blend": {
        "token": "0x4200000000000000000000000000000000000006",
        "pythPrice": "1600250000000000000000",
        "cexPrice": "1600300000000000000000",
        "blendFactor": "500000000000000000",
        "blendedPrice": "1600275000000000000000"
      }
    }
  ]
}

TIP

Call /v2/updates/price/latest without any ids[] to get all cached prices at once.

Streaming: SSE Price Feed

For real-time updates (~200ms cadence), connect to the SSE stream:

javascript
const feedIds = [
  'ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace', // ETH/USD
  'eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a', // USDC/USD
  '2817d7bfe5c64b8ebd8cb2cb5f4f59c640453faa953a0f2f8067e0e83f4db8c9', // cbBTC/USD
];

const params = feedIds.map(id => `ids[]=${id}`).join('&');
const url = `https://mainnet.proxy.ryze.pro/v2/updates/price/stream?${params}`;

const eventSource = new EventSource(url);

eventSource.onmessage = (event) => {
  const data = JSON.parse(event.data);

  for (const update of data.parsed) {
    // Standard Pyth price
    const price = Number(update.price.price) * Math.pow(10, update.price.expo);
    console.log(`${update.id.slice(0, 8)}...: $${price.toFixed(2)}`);

    // Blended execution price (WAD format, 1e18 = $1)
    if (update.blend) {
      const execPrice = Number(BigInt(update.blend.blendedPrice)) / 1e18;
      console.log(`  Execution price: $${execPrice.toFixed(2)}`);
    }
  }
};

The stream sends cached prices immediately on connect, then pushes live updates. EventSource auto-reconnects on network errors.

For the best UX, fetch prices via REST first (instant display), then switch to SSE for live updates:

javascript
async function initPrices(feedIds) {
  // 1. Seed from REST (instant)
  const params = feedIds.map(id => `ids[]=${id}`).join('&');
  const res = await fetch(
    `https://mainnet.proxy.ryze.pro/v2/updates/price/latest?${params}`
  );
  const data = await res.json();

  const prices = {};
  for (const update of data.parsed) {
    prices[update.id] = Number(update.price.price) * Math.pow(10, update.price.expo);
  }

  // 2. Connect SSE for live updates
  const es = new EventSource(
    `https://mainnet.proxy.ryze.pro/v2/updates/price/stream?${params}`
  );
  es.onmessage = (event) => {
    const data = JSON.parse(event.data);
    for (const update of data.parsed) {
      prices[update.id] = Number(update.price.price) * Math.pow(10, update.price.expo);
    }
  };

  return { prices, eventSource: es };
}

Feed IDs

Get feed IDs from the assets endpoint. Each token includes pythFeedId:

TokenPyth Feed ID
ETH/USDff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace
USDC/USDeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a
cbBTC/USD2817d7bfe5c64b8ebd8cb2cb5f4f59c640453faa953a0f2f8067e0e83f4db8c9

Price Conversion

javascript
// Pyth raw format to USD
const raw = "160025000000";
const expo = -8;
const usd = Number(BigInt(raw)) * Math.pow(10, expo);
// = 1600.25

// WAD format (blend fields) to USD
const wad = "1600275000000000000000";
const usdFromWad = Number(BigInt(wad)) / 1e18;
// = 1600.275

// Token amount to USD value
const wethAmount = BigInt("62500000000000000"); // 0.0625 WETH
const wethPriceWad = BigInt("1600000000000000000000");
const valueUsd = Number(wethAmount * wethPriceWad / BigInt(1e18)) / 1e18;
// = 100.0 USD

Blended Price Formula

The proxy blends Pyth and CEX prices using a per-token blend factor:

blendedPrice = pythPrice + (cexPrice - pythPrice) * blendFactor / 1e18
  • blendFactor = 0 -- pure Pyth price
  • blendFactor = 5e17 -- 50/50 blend
  • blendFactor = 1e18 -- pure CEX price

The blended price is what the Router uses for all swap calculations.