High-Performance Price Streaming

The fastest and most accurate market data with minimal overhead

Overview

Lightspeed is optimized for performance, delivering price updates every 500 milliseconds without the verification overhead of our other endpoints.

This endpoint is very similar to our StarkEx endpoint except it doesn’t contain any metadata that would allow you to verify data’s provenance. The trade-off provides significantly improved performance by eliminating signature generation overhead.

Ultra-Low Latency

Updates every 500ms with minimal processing overhead

High Accuracy

Aggregated from multiple premium sources

Simplified Format

Streamlined JSON responses for easier integration

Connection

1

Open WebSocket Connection

Connect to our WebSocket endpoint on your preferred environment:

wscat -c wss://ws.devnet.pragma.build/node/v1/price/subscribe
2

Subscribe to Asset Pairs

By default, no asset pairs are subscribed. Send a subscription message to start receiving data.

3

Receive Real-Time Updates

Once subscribed, you’ll receive price updates every 500 milliseconds for your selected pairs.

Subscription Management

Subscribing to Pairs

{
  "msg_type": "subscribe",
  "pairs": ["BTC/USD", "ETH/USD:MARK"]
}

The response includes all pairs you are currently subscribed to, including any previous subscriptions not mentioned in your latest request.

Unsubscribing from Pairs

{
  "msg_type": "unsubscribe",
  "pairs": ["BTC/USD"]
}

If you close your WebSocket connection, all your subscriptions will be automatically cleared. You’ll need to resubscribe when reconnecting.

Data Format

{
  "pair_id": "0x12345",
  "price": "10000000000000001",
  "num_sources_aggregated": "8"
}

Field Reference

All numeric values are returned as strings to preserve precision, especially for assets with very small or very large prices.

Implementation Examples

example.js
const WebSocket = require('ws');

// Connect to Lightspeed endpoint
const ws = new WebSocket('wss://ws.devnet.pragma.build/node/v1/price/subscribe');

// Subscribe to pairs on connection open
ws.on('open', function open() {
  console.log('Connected to Lightspeed API');
  
  // Subscribe to specific pairs
  const subscribeMsg = {
    msg_type: "subscribe",
    pairs: ["BTC/USD", "ETH/USD"]
  };
  
  ws.send(JSON.stringify(subscribeMsg));
});

// Handle incoming messages
ws.on('message', function incoming(data) {
  const message = JSON.parse(data);
  
  // Handle subscription confirmations
  if (message.msg_type === "subscribe" || message.msg_type === "unsubscribe") {
    console.log(`${message.msg_type} confirmation:`, message.pairs);
    return;
  }
  
  // Handle price updates
  console.log(`Price update for ${message.pair_id}:`, {
    price: message.price,
    sources: message.num_sources_aggregated
  });
  
  // Process price data as needed
  // ...
});

// Handle errors and disconnections
ws.on('error', function error(err) {
  console.error('Connection error:', err);
});

ws.on('close', function close() {
  console.log('Connection closed');
});

Best Practices

Implement Reconnection Logic

WebSocket connections can drop for various reasons. Always implement automatic reconnection with backoff strategy.

Process Updates Asynchronously

Handle price updates asynchronously to avoid blocking the WebSocket receive thread, especially in high-frequency scenarios.

Batch Subscription Changes

When subscribing to multiple pairs, send them in a single message rather than separate requests.

Monitor Connection Health

Implement periodic health checks and heartbeat monitoring to ensure your connection stays active.

Comparison with Starkex

Lightspeed

  • ✓ Minimal payload size
  • ✓ Optimized for performance
  • ✓ Lower latency
  • ✓ Ideal for trading applications
  • ❌ No verification metadata

Starkex

  • ✓ Includes cryptographic signatures
  • ✓ Verifiable price data
  • ✓ Individual publisher prices
  • ✓ Ideal for StarkEx integration
  • ⚠️ Slightly larger payload size

Choose Lightspeed when performance is your primary concern and Starkex when data provenance verification is required.