API to Get the WTI Crude Price
If you need a reliable way to programmatically pull the current WTI crude oil price for finance workflows—such as portfolio valuation, hedging dashboards, or PnL attribution—this guide shows how to perform your first request against the Energy API and interpret the response. By the end, you will be able to call the API endpoint for WTI Crude, read the numerical price, units, and date fields, handle errors, and integrate the result in your finance application.
What you will build: a first request for WTI Crude
We will call a single endpoint that returns the latest available data for the symbol named in the title: WTI Crude (symbol code: WTI_CRUDE). You will see how to:
- Authenticate using an api_key query parameter.
- Request the WTI_CRUDE symbol via GET /api/v1/latest with a symbols filter.
- Parse the response fields you need for finance use cases: numeric price, unit, date, and currency.
- Implement basic error-handling for symbol availability.
Before you begin, create an account to obtain an API key. New users can start on the Starter plan ($19.99/mo) with a 7-day trial and 50 calls. Use the Energy API Register page to get your key.
Endpoint and authentication
The Energy API exposes a latest endpoint that you call with GET and filter by one or more symbols. Authentication is via api_key as a query parameter. For this article we request only WTI_CRUDE.
- HTTP method: GET
- Endpoint: https://energy-api.com/api/v1/latest
- Query parameters:
- symbols: WTI_CRUDE
- api_key: YOUR_API_KEY
Copy the cURL below to make your first request. Replace YOUR_API_KEY with your actual key.
cURL: first call for WTI Crude
Code (cURL):
curl -G "https://energy-api.com/api/v1/latest" --data-urlencode "symbols=WTI_CRUDE" --data-urlencode "api_key=YOUR_API_KEY"
Official sample response structure (reference)
The following official sample illustrates the typical fields you will parse when a call succeeds. This sample may reflect a different symbol, but the envelope and field layout are representative (use this structure as a reference for parsing):
JSON (Official sample):
{
"success": true,
"date": "2026-11-12",
"base": "EUR",
"rates": {
"OMIE_ES_DA": 116.1602
},
"dates": {
"OMIE_ES_DA": "2026-11-12"
},
"currencies": {
"OMIE_ES_DA": "EUR"
},
"base_filter_note": null,
"missing_symbols": null
}
How to read this structure for finance use:
- success indicates whether the request completed as intended.
- date is the server-level date reference for the batch response.
- base can be MIXED or a currency code; always read per-symbol currencies when present.
- rates is a map from symbol code to a numeric value. In your case, read rates.WTI_CRUDE.
- dates is a map from symbol code to an ISO date string; read dates.WTI_CRUDE to align valuation dates.
- currencies is a map from symbol code to the currency of the provided rate; for WTI Crude, expect USD, with units noted below.
WTI availability and the exact live error envelope
At the time of the live check, the WTI_CRUDE symbol was reported as unavailable. Here is the exact error envelope returned by the live call. You should build your production error-handling around this structure and guide users to refresh the catalog when needed.
JSON (Live error for WTI_CRUDE):
{"success":false,"error":"Symbol WTI_CRUDE is not currently available. See \/api\/v1\/symbols for the current catalog."}
What this means for your integration:
- If success is false, do not attempt to read rates, dates, or currencies; handle the error message and surface it in your logs or UI.
- When a symbol is temporarily unavailable, revisit the catalog endpoint referenced in the error to confirm availability before retrying.
Python: request and parse WTI Crude fields
The following Python example calls the same endpoint, checks success, and extracts WTI-specific fields if present. It also handles the exact error envelope above, which you may encounter when the symbol is not available.
Code (Python):
import requests
API_URL = "https://energy-api.com/api/v1/latest"
API_KEY = "YOUR_API_KEY"
SYMBOL = "WTI_CRUDE"
def fetch_wti_latest():
params = {
"symbols": SYMBOL,
"api_key": API_KEY
}
resp = requests.get(API_URL, params=params, timeout=15)
resp.raise_for_status()
data = resp.json()
# Handle explicit error envelope from the API
if isinstance(data, dict) and data.get("success") is False:
# Example error:
# {"success":false,"error":"Symbol WTI_CRUDE is not currently available. See /api/v1/symbols for the current catalog."}
raise RuntimeError(f"API error: {data.get('error')}")
# For successful envelopes (see official sample), read per-symbol maps
rates = data.get("rates", {})
dates = data.get("dates", {})
currencies = data.get("currencies", {})
# Attempt to read the WTI crude price and metadata
price = rates.get(SYMBOL)
price_date = dates.get(SYMBOL)
currency = currencies.get(SYMBOL)
if price is None:
raise ValueError(f"Price for {SYMBOL} not found in 'rates' map.")
# Unit for WTI: USD/barrel (per catalog facts). Currency should be USD, but always read currencies[SYMBOL].
return {
"symbol": SYMBOL,
"price": price,
"unit": "USD/barrel",
"currency": currency,
"date": price_date
}
if __name__ == "__main__":
try:
wti = fetch_wti_latest()
print(f"{wti['symbol']} {wti['price']} {wti['unit']} on {wti['date']} ({wti['currency']})")
except Exception as e:
# In production, route to your logging and display a clear operator message.
print(f"Failed to fetch WTI_CRUDE: {e}")
Implementation notes for finance apps:
- Units: WTI Crude prices are quoted in USD/barrel. Use this in valuation and unit conversion logic.
- Currencies: Always prefer currencies.WTI_CRUDE to confirm the price currency before FX conversion.
- Date: dates.WTI_CRUDE is the valuation date; persist it with the price to maintain auditability.
- Error handling: Trap success = false and message parsing early to prevent downstream null arithmetic.
Understanding units, base currency, and symbol maps
The API can report a top-level base that may be MIXED. For symbol-specific work, read currencies.WTI_CRUDE rather than relying on base. When the base is MIXED, it indicates that multiple symbols in a response are quoted in different units or currencies. For a single-symbol pull of WTI_CRUDE, the finance-ready path is:
- Use rates.WTI_CRUDE as the numeric price.
- Use currencies.WTI_CRUDE for the currency tag (expected USD).
- Use dates.WTI_CRUDE as the valuation date.
- Treat the unit as USD/barrel for calculations and display.
Caching, refresh cadence, and non-trading days
Energy commodities can exhibit holiday effects and weekend lulls depending on the underlying market’s trading schedule. For live or near-real-time finance dashboards, implement a small cache with a short TTL to protect from transient instability while keeping your displays fresh. When you detect repeated symbol unavailability (as shown in the live error envelope), degrade the feature gracefully and surface an operational notice rather than stale data.
Tips for production:
- Retry with exponential backoff when you receive transient network errors, but do not hammer the endpoint on symbol unavailability; consult the catalog first.
- Persist the last known good price tagged by dates.WTI_CRUDE and currencies.WTI_CRUDE to support point-in-time restatements.
- Log the exact error strings to simplify support. They’re short and deterministic.
Troubleshooting and common pitfalls
- Authentication: Always include api_key as a query parameter. Use only YOUR_API_KEY in examples; never commit a real key to source control.
- Symbol accuracy: The Energy API catalog governs symbol availability. If you receive the live error for WTI_CRUDE, refresh the catalog and retry later.
- Mixed bases: base may be MIXED. Do not assume a global currency for all symbols in the same response; read currencies.WTI_CRUDE explicitly.
- Units: WTI Crude prices are measured in USD/barrel. Keep this unit label close to any displayed or exported numeric values for finance workflows.
- Cross-symbol queries: Do not pass base=USD when you also need TTF_GAS or EUA_CO2 in the same request. Query only what you need, or read per-symbol currencies.
JSON example: live error envelope for WTI_CRUDE
This is the exact live error envelope again, shown separately so you can copy it into tests for negative-path handling:
JSON (WTI_CRUDE error):
{"success":false,"error":"Symbol WTI_CRUDE is not currently available. See \/api\/v1\/symbols for the current catalog."}
JSON example: structure reference for successful envelopes
Use this second copy of the official sample as a parsing reference in unit tests that exercise the success path (field names and shapes):
JSON (Official sample, for parser tests):
{
"success": true,
"date": "2026-11-12",
"base": "EUR",
"rates": {
"OMIE_ES_DA": 116.1602
},
"dates": {
"OMIE_ES_DA": "2026-11-12"
},
"currencies": {
"OMIE_ES_DA": "EUR"
},
"base_filter_note": null,
"missing_symbols": null
}
How to deploy in a finance workflow
Once your request flow is stable, integrate the parsed WTI Crude output into your valuation or risk stack:
- Persist symbol, price, currency, date, and unit in your market data store.
- Normalize your downstream portfolio calculations to USD/barrel when consuming WTI_CRUDE.
- When combining with other energy instruments, never coerce symbols to a shared base—read currencies per symbol and convert explicitly if needed.
Implement a simple consistency check in your pipeline: if currencies.WTI_CRUDE is not USD or if dates.WTI_CRUDE drifts unexpectedly from the current business date, route the job for review rather than publishing incomplete PnL.
FAQ
Q: What is the correct symbol code to request WTI Crude?
A: Use WTI_CRUDE exactly. The symbol name is “WTI Crude” and the unit is USD/barrel.
Q: How do I authenticate?
A: Pass your key as a query parameter named api_key. Example: api_key=YOUR_API_KEY.
Q: How do I read the price and date fields?
A: Read the per-symbol maps: rates.WTI_CRUDE for the numeric price, dates.WTI_CRUDE for the valuation date, and currencies.WTI_CRUDE for the price currency. Base may be MIXED, so rely on per-symbol fields.
Q: What should I do if WTI_CRUDE is unavailable?
A: Handle the error envelope where success is false and consult the catalog endpoint referenced in the error message. Do not assume stale data is valid; surface an operational notice and retry when the catalog confirms availability.
Q: Can I combine WTI_CRUDE with other symbols in one request?
A: Yes, include multiple codes in symbols, but note the guidance not to pass base=USD when you also need TTF_GAS or EUA_CO2. Always read per-symbol currencies for accurate finance calculations.
Ready to integrate WTI Crude pricing into your finance stack? Create your key and run the cURL above in under a minute: visit Register. For endpoint details and field descriptions, see the Documentation.
Ready to get started?
Get your API key and start querying energy commodity prices in minutes.
Get API Key