Get API key
Real-time prices

Stream price updates

wswss://pyth-lazer-0.dourolabs.app/v1/stream

An API key or short-lived access token, in one of the three locations under Authorization.

Receive price updates over a WebSocket connection. Send a subscribe message to select feeds, properties, and an update channel. By default, the server sends updates as JSON streamUpdated messages at the channel's update frequency.

For a single update: Get latest prices →

wsv1/stream
import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";

const token = process.env.PYTH_API_KEY;
if (!token) {
  throw new Error("Set PYTH_API_KEY to your API key.");
}

const client = await PythLazerClient.create({
  token,
  webSocketPoolConfig: {
    urls: [
      "wss://pyth-lazer-0.dourolabs.app/v1/stream",
      "wss://pyth-lazer-1.dourolabs.app/v1/stream",
      "wss://pyth-lazer-2.dourolabs.app/v1/stream",
    ],
  },
});

client.addMessageListener((message) => {
  console.log(message);
});

client.subscribe({
  type: "subscribe",
  subscriptionId: 1,
  channel: "fixed_rate@200ms",
  formats: ["solana"],
  properties: ["price", "exponent"],
  priceFeedIds: [1, 2],
});
Example session
↑ sent↓ received
  1. sent
    {
      "type": "subscribe",
      "subscriptionId": 1,
      "channel": "fixed_rate@200ms",
      "formats": ["solana"],
      "properties": ["price", "exponent"],
      "priceFeedIds": [1, 2]
    }
  2. received
    { "subscriptionId": 1, "type": "subscribed" }
  3. received
    {
      "type": "streamUpdated",
      "subscriptionId": 1,
      "parsed": {
        "priceFeeds": [
          {
            "priceFeedId": 1,
            "exponent": -8,
            "price": "11294021500000"
          },
          {
            "priceFeedId": 2,
            "exponent": -8,
            "price": "418733750000"
          }
        ],
        "timestampUs": "1758830400200000"
      },
      "solana": { "data": "uQEagvZh…", "encoding": "base64" }
    }

Endpoints

The endpoints below provide the same stream API. Connect to all of them, so the stream continues when one is unavailable. The JavaScript SDK connects to all of them by default and removes duplicate updates. The server closes every connection after 24 hours, without an error message.

Connect to all 3 endpoints.

  • wss://pyth-lazer-0.dourolabs.app/v1/stream
  • wss://pyth-lazer-1.dourolabs.app/v1/stream
  • wss://pyth-lazer-2.dourolabs.app/v1/stream

Authorization

Authenticate with an API key or a short-lived access token. The server checks the following locations in order.

Authorization

Set the header to Bearer <token>. If the header is malformed, the server returns HTTP 400 without checking the remaining locations.

Sec-WebSocket-Protocol

Browser WebSocket clients cannot set the Authorization header. Pass pyth-lazer-auth followed by the token as subprotocols: new WebSocket(url, ["pyth-lazer-auth", token]).

ACCESS_TOKEN

Pass the token as a URL query parameter only when neither method above is possible. URLs can appear in logs.

Message flow

Send subscribe to start receiving updates. Send unsubscribe with the same subscriptionId to stop that subscription.

ClientServer
  1. Client sends subscribe
  2. Server sends subscribed
  3. Server sends streamUpdated at the channel's update frequency
  4. Client sends unsubscribe
  5. Server sends unsubscribed
One WebSocket connection can support multiple subscriptions. Messages about a subscription include its subscriptionId. General error messages do not include this field.

The Playground sends subscribe to the live service and shows each server message. It works without an API key.

Client messages

Send client messages as JSON text frames.

"type": "subscribe"

Starts a subscription for the selected feeds and channel.

channelRequired

The channel that determines the update frequency.

  • real_time
  • fixed_rate@50ms
  • fixed_rate@200ms
  • fixed_rate@1000ms
formatsRequired

Payload formats to include in each update, with no duplicates. An empty array requests no binary payloads.

  • evm
  • solana
  • leEcdsa
  • leUnsigned
propertiesRequired

Feed properties to include in each update. Specify at least one property. Duplicate values are not allowed.

  • price
  • bestBidPrice
  • bestAskPrice
  • publisherCount
  • exponent
  • confidence
  • fundingRate
  • fundingTimestamp
  • fundingRateInterval
  • marketSession
  • emaPrice
  • emaConfidence
  • feedUpdateTimestamp
subscriptionIdintegerRequired

Client-assigned integer that identifies the subscription. Must be unique among active subscriptions on the connection. An ID can be reused after its unsubscribed reply.

Feedsone of the 2Required

Provide either priceFeedIds or symbols, but not both. Use numeric IDs, such as 1 for BTC/USD, or symbols, such as Crypto.BTC/USD. The array must contain at least one entry and no duplicates.

Select feeds by pyth_lazer_id in priceFeedIds, not by symbol. Feed symbols can change when we correct symbology, and a symbol may later point to a different asset. A pyth_lazer_id never changes.

priceFeedIdsinteger[] | null
symbolsstring[] | null
deliveryFormatstringDefault json

Use json to receive streamUpdated messages or binary to receive binary frames.

  • jsondefault
  • binary
ignoreInvalidFeedsbooleanDefault false

If true, skips invalid feeds and subscribes to the remaining feeds. The server responds with subscribedWithInvalidFeedIdsIgnored. If false, any invalid feed causes a subscriptionError.

jsonBinaryEncodingstringDefault base64

Encoding to use for binary payloads in JSON updates. This option does not apply when deliveryFormat is binary.

  • base64default
  • hex
parsedbooleanDefault true

If true, includes decoded update values in the parsed response field.

"type": "unsubscribe"

Stops the subscription identified by subscriptionId.

subscriptionIdintegerRequired

The ID of the subscription to stop.

Server messages

For JSON delivery, each server message includes a type field that identifies the message type. Binary price updates use binary frames.

"type": "error"

The server sends this message if it cannot parse a client message or encounters an internal error while processing a subscription. Parsing can fail because of invalid JSON, missing fields, or unrecognized values. The message does not include a subscriptionId. The connection stays open, except after client too slow: the server sends that error when the client reads updates too slowly, then closes the connection.

errorstring

A description of the error.

"type": "subscribed"

Confirms that the subscription is active and all requested feeds are valid. The server sends this message when ignoreInvalidFeeds is false (the default).

subscriptionIdinteger

The ID of the subscription associated with this message.

"type": "subscribedWithInvalidFeedIdsIgnored"

Confirms that the subscription is active. Lists subscribed feeds and groups skipped feeds by reason. The server sends this message when ignoreInvalidFeeds is true, even when no feeds are skipped.

ignoredInvalidFeedIdsobject

Feeds excluded from the subscription, grouped by reason.

unknownIdsinteger[]

Feed IDs that the server does not recognize.

unknownSymbolsstring[]

Feed symbols that the server does not recognize.

unstableinteger[]

IDs of feeds marked unstable and unavailable for subscription.

unsupportedChannelsinteger[]

IDs of feeds that do not support the requested channel.

notEntitledinteger[]

IDs of feeds that the credentials cannot access.

subscribedFeedIdsinteger[]

IDs of feeds included in the subscription.

subscriptionIdinteger

The ID of the subscription associated with this message.

"type": "unsubscribed"

Confirms that the subscription has ended. The server sends no further updates for this subscription.

subscriptionIdinteger

The ID of the subscription associated with this message.

"type": "subscriptionError"

Reports a failed subscribe or unsubscribe. Causes: a requested feed is unknown, unavailable or unsupported on the channel while ignoreInvalidFeeds is false. The subscriptionId is already in use. The unsubscribe matches no active subscription.

errorstring

A description of the error.

subscriptionIdinteger

The ID of the subscription associated with this message.

"type": "streamUpdated"

Contains a price update for the subscription. With JSON delivery, the server sends this message at the channel's update frequency. With binary delivery, the server sends a binary frame instead.

subscriptionIdinteger

The ID of the subscription associated with this message.

parsedobject

Decoded feed values for this update. Omitted when the request sets parsed to false.

priceFeedsobject[]

Feed values included in this update.

priceFeedIdinteger

Numeric ID of the price feed.

exponentinteger

Power of ten that scales the decimal fields: decimal value = mantissa * 10^exponent. Included when requested in properties.

pricestring

Price, before applying exponent. On funding-rate feeds, the funding price. Included when requested in properties and a value is available.

bestAskPricestring

Best ask price, before applying exponent. Included for price feeds when requested in properties and a value is available.

bestBidPricestring

Best bid price, before applying exponent. Included for price feeds when requested in properties and a value is available.

confidenceinteger

Confidence interval of the price, before applying exponent. Included for price feeds when requested in properties and a value is available.

emaConfidenceinteger

Exponential moving average of the confidence interval, before applying exponent. Included for price feeds when requested in properties and a value is available.

emaPricestring

Exponential moving average of the price, before applying exponent. Included for price feeds when requested in properties and a value is available.

Show 6 more
feedUpdateTimestampinteger

Feed update timestamp, in Unix microseconds. Included when requested in properties.

fundingRateinteger

Perpetual futures funding rate, before applying exponent. Included for funding-rate feeds when requested in properties and a value is available.

fundingRateIntervalinteger

Time between funding rate updates, in microseconds. Included for funding-rate feeds that define an interval, when requested in properties.

fundingTimestampinteger

Timestamp of the latest funding rate, in Unix microseconds. Included for funding-rate feeds when requested in properties and a value is available.

marketSessionstring

Market session of the feed update. Included when requested in properties.

  • regular
  • preMarket
  • postMarket
  • overNight
  • closed
publisherCountinteger

Number of publishers contributing to the update. Included when requested in properties.

timestampUsstring

The update timestamp, in Unix microseconds.

evmleEcdsaleUnsignedsolanaobject

Each payload contains encoding and data. The evm, solana, and leEcdsa payloads include signatures. The leUnsigned payload does not include a signature.

datastring

Binary payload encoded using the format specified by encoding.

encodingstring

The encoding of data.

  • base64
  • hex