How to Get Crude Oil WTI (CL=F) Prices via API
You need to programmatically display and alert on West Texas Intermediate (WTI) front-month prices (CL=F) in your app. By the end of this guide, you will: look up the correct symbol, fetch the latest price via a single HTTP call, parse it in code, and understand how to extend it to fluctuations and historical ranges—ready for charting and alerts.
What you’ll build: a clean path from CL=F to a price on screen
We’ll keep it practical and minimal. You’ll confirm the exact symbol on the supported symbols list, hit the latest endpoint, and read the USD-denominated price field your UI needs. We’ll also cover update cadence, weekends vs. trading days, timestamp use, and how to cache responses safely in production.
If you don’t have a key yet, start with a 7‑day trial (PRO $49.99/mo) and get your credentials here: Register.
Confirm the exact WTI symbol before you code
Commodity and index symbols are sometimes exchange-specific. Do not assume that “CL=F” is the canonical code used by the API. First, look it up on the symbols list and confirm the exact code string the API expects for WTI front-month. If a precise WTI symbol is listed, use that code directly in your integration.
- Browse the up-to-date catalog here: Indices-API Supported Symbols.
- If you need coverage details or methodology, see: Market Coverage & Precision (MCP).
Tip: the API typically returns both a compact cross-style code and a USD-prefixed field for direct dollar quotes, e.g., USD{SYMBOL}. You’ll read the USD-prefixed field for charting in dollars. We’ll show an example below using an index to illustrate the exact JSON structure.
Fetch the latest quote in one request
Use the latest endpoint. Authentication is via an access_key query parameter. The endpoint returns a single payload containing base currency, a UTC timestamp, the trade date, and a rates map keyed by symbols (including a USD{SYMBOL} convenience field for dollar-denominated reads when available).
cURL: copy–paste and run
curl -s "https://indices-api.com/api/latest?access_key=YOUR_API_KEY"
You will get a JSON response that follows the same structure shown below. This is a real payload example demonstrating how to read a USD-prefixed field for an index. Replace the symbol with the confirmed WTI code from the symbols page when you integrate CL=F.
{"data":{"success":true,"timestamp":1794271020,"date":"2026-11-10","base":"USD","rates":{"GSPC":0.00013245138371961,"USD":1,"USDGSPC":7549.939999999756}}}
What each field means (and what you’ll actually use)
- data.success: boolean indicating the call succeeded.
- data.timestamp: Unix epoch seconds (UTC). Use for cache keys and freshness checks.
- data.date: Trade date linked to the quotes. Useful for labeling candles and EOD snapshots.
- data.base: Base currency of the price map. By default, USD.
- data.rates: Map of symbol codes to values. In this example:
- GSPC: Cross-style rate value relative to USD.
- USD: Always 1.0 in USD base.
- USDGSPC: The direct read you want for a USD price of this symbol.
For WTI, after you confirm the precise symbol on the symbols list, read the USD-prefixed entry (e.g., USD{WTI_SYMBOL}) to get a direct dollar price suitable for charts and alerts.
JavaScript example: read a USD price and guard for weekends
This snippet fetches the latest payload, checks freshness via timestamp, and pulls a USD-denominated field. Replace WTI_SYMBOL with the confirmed code from the symbols list and set the key via environment or secrets manager.
async function getLatestUsdPrice(symbolCode) {
const url = `https://indices-api.com/api/latest?access_key=${encodeURIComponent(process.env.INDICES_API_KEY)}`;
const res = await fetch(url, { cache: "no-store" });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const payload = await res.json();
// Access the inner data object as shown in the real response above
const data = payload.data;
if (!data || !data.success) throw new Error("API indicated failure");
const { timestamp, date, base, rates } = data;
// Build the USD-prefixed field name that carries the dollar price
const usdField = `USD${symbolCode}`;
const usdPrice = rates[usdField];
if (typeof usdPrice !== "number") {
throw new Error(`Missing USD price for ${symbolCode}. Check the symbols list and payload keys.`);
}
// Basic freshness/caching suggestion: if data is older than ~15 minutes, decide whether to refetch or serve cached UI
const now = Math.floor(Date.now() / 1000);
const ageSec = now - timestamp;
return {
symbol: symbolCode,
priceUsd: usdPrice,
tradeDate: date, // e.g., "2026-11-10"
timestampUtc: timestamp, // epoch seconds
base, // typically "USD"
stale: ageSec > 1200 // 20-minute heuristic; tune per your plan and UX
};
}
// Example invocation with an index from the real payload:
// For CL=F, replace "GSPC" with the confirmed WTI symbol code from the symbols list.
getLatestUsdPrice("GSPC")
.then(console.log)
.catch(console.error);
Notes:
- Base currency: USD. Prices are returned “per instrument” in dollars. Your UI can display the USD-prefixed field as-is.
- Weekends/non-trading days: Commodity and index schedules vary. On non-trading days, the latest payload may carry the prior session’s date and timestamp. Use both fields to label data clearly.
- Update frequency: The latest endpoint refresh cadence depends on plan. Expect updates every 60 minutes, 10 minutes, or faster per subscription. See the Indices-API Documentation for plan details.
From “latest” to charting and alerts for CL=F
Once you can read the USD-prefixed price for your confirmed WTI symbol, you can support the most common product tasks: backfilling a range for a chart and alerting on moves between two dates.
Backfilling a range
For a multi-day chart, query historical data across a date span. Indices-API provides dedicated endpoints for historical snapshots and time series. The general approach:
- Pick a start_date and an end_date that is not today (use the most recent completed trading day). The end_date cannot be today.
- Request daily observations across the window you need.
- Plot the USD-prefixed series to keep everything in dollars consistently.
Consult the Documentation for the exact parameters and response schema of the time-series and historical endpoints and apply the same field-reading pattern shown above (base, date, rates, USD{SYMBOL}).
Fluctuations and day-over-day changes
For alerting, you can either compute changes client-side from two observations or use the fluctuation endpoint, which reports start_rate, end_rate, and absolute/percent change for a defined window. When you configure alerts:
- Pick your window (e.g., prev close → last close) and set thresholds.
- Avoid same-day end_date. Use the last completed session for stability.
- If you compute client-side, store the last N closes and compare the most recent two values in USD.
Because instruments trade on different calendars and sessions, always consider the trade date in your comparisons. If today is a holiday for WTI, your alert should reference the last available date to avoid noisy triggers.
Production details that will save you time
- Authentication: All requests use the access_key query parameter.
- Base currency and units: base is typically USD; quotes are “per instrument.” For display, read the USD-prefixed field (USD{SYMBOL}).
- Timestamps: timestamp is epoch seconds in UTC. Use it for caching and TTL decisions, and show users the trade date alongside the plotted point.
- End-of-day vs. intraday: The latest endpoint returns the current snapshot per your plan’s update frequency. If you need candles, use the OHLC or intraday endpoints described in the docs and still read USD{SYMBOL} for dollar charts.
- Weekends/holidays: Data remains accessible; the date field reflects the prior session. Don’t treat weekend payloads as stale errors—check timestamp and date first.
- Caching: A common approach is a short in-memory cache (e.g., 15–60 seconds for dashboards) layered over a longer CDN cache for historical endpoints. Compare the server timestamp to your TTL before invalidating.
- Pagination and limits: Some endpoints impose date-range limits per request. Slice long backfills into bounded windows and merge client-side.
- Symbols change: Exchanges may roll front-month futures. If you model the “current” WTI contract, watch symbol changes via the symbols endpoint and rotate automatically.
Quality checks for CL=F before shipping
- Confirm the exact code on the Symbols page. Do not hard-code an assumed ticker.
- Verify that data.rates contains the USD-prefixed entry for your symbol. If not present, inspect the plain symbol mapping and adapt your read logic accordingly.
- Always log data.date with the plotted point; this avoids confusion when sessions differ by region or holiday.
- Test alert logic across a weekend boundary and a holiday to ensure thresholds trigger on the intended session.
Where to go deeper
- Endpoint parameters, response fields, and examples: Indices-API Documentation
- Browse all supported instruments and confirm codes: Indices-API Supported Symbols
- Market coverage and precision notes: MCP
- WTI background reading: CME WTI Crude Oil (CL) contract specs
- Typical consumer reference page for the front-month stream: Yahoo Finance CL=F overview
FAQ
How do I get the exact WTI symbol code this API expects?
Use the searchable catalog at Symbols. Copy the code exactly as listed. If you model “front-month” rolls, implement a lookup that follows the current front-month symbol.
Which field is the dollar price I should chart?
Read the USD-prefixed field in data.rates, e.g., USD{SYMBOL}. In the real payload above it’s USDGSPC for that index. For WTI, use USD{WTI_SYMBOL} if present.
Why does end_date “not today” matter in time-series calls?
The latest session may be in progress, paused, or on a holiday. Using the last completed date ensures stable, finalized values for EOD charts. Always set end_date to the most recent completed trading day.
How often does the latest price update?
Update frequency depends on your plan tier (e.g., every 60 minutes or 10 minutes). Consult the Documentation for specifics and design your cache TTLs accordingly.
What should I do on weekends and holidays?
Expect the payload to include the last active trade date; the timestamp will reflect when the snapshot was generated. Label points with data.date, and keep alerts scoped to completed sessions to avoid noisy triggers.
Get your key and ship it
Spin up a 7‑day trial (PRO $49.99/mo), confirm the WTI symbol on the symbols page, and plug in the latest endpoint to render a clean USD price in your app. Your next step: get an API key here and start calling the endpoints in minutes: Register.