API guide
Oil price API: WTI, Brent and natural gas prices in JSON
An oil price is a futures market wearing a spot price’s clothes. Know the benchmark, the unit and the contract calendar behind a number before you chart it.
On this page
- Energy symbols and their units
- Your first crude oil price API request
- The front month: what one oil price really is
- Units: barrels, MMBtu and cents
- Historical oil price data
- Streaming oil prices over WebSocket
- Polling budget: how many requests an oil dashboard needs
- What to look for in oil price data
- Questions
Key takeaways
- `GET /commodities/quote/WTIUSD` returns the WTI crude bid, ask and a Unix-millisecond timestamp; `BRENTUSD` gives Brent and `NGASUSD` natural gas.
- Crude benchmarks are conventionally quoted in US dollars per barrel of 42 US gallons, and US natural gas in dollars per million British thermal units (MMBtu).
- WTIUSD and BRENTUSD are continuous references: one series across futures expiries, so a steep curve can show up as a step around a contract’s last trading day.
- Daily bars cover UTC days. The energy reference trades from Sunday 18:00 to Friday 17:00 New York time with a one-hour pause each day.
- Every account starts with 3,000 free REST requests a month; the Commodities feed, with energy, metals and grains, is priced from $49 a month.
An oil price API returns crude and gas prices as JSON your code can read. With TickerLayer, GET /commodities/quote/WTIUSD returns the WTI crude bid, ask and a Unix-millisecond timestamp; swap the symbol for BRENTUSD to get Brent or NGASUSD for natural gas. The commodities.quotes WebSocket channel streams the same fields, and the aggregates route returns daily and intraday bars.
Energy sits in the commodities API next to metals and grains, under one key and one set of routes. What makes oil harder than a stock quote is everything around the number: two competing benchmarks (compared in WTI vs Brent), prices set in futures markets, contracts that expire every month, and units that change from product to product. This guide takes each in turn, with code that ran against the live API on 28 September 2026.
Energy symbols and their units
| Symbol | Name | Market convention | Unit the docs label |
|---|---|---|---|
WTIUSD | WTI crude oil | USD per barrel | USD |
BRENTUSD | Brent crude oil | USD per barrel | USD |
NGASUSD | Natural gas | USD per MMBtu | USD |
GASOLINEUSD | Gasoline (RBOB) | USD per US gallon | No label |
HOUSD | Heating oil | USD per US gallon | No label |
The split between the last two columns is deliberate. TickerLayer labels a unit only where the public contract documents one, and the energy references are documented as dollar prices. The magnitudes match the conventions (WTI near $96 and natural gas near $3.10 on 28 September 2026), but pin the unit in your own code as a named constant instead of letting a bare float travel through your system.
Your first crude oil price API request
curl -sS "https://api.tickerlayer.com/commodities/quote/WTIUSD" \
-H "x-api-key: $TICKERLAYER_API_KEY"GET /commodities/quote/WTIUSD
{
"symbol": "WTIUSD",1
"bid": 96.194,2
"ask": 96.242,3
"bid_size": 40,4
"ask_size": 44,
"timestamp": 17905911284595
}
symbolThe canonical code. Aliases resolve to it on quote, snapshot and aggregate routes.bidBest bid. With the ask, a 4.8-cent spread, about 5 basis points.askBest ask. REST sends both as JSON numbers.bid_sizeSize at the best bid. Units depend on the market, so read it as relative depth.timestampObservation time in Unix milliseconds, UTC: 2026-09-28 10:25:28.459.
For several benchmarks at once, loop over the symbols. This script prints each quote with its own observation time, then the Brent minus WTI spread. It needs Python 3.9 or newer and pip install requests.
import os
from datetime import datetime, timezone
import requests
API = "https://api.tickerlayer.com"
HEADERS = {"x-api-key": os.environ["TICKERLAYER_API_KEY"]}
ENERGY = {"WTIUSD": "WTI crude", "BRENTUSD": "Brent crude", "NGASUSD": "Natural gas"}
def quote(symbol: str) -> dict:
r = requests.get(f"{API}/commodities/quote/{symbol}", headers=HEADERS, timeout=10)
if r.status_code == 403:
raise SystemExit("This key has no commodities access: see tickerlayer.com/pricing")
r.raise_for_status()
return r.json()
mids = {}
for symbol, name in ENERGY.items():
q = quote(symbol)
bid, ask = float(q["bid"]), float(q["ask"])
mids[symbol] = (bid + ask) / 2
at = datetime.fromtimestamp(q["timestamp"] / 1000, tz=timezone.utc)
print(f"{name:<12} {symbol:<9} bid {bid:>8.3f} ask {ask:>8.3f} {at:%H:%M:%S} UTC")
print(f"Brent minus WTI: {mids['BRENTUSD'] - mids['WTIUSD']:.2f} USD")WTI crude WTIUSD bid 96.146 ask 96.194 10:56:27 UTC
Brent crude BRENTUSD bid 108.360 ask 108.410 10:56:22 UTC
Natural gas NGASUSD bid 3.101 ask 3.103 10:56:14 UTC
Brent minus WTI: 12.21 USDLook at the three timestamps. Each quote carries its own observation time, and the natural gas quote here was 13 seconds older than the WTI one. Before you subtract two prices, check that they belong to roughly the same moment; for a spread that feeds a decision, compare the timestamp values and skip the calculation when they drift too far apart.
The front month: what one oil price really is
Almost every headline oil price is a futures price. Crude changes hands in physical cargoes, but the number the world watches is set by the nearest futures contract, the front month. Each contract has a delivery month and a last trading day, and when the front contract expires, the next one takes its place.
A single daily series, the kind a chart or a backtest wants, has to cross from one contract to the next. The commodities data-quality page describes TickerLayer’s energy symbols as continuous references and treats spot, front-month and continuous futures as different instruments. That is the right mental model: WTIUSD is one unbroken series, not a single dated contract.
- October contract is frontthe series follows it
- Last trading day22 Sep 2026 for WTI
- November becomes frontthe series follows it now
- October minus Novembershows up as a step when the curve is steep
| Benchmark | Last trading day of a contract | Example |
|---|---|---|
| WTI crude | Three business days before the 25th of the month before delivery | October 2026 contract: 22 September 2026 |
| Brent crude | Last business day of the second month before delivery | November 2026 contract: 30 September 2026 |
| US natural gas | Third-to-last business day of the month before delivery | October 2026 contract: 28 September 2026 |
The size of the step equals the price gap between the two contracts, so it depends on the curve. In a calm, gently sloping market it is a few cents. In a supply squeeze, when near-term barrels are scarce and later ones are cheaper, it can be dollars. The contango and backwardation explainer shows the curve shapes behind it.
Units: barrels, MMBtu and cents
Energy prices come in different quantities, and mixing them is how a dashboard ends up plotting natural gas and crude on one axis. These are the conversions that come up in practice:
- 42US gallons in one barrel of crude
- 158.987liters in one barrel
- 1.055gigajoules in one MMBtu
- 100×error from plotting a cents quote as dollars
USD per liter = USD per barrel ÷ 158.987USD per gallon = USD per barrel ÷ 42USD per GJ = USD per MMBtu ÷ 1.055
Natural gas is the most regional of the three. US gas is conventionally quoted in dollars per MMBtu, while European gas trades in euros per megawatt-hour, and one megawatt-hour is about 3.412 MMBtu. The same gas priced per megawatt-hour therefore shows a number about 3.4 times larger than per MMBtu, before any currency or real price difference. Convert both sides to one unit and one currency before you compare regions.
Softs and grains add a second trap, because their convention is cents. SUGARUSD is documented in US cents per pound, so a value of 18.542 means $0.18542 a pound, and CORNUSD, WHEATUSD and SOYBEANUSD are in US cents per bushel. Plot sugar next to a dollar-quoted series without dividing by 100 and it is off by a factor of a hundred. The troy ounce and commodity units explainer has the full table, metals included.
Historical oil price data
Daily and intraday bars come from the aggregates route, under the same symbol as the live quote. Bar sizes are 1, 5 and 15 minutes, 1 and 4 hours, and 1 day; dates are UTC YYYY-MM-DD; limit goes up to 5,000, and next_offset pages through longer ranges. History depth is two years on Individual plans and ten on Business.
curl -sS "https://api.tickerlayer.com/commodities/agg/WTIUSD/1/day/2026-09-13/2026-09-25?sort=asc" \
-H "x-api-key: $TICKERLAYER_API_KEY"WTIUSD daily bars, 14 to 25 September 2026
The chart is a real, volatile month: WTI swung between $88.72 and $106.72 in two weeks. It also shows why the contract calendar belongs on the chart. The slide into 22 September, the last trading day of the October contract, can blend a falling market with the switch to November, and only the curve on that day can tell you how much was which.
Energy and metals reference hours, New York daylight time
Hours in UTC
Streaming oil prices over WebSocket
For a ticker or an alert, subscribe to commodities.quotes on the stream instead of polling. Right after the subscribe acknowledgement you get the last known value per symbol, marked "snapshot": true; after that, frames arrive as the reference moves. WebSocket access comes with paid plans.
{
"action": "subscribe",
"channels": ["commodities.quotes"],
"symbols": ["WTIUSD", "BRENTUSD", "NGASUSD"]
}A commodities.quotes frame
{
"type": "quote",1
"channel": "commodities.quotes",
"asset": "commodities",
"symbol": "WTIUSD",
"bid": 96.163,2
"ask": 96.211,
"bid_size": 51,
"ask_size": 97,
"ts": 1790593058637,3
"timestamp": 1790593058637,
"snapshot": true4
}
typequote for prices; system and error frames share the socket.bidA number on most commodity frames, but some arrive as strings. Parse with float() or Number().tsObservation time in Unix milliseconds. timestamp mirrors it; read ts.snapshotMarks the replayed last value sent right after you subscribe.
The gold price API guide has a complete Node.js streaming script that works unchanged for oil once you swap the symbols, and the WebSocket docs cover connection limits, error frames and reconnects.
Polling budget: how many requests an oil dashboard needs
REST is the simplest way to start, and the quota math decides how long it stays simple. Three energy symbols refreshed every 10 seconds for 23 hours a day is 24,840 requests a day, about 546,000 over 22 trading days. That is more than twice the 250,000 monthly calls on an Individual plan, for one small panel.
Two fixes keep the budget sane. Poll the snapshot only while someone is looking at the page, and move always-on panels and alerts to one WebSocket connection, which costs no REST calls at all. Every authenticated REST response also carries X-RateLimit-Limit and X-RateLimit-Remaining, so read your per-second ceiling from the headers instead of hard-coding it, and back off on a 429 for as long as Retry-After says.
What to look for in oil price data
Do
- Name the benchmark in the interface: WTI and Brent are different oils.
- Store the unit next to every price you persist.
- Compare timestamps before subtracting two quotes.
- Mark contract expiry dates on energy charts.
- Compute daily returns on trading days only.
Avoid
- Calling one of them "the oil price" without saying which.
- Plotting sugar in cents on a dollar axis.
- Alerting on a contract roll as if it were news.
- Treating an indicative reference as a settlement price.
- Polling in a tight loop when a stream would do.
On the provider side, a usable commodity price API documents its symbols and units, returns bid and ask, timestamps every quote and serves history under the same symbol. TickerLayer’s energy data is indicative reference pricing for applications and analytics, not an exchange settlement feed, and the market data disclaimer spells out what that means.
Questions
Is there a free oil price API?
Every TickerLayer account starts with 3,000 free REST requests a month and needs no card. Energy prices are part of the Commodities feed, priced from $49 a month on the Individual plan.
What unit is the oil price quoted in?
Crude benchmarks such as WTI and Brent are conventionally quoted in US dollars per barrel of 42 US gallons. US natural gas is quoted in dollars per million British thermal units (MMBtu).
What is the difference between WTI and Brent?
WTI is a light, sweet US crude priced for delivery inland at Cushing, Oklahoma; Brent is a light, sweet North Sea blend priced on tankers. Brent usually trades a few dollars higher.
Why do oil price charts jump around contract expiry?
Most oil price series follow the nearest futures contract. When it expires, the series moves to the next contract, and the price gap between the two delivery months shows up as a step.
Is the oil price API real-time?
Quotes are available in real time over REST and WebSocket. They are indicative reference prices rather than exchange settlements, and the public symbol pages on the website show them 15 minutes delayed.
How do I get historical crude oil prices?
Call GET /commodities/agg/WTIUSD/1/day/{from}/{to} with UTC dates and page with next_offset. Individual plans include two years of history and Business plans ten.