Real-Time Oil Price WebSocket
Open one connection to wss://api.oilpriceapi.com/cable and OilPriceAPI pushes Brent, WTI, natural gas, gold and silver updates to you as they arrive, instead of you polling for them.
Quick start
- Use an API key on the Professional or Scale plan. Other keys connect, but the channel subscription is rejected.
- Connect to
wss://api.oilpriceapi.com/cable?token=YOUR_API_KEYwith theactioncable-v1-jsonsubprotocol. - After the welcome frame, subscribe to
EnergyPricesChannel. The first message carries the current prices; updates follow.
Native WebSocket, no dependencies
const token = 'YOUR_API_KEY';
const ws = new WebSocket(
`wss://api.oilpriceapi.com/cable?token=${encodeURIComponent(token)}`,
['actioncable-v1-json']
);
ws.addEventListener('message', (event) => {
const frame = JSON.parse(event.data);
if (frame.type === 'welcome') {
ws.send(JSON.stringify({
command: 'subscribe',
identifier: JSON.stringify({ channel: 'EnergyPricesChannel' })
}));
return;
}
if (frame.type === 'reject_subscription') {
console.error('This key does not include WebSocket access');
return;
}
if (frame.type === 'ping') return;
if (frame.message) console.log('Price update:', frame.message);
});With the ActionCable client
// npm install @rails/actioncable
import { createConsumer } from '@rails/actioncable';
const cable = createConsumer(
`wss://api.oilpriceapi.com/cable?token=${encodeURIComponent(apiKey)}`
);
cable.subscriptions.create('EnergyPricesChannel', {
received(data) {
console.log('Received:', data);
},
});Payload format, reconnect and backfill patterns are in the WebSocket guide.
Live example
Send this frame after the welcome message. The latest Brent record the stream starts from is shown beside it, read from the REST API.
Subscribe frame
{
"command": "subscribe",
"identifier": "{\"channel\":\"EnergyPricesChannel\"}"
}Latest BRENT_CRUDE_USD from the API
$105.65per barrel
As of 2026-10-14 13:21 UTC
Each pushed payload carries its own timestamp. Signed-in Professional and Scale accounts can watch their stream on the streaming demo page.
What the stream carries
| Code | Price |
|---|---|
| BRENT_CRUDE_USD | Brent crude |
| WTI_USD | WTI crude |
| NATURAL_GAS_USD | US natural gas (Henry Hub) |
| NATURAL_GAS_GBP | UK natural gas |
| DUTCH_TTF_EUR | Dutch TTF natural gas |
| GOLD_USD | Gold |
| SILVER_USD | Silver |
Accounts with drilling intelligence also receive rig count, frac spread and DUC well data on the same channel. Every other code in the catalog is available through the REST API.
Frequently asked questions
Which plans include the oil price WebSocket?
Professional and Scale. Developer and Starter keys can connect, but the EnergyPricesChannel subscription is rejected. Starter and higher plans include webhooks if you want pushed updates without a persistent connection.
Which prices does the WebSocket stream?
Brent crude (BRENT_CRUDE_USD), WTI crude (WTI_USD), US natural gas (NATURAL_GAS_USD), UK natural gas (NATURAL_GAS_GBP), Dutch TTF (DUTCH_TTF_EUR), gold (GOLD_USD) and silver (SILVER_USD). Accounts with drilling intelligence also receive rig count, frac spread and DUC well data. For any other code, use the REST API.
How do I authenticate the connection?
Put your API key in the token query parameter of wss://api.oilpriceapi.com/cable, URL-encoded. Browsers cannot set headers on a WebSocket, which is why the key goes in the URL; avoid logging the full URL.
How real-time is it?
A payload is pushed after OilPriceAPI receives a new upstream update, so you stop polling for values that have not changed. How often that happens depends on the market and source. We do not publish a fixed latency figure; compare each payload's source timestamp with the time your client receives it.
What should my client do when the connection drops?
Reconnect, resubscribe to EnergyPricesChannel, and fill any gap from the REST API. Quiet periods are normal: the server sends pings between updates.
Can I try it before upgrading?
You can call the REST API with a free key to build against the same price records. Streaming itself needs a Professional or Scale key. Signed-in accounts with access can watch their stream on the streaming demo page.
Stop polling for prices that have not changed
Start with a free key on the REST API, then switch on streaming with Professional or Scale.