Getting Started
Learn how to access, configure, and use Pyth Pro price feeds
Pyth Pro is a high-performance, low-latency service that provides real-time financial market data. This guide will walk you through setting up and running a basic JavaScript example to subscribe to Pyth Pro price feeds.
Try a Live Stream
This preview subscribes to three feeds on the Fixed 200ms channel.
- Change since Run
- —
- Timestamp
- —
- Change since Run
- —
- Timestamp
- —
- Change since Run
- —
- Timestamp
- —
The preview uses a shared demo key, which is rate-limited, and each stream stops after ten seconds. For other feeds, properties or channels, open the Pyth Playground.
Get an API Key
Your own app needs a Pyth Pro API key. To request one, follow Acquire an API Key.
Run the Code
This code opens the same stream from your app, in TypeScript, Python or Go, or as a wscat command.
Set the PYTH_PRO_API_KEY environment variable to your API key, then run it.
pyth-pro-example.ts// Requirements: Node.js 24 or later
// npm install @pythnetwork/pyth-lazer-sdk
// npm pkg set type=module
//
// Usage:
// node pyth-pro-example.ts
import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";
// Read your API key from the environment (never hard-code it)
const token = process.env.PYTH_PRO_API_KEY;
if (!token) throw new Error("Set PYTH_PRO_API_KEY in your environment");
// Create the Pyth Pro client with WebSocket pool configuration
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",
],
},
});
// Subscribe to price feeds
client.subscribe({
type: "subscribe",
subscriptionId: 1,
priceFeedIds: [3191, 327, 1],
properties: ["price", "feedUpdateTimestamp"],
formats: ["solana"],
channel: "fixed_rate@200ms",
deliveryFormat: "json",
jsonBinaryEncoding: "hex",
parsed: true,
ignoreInvalidFeeds: true, // Ignore invalid feed IDs instead of failing
});
// Listen for price updates
client.addMessageListener((message) => {
if (message.type === "json") {
console.log("Received JSON update:", JSON.stringify(message.value, null, 2));
} else {
console.log("Received binary update:", {
subscriptionId: message.value.subscriptionId,
parsed: message.value.parsed,
});
}
});
// Handle connection errors
client.addAllConnectionsDownListener(() => {
console.error("All WebSocket connections are down!");
});
// To unsubscribe later:
// client.unsubscribe(1);
// To shutdown the client:
// client.shutdown();
Pyth Pro was previously known as Pyth Lazer. The SDK remains the same.
Production Tip: Include feedUpdateTimestamp
For production applications, add "feedUpdateTimestamp" to the properties
array. This field lets you determine whether a price was freshly generated or
carried forward from an earlier update by comparing it against timestampUs.
See Payload Reference — Price Availability
Semantics for
details.
For a detailed explanation of every property passed to client.subscribe, see
the Payload
Reference.
What's Next?
Now that you've successfully run the basic Pyth Pro example, you can explore more advanced integration patterns:
More Information
Explore additional Pyth Pro capabilities:
- Subscribe to Price Updates - Detailed guide on WebSocket subscriptions and message handling
- Price Feed IDs - Where to find each feed's ID, in Pyth Terminal or from code
Blockchain Integration
Learn how to integrate Pyth Pro price feeds into your smart contracts:
- Solana Integration - Build SVM smart contracts that consume Pyth Pro price feeds with cryptographic verification
- EVM Integration - Integrate Pyth Pro into Ethereum and other EVM-compatible chains
- Sui Integration - Verify Pyth Pro price updates in Sui Programmable Transaction Blocks before consuming them in Move contracts
- IOTA Integration - Verify Pyth Pro price updates in IOTA Programmable Transaction Blocks before consuming them in Move contracts
- Cardano Integration - Verify Pyth Pro price updates in Cardano transactions
AI-Assisted Development
Use Pyth market data directly in AI assistants like Claude, Cursor, and Windsurf via the Model Context Protocol:
- MCP Server - Connect your AI assistant to Pyth price feeds, historical data, and candlestick charts
- MCP Skills - Pre-built workflows for portfolio tracking, volatility analysis, FX conversion, and more
Example Applications
Check out more comprehensive examples in the pyth-examples repository:
- Solana Examples - Post price data to Solana smart contracts with Ed25519 and ECDSA verification
- EVM Examples - Smart contract integration for Ethereum-compatible chains