Market Price Updates
Receive real-time price updates for individual price types (mark, last, index, mid) as they change.
Endpoint
Public subscriptions (candles, marketPrices, orderbook):
wss://papi.synthetix.io/v1/ws/infoPrivate subscriptions (subAccountUpdates - requires authentication):
wss://papi.synthetix.io/v1/ws/tradeOverview
The marketPrices subscription provides real-time updates for individual price types as they are published. Each price type (mark, last, index, mid) is sent as a separate update message when it changes.
Important: Unlike the REST API which returns all price types in a single response, the WebSocket sends individual updates for each price type separately.
Subscription Request
Subscribe to Market Price Updates
{
"id": "sub-1",
"method": "subscribe",
"params": {
"type": "marketPrices",
"symbol": "BTC-USDT"
}
}Subscribe to All Markets
{
"id": "sub-all",
"method": "subscribe",
"params": {
"type": "marketPrices",
"symbol": "ALL"
}
}Alternatively, omit the symbol parameter to subscribe to all markets (defaults to "ALL"):
{
"id": "sub-all",
"method": "subscribe",
"params": {
"type": "marketPrices"
}
}Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Client-generated unique request identifier |
method | string | Yes | Must be "subscribe" |
params.type | string | Yes | Must be "marketPrices" |
params.symbol | string | No | Trading pair symbol or "ALL" for all markets. Defaults to "ALL" if omitted |
Price Update Messages
Update Message Format
{
"method": "market_price_update",
"data": {
"symbol": "BTC-USDT",
"price": "50125.50",
"lastUpdateTime": "2025-01-03T12:34:56.789Z",
"updateType": "mark"
}
}Message Fields
| Field | Type | Description |
|---|---|---|
symbol | string | Trading pair symbol (e.g., "BTC-USDT") |
price | string | Price value for this update type |
lastUpdateTime | string | Timestamp when the price was published (RFC3339 format) |
updateType | string | Price type: "mark", "last", "index", or "mid" |
Price Types
Each price type is sent as a separate update:
| Type | Description | Example Use Case |
|---|---|---|
mark | Mark price used for margin calculations | Position valuation, liquidation checks |
last | Last traded price on the exchange | Current market price display |
index | Index price from external reference | Fair value reference |
mid | Mid-market price (average of best bid/ask) | Spread analysis |
Update Examples
Mark Price Update
{
"method": "market_price_update",
"data": {
"symbol": "BTC-USDT",
"price": "50125.50",
"lastUpdateTime": "2025-01-03T12:34:56.789Z",
"updateType": "mark"
}
}Index Price Update
{
"method": "market_price_update",
"data": {
"symbol": "ETH-USDT",
"price": "3250.75",
"lastUpdateTime": "2025-01-03T12:34:57.123Z",
"updateType": "index"
}
}Last Price Update
{
"method": "market_price_update",
"data": {
"symbol": "SOL-USDT",
"price": "125.48",
"lastUpdateTime": "2025-01-03T12:34:57.456Z",
"updateType": "last"
}
}Mid Price Update
{
"method": "market_price_update",
"data": {
"symbol": "BTC-USDT",
"price": "50124.25",
"lastUpdateTime": "2025-01-03T12:34:58.789Z",
"updateType": "mid"
}
}Implementation Example
const ws = new WebSocket('wss://papi.synthetix.io/v1/ws/info');
ws.onopen = () => {
ws.send(JSON.stringify({
id: 'sub-1',
method: 'subscribe',
params: {
type: 'marketPrices',
symbol: 'BTC-USDT'
}
}));
};
// Cache prices by type
const priceCache = new Map();
ws.onmessage = (event) => {
const message = JSON.parse(event.data);
if (message.method === 'market_price_update') {
const { symbol, price, updateType } = message.data;
if (!priceCache.has(symbol)) {
priceCache.set(symbol, {});
}
priceCache.get(symbol)[updateType] = price;
console.log(`${symbol} ${updateType}: ${price}`);
}
};Subscribe to All Markets
ws.send(JSON.stringify({
id: 'sub-all',
method: 'subscribe',
params: {
type: 'marketPrices',
symbol: 'ALL'
}
}));Use Cases
Trading Interfaces
- Price Tickers: Display real-time mark, last, and index prices
- Price Type Comparison: Compare different price types for arbitrage
- Latency Monitoring: Track price update frequency and freshness
Risk Management
- Mark Price Monitoring: Track mark prices for margin calculations
- Price Divergence: Monitor differences between price types
- Price Staleness: Alert on outdated prices using
lastUpdateTime
Market Analysis
- Price Discovery: Analyze how different price types move
- Spread Analysis: Calculate spreads between mark and index
- Update Frequency: Monitor how often each price type updates
Implementation Notes
- Update Frequency: Each price type updates independently when it changes
- Separate Messages: You receive one message per price type, not a combined message
- Timestamp Format:
lastUpdateTimeis in RFC3339 format - Price Caching: Maintain a local cache to have the latest price for each type
- Memory Management: Clean up old price data to prevent memory leaks
Comparison: WebSocket vs REST API
| Feature | WebSocket marketPrices | REST getMarketPrices |
|---|---|---|
| Data Format | Individual price updates | Comprehensive market data |
| Update Model | Push (as prices change) | Pull (on request) |
| Fields | symbol, price, timestamp, type | All price types + funding + volume + OI |
| Use Case | Real-time price tracking | Snapshot of all market data |
| Message Size | Small (one price at a time) | Large (all data at once) |
Note: For comprehensive market data including funding rates, volume, and open interest, use the REST API endpoint Get Market Prices.
Error Handling
Subscription Errors
{
"id": "sub-1",
"status": 400,
"result": null,
"error": {
"code": 400,
"message": "Invalid symbol: XYZ-USDT not supported"
}
}Common Issues
| Error | Description | Solution |
|---|---|---|
| Invalid symbol | Symbol not available | Check supported trading pairs via Get Markets |
| Subscription failed | Too many active subscriptions | Reduce the number of concurrent subscriptions |
| Connection timeout | WebSocket disconnected | Implement reconnection logic with exponential backoff |
Related Endpoints
- Get Market Prices - Comprehensive market data via REST API (all price types, funding, volume, OI)
- Get Markets - Available trading pairs
- Orderbook Updates - Real-time orderbook depth updates
- Candle Updates - OHLCV candlestick data