Skip to main content

Real-Time Price Updates

Experience live commodity price updates via WebSocket connection

Demo Mode

This is a demonstration of the real-time WebSocket feature available for Professional plans and above. In production, you'll receive live price updates as they happen in the market.

Real-Time Prices
connecting

WTI Crude Oil

Waiting for data...

Brent Crude Oil

Waiting for data...

Natural Gas

Waiting for data...

Gold

Waiting for data...

Silver

Waiting for data...

Copper

Waiting for data...

WebSocket Benefits

  • • Instant price updates without polling
  • • Lower latency than REST API calls
  • • Reduced server load and API requests
  • • Perfect for trading applications
  • • Automatic reconnection on disconnect

Implementation

// Connect to WebSocket
const ws = new WebSocket(
  'wss://api.oilpriceapi.com/v1/stream'
);

// Subscribe to commodities
ws.send(JSON.stringify({
  action: 'subscribe',
  commodities: ['CRUDE_OIL_USD'],
  auth: 'YOUR_API_KEY'
}));

// Receive updates
ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log('Price update:', data);
};

Ready for Real-Time Data?

Upgrade to Professional plan or above to access WebSocket streaming for all commodities