Skip to content

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/info

Private subscriptions (subAccountUpdates - requires authentication):

wss://papi.synthetix.io/v1/ws/trade

Overview

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

ParameterTypeRequiredDescription
idstringYesClient-generated unique request identifier
methodstringYesMust be "subscribe"
params.typestringYesMust be "marketPrices"
params.symbolstringNoTrading 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

FieldTypeDescription
symbolstringTrading pair symbol (e.g., "BTC-USDT")
pricestringPrice value for this update type
lastUpdateTimestringTimestamp when the price was published (RFC3339 format)
updateTypestringPrice type: "mark", "last", "index", or "mid"

Price Types

Each price type is sent as a separate update:

TypeDescriptionExample Use Case
markMark price used for margin calculationsPosition valuation, liquidation checks
lastLast traded price on the exchangeCurrent market price display
indexIndex price from external referenceFair value reference
midMid-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: lastUpdateTime is 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

FeatureWebSocket marketPricesREST getMarketPrices
Data FormatIndividual price updatesComprehensive market data
Update ModelPush (as prices change)Pull (on request)
Fieldssymbol, price, timestamp, typeAll price types + funding + volume + OI
Use CaseReal-time price trackingSnapshot of all market data
Message SizeSmall (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

ErrorDescriptionSolution
Invalid symbolSymbol not availableCheck supported trading pairs via Get Markets
Subscription failedToo many active subscriptionsReduce the number of concurrent subscriptions
Connection timeoutWebSocket disconnectedImplement reconnection logic with exponential backoff

Related Endpoints