OilPriceAPI Documentation
GitHub
GitHub
  • Interactive Explorer

    • Interactive API Explorer
  • Price Data

    • API Reference
    • Get Latest Prices
    • Historical Prices
  • Commodities

    • List Commodities
    • Get Commodity Details
  • Marine Fuels

    • List Marine Fuel Ports
    • Get Port Details with Prices
  • Premium Endpoints

    • All Prices API - One Call, All Commodities
    • Cushing Oil Storage Intelligence API
    • Drilling Intelligence API
    • Marine Fuels API
    • ICE Brent Futures API

All Prices API - One Call, All Commodities

Overview

Get all available commodity prices in a single API call. This endpoint returns current prices for 40+ energy commodities, metals, and forex pairs, making it ideal for dashboards, market overviews, and reducing API calls.

Access Level: Available to all tiers (request limits apply)

Endpoint

GET /v1/prices/all

Authentication

Requires API key authentication:

curl -X GET "https://api.oilpriceapi.com/v1/prices/all" \
  -H "Authorization: Token YOUR_API_KEY" \
  -H "Accept: application/json"

Query Parameters

ParameterTypeDescriptionExample
categoriesstringComma-separated list of categories to filteroil,gas,metals
codesstringComma-separated list of specific commodity codesWTI_USD,BRENT_CRUDE_USD,GOLD_USD
include_metadatabooleanInclude additional metadata for each commoditytrue

Response Format

{
  "status": "success",
  "data": {
    "prices": [
      {
        "code": "WTI_USD",
        "name": "WTI Crude Oil",
        "price": 72.45,
        "currency": "USD",
        "unit": "barrel",
        "category": "oil",
        "change_24h": 0.85,
        "change_24h_percent": 1.19,
        "last_updated": "2025-09-22T14:30:00Z"
      },
      {
        "code": "BRENT_CRUDE_USD",
        "name": "Brent Crude Oil",
        "price": 76.32,
        "currency": "USD",
        "unit": "barrel",
        "category": "oil",
        "change_24h": 0.92,
        "change_24h_percent": 1.22,
        "last_updated": "2025-09-22T14:30:00Z"
      },
      {
        "code": "NATURAL_GAS_USD",
        "name": "Natural Gas (Henry Hub)",
        "price": 2.85,
        "currency": "USD",
        "unit": "mmBtu",
        "category": "gas",
        "change_24h": -0.03,
        "change_24h_percent": -1.04,
        "last_updated": "2025-09-22T14:30:00Z"
      },
      {
        "code": "GOLD_USD",
        "name": "Gold",
        "price": 1923.45,
        "currency": "USD",
        "unit": "oz",
        "category": "metals",
        "change_24h": 5.20,
        "change_24h_percent": 0.27,
        "last_updated": "2025-09-22T14:30:00Z"
      }
      // ... 35+ more commodities
    ],
    "metadata": {
      "total_commodities": 42,
      "timestamp": "2025-09-22T14:30:00Z",
      "cache_time": 60,
      "categories_included": ["oil", "gas", "metals", "forex", "marine_fuels"],
      "update_frequency": "5 minutes"
    }
  }
}

Available Commodities

Energy - Oil (10 types)

CodeNameUnit
WTI_USDWTI Crude OilUSD/barrel
BRENT_CRUDE_USDBrent Crude OilUSD/barrel
DUBAI_CRUDE_USDDubai CrudeUSD/barrel
TAPIS_CRUDE_USDTapis CrudeUSD/barrel
WCS_CRUDE_USDWestern Canada SelectUSD/barrel
URALS_CRUDE_USDUrals CrudeUSD/barrel
GASOLINE_RBOB_USDRBOB GasolineUSD/gallon
HEATING_OIL_USDHeating OilUSD/gallon
JET_FUEL_USDJet FuelUSD/gallon
ULSD_DIESEL_USDULSD DieselUSD/gallon

Energy - Natural Gas (5 types)

CodeNameUnit
NATURAL_GAS_USDHenry Hub Natural GasUSD/mmBtu
NATURAL_GAS_GBPUK Natural GasGBp/therm
DUTCH_TTF_EURDutch TTF GasEUR/MWh
JKM_LNG_USDJapan/Korea LNGUSD/mmBtu
NATURAL_GAS_STORAGEUS Gas StorageBcf

Marine Fuels (Base + Port-specific)

CodeNameUnit
VLSFO_USDVery Low Sulfur Fuel Oil (Global)USD/MT
HFO_380_USDHeavy Fuel Oil 380 CST (Global)USD/MT
MGO_05S_USDMarine Gas Oil 0.5%S (Global)USD/MT
HFO_380_NLRTM_USDHFO 380 RotterdamUSD/MT
VLSFO_SGSIN_USDVLSFO SingaporeUSD/MT
MGO_05S_USHOU_USDMGO HoustonUSD/MT
VLSFO_AEFUJ_USDVLSFO FujairahUSD/MT

Metals (2 types)

CodeNameUnit
GOLD_USDGoldUSD/oz
URANIUM_USDUranium U308USD/lb

Other Energy (3 types)

CodeNameUnit
COAL_USDNewcastle CoalUSD/MT
ETHANOL_USDEthanolUSD/gallon
EU_CARBON_EUREU Carbon CreditsEUR/tonne

Forex (2 pairs)

CodeNameUnit
GBP_USDBritish PoundUSD
EUR_USDEuroUSD

Drilling Intelligence (Premium Only)

CodeNameUnit
US_RIG_COUNTUS Rig Countrigs
CANADA_RIG_COUNTCanada Rig Countrigs
CUSHING_STORAGECushing Oil Storagemillion barrels

Filtering Examples

Get Only Oil and Gas Prices

GET /v1/prices/all?categories=oil,gas

Get Specific Commodities

GET /v1/prices/all?codes=WTI_USD,BRENT_CRUDE_USD,NATURAL_GAS_USD,GOLD_USD

Get All Prices with Metadata

GET /v1/prices/all?include_metadata=true

Health Check Endpoint

Monitor data freshness for all commodities:

GET /v1/prices/all/health

Response:

{
  "status": "healthy",
  "data": {
    "total_commodities": 42,
    "fresh_data": 40,
    "stale_data": 2,
    "stale_commodities": [
      {
        "code": "COAL_USD",
        "last_updated": "2025-09-22T08:00:00Z",
        "hours_old": 6.5
      }
    ],
    "average_age_minutes": 12,
    "last_full_update": "2025-09-22T14:25:00Z"
  }
}

Example Usage

JavaScript - Dashboard Integration

async function updateDashboard() {
  const response = await fetch('https://api.oilpriceapi.com/v1/prices/all', {
    headers: {
      'Authorization': 'Token YOUR_API_KEY'
    }
  });

  const data = await response.json();

  // Group by category
  const grouped = data.data.prices.reduce((acc, item) => {
    if (!acc[item.category]) acc[item.category] = [];
    acc[item.category].push(item);
    return acc;
  }, {});

  // Display oil prices
  grouped.oil.forEach(commodity => {
    console.log(`${commodity.name}: $${commodity.price} ${commodity.change_24h_percent > 0 ? 'šŸ“ˆ' : 'šŸ“‰'}`);
  });
}

Python - Real-time Price Alerts (WebSocket)

import websocket
import json
import threading

class PriceAlertSystem:
    def __init__(self, api_key, alert_threshold=2.0):
        self.api_key = api_key
        self.alert_threshold = alert_threshold
        self.ws = None

    def on_message(self, ws, message):
        data = json.loads(message)

        if data.get('type') == 'ping':
            return

        if 'message' in data:
            self.handle_price_update(data['message'])

    def handle_price_update(self, data):
        if data.get('type') == 'price_update':
            price_data = data['data']

            # Check alert condition: >2% daily change
            change_percent = abs(price_data.get('change_24h_percent', 0))
            if change_percent > self.alert_threshold:
                self.trigger_alert(price_data, change_percent)

    def trigger_alert(self, price_data, change_percent):
        direction = "šŸ“ˆ" if price_data.get('change_24h', 0) > 0 else "šŸ“‰"
        print(f"🚨 PRICE ALERT: {price_data['name']} {direction}")
        print(f"   Current: ${price_data['price']}")
        print(f"   Change: {change_percent:.2f}% in 24h")
        print(f"   Time: {price_data['created_at']}\n")

        # Add your alert logic here:
        # - Send email notification
        # - Push to mobile app
        # - Log to database
        # - Trigger trading bot

    def on_error(self, ws, error):
        print(f"WebSocket error: {error}")

    def on_close(self, ws):
        print("Price alert connection closed")

    def on_open(self, ws):
        print("āœ… Connected to real-time price alerts")

        # Subscribe to all commodity price updates
        subscribe_message = {
            'command': 'subscribe',
            'identifier': json.dumps({
                'channel': 'EnergyPricesChannel',
                'api_key': self.api_key
            })
        }
        ws.send(json.dumps(subscribe_message))

    def start_monitoring(self):
        websocket.enableTrace(False)
        self.ws = websocket.WebSocketApp(
            "wss://api.oilpriceapi.com/cable",
            on_message=self.on_message,
            on_error=self.on_error,
            on_close=self.on_close,
            on_open=self.on_open
        )

        # Run forever - use threading for background operation
        self.ws.run_forever()

# Usage - Real-time alerts with 2% threshold
alert_system = PriceAlertSystem('YOUR_API_KEY', alert_threshold=2.0)

# Start monitoring in background thread
monitor_thread = threading.Thread(target=alert_system.start_monitoring)
monitor_thread.daemon = True
monitor_thread.start()

print("šŸ”„ Price alert system running...")
print("Will alert on price moves >2%")

# Keep main thread alive
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    print("\nā¹ļø  Stopping price alerts...")

Note: WebSocket alerts require Reservoir Mastery subscription. For free tiers, use the REST API with reasonable polling intervals to avoid rate limits.

React - Real-time Price Grid

import React, { useState, useEffect } from 'react';

function PriceGrid() {
  const [prices, setPrices] = useState([]);

  useEffect(() => {
    const fetchPrices = async () => {
      const response = await fetch('/api/prices/all', {
        headers: {
          'Authorization': 'Token YOUR_API_KEY'
        }
      });
      const data = await response.json();
      setPrices(data.data.prices);
    };

    fetchPrices();
    const interval = setInterval(fetchPrices, 60000); // Update every minute

    return () => clearInterval(interval);
  }, []);

  return (
    <div className="price-grid">
      {prices.map(commodity => (
        <div key={commodity.code} className="price-card">
          <h3>{commodity.name}</h3>
          <div className="price">${commodity.price}</div>
          <div className={commodity.change_24h > 0 ? 'up' : 'down'}>
            {commodity.change_24h_percent.toFixed(2)}%
          </div>
        </div>
      ))}
    </div>
  );
}

Benefits

  1. Reduced API Calls: Get all data in one request instead of 40+ individual calls
  2. Lower Latency: Single round-trip for complete market overview
  3. Synchronized Data: All prices from the same timestamp
  4. Simplified Code: One endpoint to maintain in your application
  5. Cost Effective: Counts as single request against your limit

Performance

  • Response Time: < 200ms average
  • Payload Size: ~15KB (compressed)
  • Cache Headers: Included for client-side caching
  • CDN: Global edge locations for low latency

Error Responses

StatusDescription
401Unauthorized - Invalid API key
429Rate limit exceeded
503Service temporarily unavailable
504Gateway timeout - try with filters

Related Endpoints

  • /v1/prices/latest?code={CODE} - Single commodity price
  • /v1/prices/past_day - 24-hour historical data
  • /v1/commodities - List of available commodities
  • /v1/prices/marine-fuels - Detailed marine fuel prices by port
Next
Cushing Oil Storage Intelligence API