Crude Oil WTI (CL) Historical Price API
You need to backfill and chart West Texas Intermediate crude oil (WTI) daily prices, power alerts on week-over-week moves, and keep a dashboard current with the latest ticks. By the end of this guide, you’ll fetch historical candles for WTI, reason about update cadence and trading-day gaps, and wire a resilient client that caches and retries correctly using Indices-API.
What you’ll build: a reliable WTI historical series
This walkthrough focuses on building a time series for WTI (“Crude Oil WTI (CL)”) using two endpoints:
- Latest endpoint: to verify connectivity and get the most recent snapshot.
- Time-series or OHLC endpoint: to backfill daily closes or full candles between two dates.
Indices-API returns quotes with base=USD by default and expresses prices as “per index” in the unit field. For commodity-like instruments such as WTI, you should confirm the exact symbol code on the symbols registry before coding against it. If “CL” is not the final symbol, look it up first and adjust your requests accordingly.
Start a free 7-day trial on the PRO plan ($49.99/mo after) to access historical and near real-time data, then follow along with the examples. To get your key, use the Register link below.
Confirm the WTI symbol code before you fetch
The title references Crude Oil WTI (CL). Symbols can differ across data vendors and environments, so do not hardcode “CL” until you verify. Use the official symbols catalog to confirm the exact code and its availability in your plan:
- Check the supported code for WTI: Browse Indices-API Supported Symbols.
- Confirm whether WTI has daily “time-series” and/or “OHLC” coverage.
- Note display name, currency (USD), and any symbol remarks.
If the symbol differs (e.g., not “CL”), use the one listed in the symbols page for all requests. This prevents invalid_symbol errors and ensures continuity for backfills and alerts.
A quick connectivity check with the Latest endpoint
Use the Latest endpoint first to confirm your API key, base currency, and response structure. This endpoint returns a multi-symbol snapshot with fields you’ll also see in historical responses: timestamp, base, date, rates, and unit. While you may later filter to one symbol in your application code, the immediate goal is to validate transport and interpret the response envelope.
curl: Latest snapshot (base USD)
curl -s 'https://indices-api.com/api/latest?access_key=YOUR_API_KEY'
As of a live test during drafting, a symbol lookup returned the following official error envelope. Use this exact payload to build your client-side error handling and then resolve by confirming the correct symbol code on the symbols page.
{"success":false,"error":{"code":400,"type":"invalid_symbol","info":"One or more invalid symbols have been specified."}}
How to read the envelope when success=true (what your app should rely on):
- success: boolean indicating whether the request succeeded.
- timestamp: Unix time (UTC) for the snapshot’s effective time. Useful for cache keys and staleness detection.
- base: the base currency; Indices-API uses USD by default.
- date: YYYY-MM-DD trade date associated with the snapshot.
- rates: object keyed by symbol with numeric quotes.
- unit: “per index,” i.e., the quote is expressed per instrument unit with USD as the base.
If you receive invalid_symbol, go back to the symbols catalog, confirm WTI’s canonical code, and retry.
JavaScript example: fetch latest, parse, and guard for errors
async function fetchLatest() {
const url = 'https://indices-api.com/api/latest?access_key=YOUR_API_KEY';
const res = await fetch(url, { method: 'GET' });
const json = await res.json();
// This sample uses the real envelope provided in this article if the symbol is invalid.
// In production, handle both success=true and success=false.
if (!json.success) {
// Expect shape: { success:false, error:{ code, type, info } }
console.error('API error:', json.error);
// A common cause is an invalid symbol; confirm the WTI code on the Symbols page.
return null;
}
// On success, you will typically rely on these fields:
const { timestamp, base, date, rates, unit } = json;
// Example: if you confirmed WTI's symbol code, pull it here:
// const wtiQuote = rates['CONFIRMED_WTI_SYMBOL'];
// console.log({ timestamp, base, date, wtiQuote, unit });
return { timestamp, base, date, rates, unit };
}
fetchLatest().then(console.log).catch(console.error);
Notes that will save you time:
- Pricing is in USD by default. You don’t need to specify base=USD.
- Timestamps are UTC-based; normalize downstream times to a single timezone.
- Caching: treat timestamp+date as your cache key and refresh based on your plan’s update interval (e.g., up to every 10–60 minutes).
- Weekends and holidays: WTI won’t print on some calendar days. Use the last available date when forward-filling for charts.
Backfill daily history for WTI
For dashboards and research, you’ll need a consistent daily series between two dates. Use the time-series or OHLC endpoint based on your desired granularity:
- Time-series: daily rates keyed by date for a given start and end window.
- OHLC: open/high/low/close for one or more days.
Constraints that apply broadly when backfilling:
- Set end_date to a completed trading day. Do not use today as end_date; settle on the last full day to avoid partial data.
- Trading days only: expect gaps for weekends/holidays and fill them in your chart layer as needed.
- Pagination: if you request long ranges, loop by month/quarter to manage memory and respect any request-size constraints.
- Updates: new prints propagate based on your plan’s update frequency. If you poll intraday, cache until the server timestamp advances.
Designing your WTI fetcher
Because symbol mismatches are the most common source of 400 errors, resolve the WTI symbol first. Once confirmed, your workflow is:
- Call latest to verify plan and base settings.
- Call timeseries for historical backfill up to yesterday’s date.
- (Optional) Call OHLC for days where you need full candles (O/H/L/C), otherwise use the “close” equivalent from daily rates.
- Store normalized series in your DB (UTC dates, base USD, numeric values).
Interpreting fields you’ll actually use
Across latest, historical, and OHLC responses, your parsing logic typically depends on:
- base: Confirm “USD”. If your app supports multi-currency, treat base as metadata on the series.
- date or start_date/end_date: Align labels for charts and query windows.
- timestamp: Use for cache-control and staleness checks.
- rates: Extract the confirmed WTI symbol value. Store as a float with sufficient precision.
- unit: Keep as “per index.” It tells you this is a scalar quote per instrument.
Resilience: retries, caching, and symbol checks
For production stability:
- Retry: On transient network errors, back off and retry a few times. Do not hammer on persistent 4xx errors (like invalid_symbol).
- Cache by date and symbol: For historical calls, cache indefinitely once a day is settled. For latest, respect the timestamp and your update frequency.
- Validate symbols centrally: Load the symbols list into your app and whitelist allowed tickers. This eliminates most invalid_symbol errors at call time.
- Guard end_date: Ensure end_date is not “today.” If your UI requests “last 30 days,” compute end_date as yesterday in UTC.
Where to find parameters and endpoint details
This article deliberately focuses on the small set you need to ship a WTI chart. For complete parameters, response variations, and additional endpoints such as fluctuation and intraday, use the official documentation:
- Indices-API Documentation
- Managed Connectivity Program (MCP) for enterprise workflows
Practical notes for WTI specifically
- Contract conventions: WTI futures are often referenced as CL on U.S. venues. However, the data platform’s symbol can differ. Always confirm in the symbols registry.
- Session behavior: Expect limited or no updates on weekends. Some holiday eves and off-hours sessions can result in sparse prints.
- Roll logic: If you track front-month continuous series for analysis, maintain your own roll schedule. The API will quote by symbol; continuity is your app’s responsibility.
- Unit and currency: The API returns values with base=USD and unit=“per index,” which you should interpret as the instrument’s price in USD terms.
Putting it together in your app
Here’s a simple end-to-end approach for a WTI chart module:
- Symbol resolution: Load WTI’s code from the symbols list on boot. Fail fast if not found.
- Latest snapshot: Verify connectivity with the Latest endpoint; parse { success, date, timestamp, base, rates }.
- Backfill: Use a historical endpoint to fetch from start_date to yesterday’s end_date, chunked by calendar month. Fill chart gaps for non-trading days.
- Cache: Keep immutable historical days indefinitely; refresh latest only as frequently as your plan updates.
- Alerts: If you need day-over-day or week-over-week moves, schedule a daily fluctuation check after the session settles.
Additional resources for WTI context
- Exchange contract specs (for research context): CME WTI Crude Oil (CL) Contract
- Market calendar and data releases impacting oil: EIA Weekly Petroleum Status Report
FAQ
How do I find the exact WTI symbol supported by Indices-API?
Open the symbols catalog and search for “WTI” or “Crude Oil.” If the canonical code is not “CL,” use the one listed there for all requests: Indices-API Supported Symbols.
Why did I get invalid_symbol on my first call?
Symbols differ across data vendors. The error means the server didn’t recognize your ticker. Confirm WTI’s code in the symbols page and retry. Also check for typos and whitespace.
Can I set end_date to today for time-series?
Avoid using today as end_date. Use the most recent completed trading day (yesterday in UTC) to ensure you’re not ingesting partial or unsettled data.
How often do WTI quotes update?
Update frequency depends on your subscription tier (e.g., up to every 10–60 minutes). Use the response timestamp to decide when to refresh the cache.
What currency and units should I expect?
The API returns base=USD and unit=“per index.” Store that metadata alongside your series and display prices in USD unless your application does explicit conversions.
Get your key and start backfilling WTI today
Spin up your WTI chart and backfill in minutes. Create a free 7-day trial on PRO ($49.99/mo after), confirm the WTI code in the symbols page, and plug the endpoints into your pipeline. Get your API key here: Register. For endpoint specifics, see the Documentation, and if you need managed pipelines, review MCP.