A food business might follow corn, wheat and soybeans alongside fuel prices. A research platform might put gold, copper and crude oil on the same screen. Both need the same three things: a price now, enough history to show context, and a way to keep that screen up to date.
The SiftingIO Commodity Data API brings those markets into one integration. You can request prices over REST, download historical OHLCV bars, and receive real-time updates over WebSocket using the same API key.
This guide builds a practical commodity watchlist from those parts. It starts with corn and soybeans, adds metals and energy, then shows how to save price history and connect a live stream. The examples run on your computer or backend, with your API key kept in an environment variable.
A selection of SiftingIO commodity symbols#
The table below is a selection of the commodity symbols SiftingIO publishes, and the symbol catalog lists more. Use the API symbol exactly as shown when making a request.
| Category | Commodity | API symbol |
|---|---|---|
| Precious metals | Gold | XAUUSD |
| Precious metals | Silver | XAGUSD |
| Precious metals | Platinum | XPTUSD |
| Precious metals | Palladium | XPDUSD |
| Industrial metals | Copper | XCUUSD |
| Industrial metals | Aluminium | XALUSD |
| Industrial metals | Nickel | XNIUSD |
| Energy | WTI crude oil | WTIUSD |
| Energy | Brent crude oil | UKOUSD |
| Energy | Natural gas | NATGAS |
| Energy | Gasoline | GASUSD |
| Grains and oilseeds | Corn | CORN |
| Grains and oilseeds | Soybeans | SOYBEAN |
| Grains and oilseeds | Wheat | WHEAT |
| Soft commodities | Cotton | COTTON |
| Soft commodities | Coffee | COFFEE |
| Soft commodities | Sugar | SUGAR |
| Soft commodities | Cocoa | COCOA |
| Livestock | Cattle | CATTLE |
| Livestock | Hogs | HOGSUSD |
For an agricultural commodity prices API integration, a useful starting list is CORN, SOYBEAN and WHEAT. Add COTTON for textile exposure, or COFFEE, SUGAR and COCOA for food and beverage research. CATTLE and HOGSUSD extend the same workflow to livestock.
Energy belongs beside those markets when you want to follow transport and production costs. Metals bring in a different view: gold and silver for precious metals, copper, aluminium and nickel for industrial activity, and platinum and palladium for specialist applications.
Keep the product name, symbol and quoting unit together in your application. Commodity prices use different units and scales, so a price column should carry the unit associated with each instrument. For the instrument lookup and additional coverage requests, use the commodity symbol catalog.
Decide which API call your screen needs#
Think of the watchlist as four small jobs.
| Job | Interface | What your application receives |
|---|---|---|
| Fill the latest-price column | REST latest-price endpoint | Price and observation timestamp for one symbol |
| Show bid and ask | REST quote endpoint | Bid, ask, sizes and timestamp |
| Draw the price chart | REST historical bars endpoint | Open, high, low, close and volume fields for each interval |
| Keep prices moving | WebSocket, product com | Updates for the commodity symbols you subscribe to |
REST is a good fit for opening a page, downloading a dataset or running a scheduled report. WebSocket keeps a connection open and sends updates as they become available. That makes it useful for watchlists, alerts and live chart displays.
SiftingIO provides aggregated commodity pricing for these workflows. Oil instruments include CFD pricing series. Keep each series labelled with its own symbol and product name throughout your application. The data methodology explains how the published prices are produced.
Get an API key and request your first corn price#
Create a SiftingIO account, verify your email and generate an API key in the dashboard. The Free plan provides a starting point for trying the requests in this guide.
Set the key in the terminal where you will run the examples:
export SIFTINGIO_API_KEY='YOUR_API_KEY'
The REST API reads it from the X-API-Key header. Request corn with:
curl --fail-with-body --silent --show-error \
-H "X-API-Key: $SIFTINGIO_API_KEY" \
"https://api.sifting.io/v1/last/trade/commodities/CORN"
The block below is an illustrative example of the response shape. Its values are a fixture chosen to be internally consistent. It is not a recorded response, so expect different numbers when you run the request.
{
"s": "CORN",
"p": "443.49",
"P": "9",
"t": 1795014058506
}
s identifies the instrument. p is the published price, returned as a decimal string. t is its observation time in Unix milliseconds: in this example, 18 November 2026 at 15:00:58.506 UTC. For a price watchlist, those are the three fields to start with.
The capital P is a size field. The docs do not define a size unit for commodities; use the historical bar's v field when your analysis specifically needs the documented tick-count measure.
Change the final path segment to SOYBEAN, WHEAT, XAUUSD or another symbol from the table. Keep commodities in the path so the request identifies the correct asset class.
For bid and ask, use the quote endpoint:
curl --fail-with-body --silent --show-error \
-H "X-API-Key: $SIFTINGIO_API_KEY" \
"https://api.sifting.io/v1/last/quote/commodities/XAUUSD"
The quote fields are b for bid, a for ask and t for the observation time. Uppercase B and A carry the corresponding sizes. The quote API reference describes the complete response.
For a readable interface, format the price for display while preserving the original value and timestamp in storage. That lets a user see when a row last changed and gives your reporting code the original precision.
Download historical commodity data#
A current price tells you where a market is now. Historical bars let you put it on a chart, compare periods and measure the size of a move.
Use the same symbol with the historical Commodities endpoint. This request asks for hourly soybean bars over a recent date range:
curl --fail-with-body --silent --show-error --compressed \
-H "X-API-Key: $SIFTINGIO_API_KEY" \
-H "Accept-Encoding: gzip" \
"https://api.sifting.io/v1/hist/commodities/SOYBEAN/bars?start=2026-11-16T00:00:00Z&end=2026-11-17T23:59:59Z&interval=1h&limit=2000"
start and end define the requested window. The Z makes the UTC timezone explicit. interval=1h groups observations into hourly bars, and limit controls how many bars a response can contain. --compressed lets cURL decode the compressed response.
The returned JSON has a data array containing the bars and a meta object containing information about the request and pagination.
| Bar field | Meaning | Typical use |
|---|---|---|
t | Bar opening time, Unix milliseconds | Position the candle on the chart |
o | Open | First price in the interval |
h | High | Upper price range |
l | Low | Lower price range |
c | Close | Closing price for the interval |
v | Tick-count volume where available | Measure observed price-update activity |
Commodity v counts price updates rather than exchange-traded contracts. Keep that definition with the dataset when using it in research.
Supported intervals are 1m, 5m, 15m, 30m, 1h, 1d, 1w and 1mo. Use minute bars for detailed intraday work, hourly bars for a compact recent chart, and daily or monthly bars for longer views. Keep the chart timezone consistent across your watchlist.
Available depth is specific to each instrument. Select the dates your application needs when requesting agricultural, energy and other metal series. The historical Commodities reference covers the full parameter set.
Save the full result as a CSV in Python#
For larger downloads, follow meta.next_cursor until the API finishes the range. Each page keeps the same symbol, dates and interval; only the cursor advances.
Install Requests once:
python -m pip install requests
Save this as commodity_history.py. It downloads hourly corn bars and writes a CSV with an explicit UTC timestamp column.
import csv
import os
from datetime import datetime, timezone
import requests
def download_bars(session, symbol, start, end, interval="1h"):
url = f"https://api.sifting.io/v1/hist/commodities/{symbol}/bars"
params = {
"start": start,
"end": end,
"interval": interval,
"limit": 2000,
}
rows = {}
seen_cursors = set()
while True:
response = session.get(url, params=params, timeout=30)
response.raise_for_status()
page = response.json()
for bar in page["data"]:
rows[bar["t"]] = bar
cursor = page.get("meta", {}).get("next_cursor")
if not cursor:
break
if cursor in seen_cursors:
raise RuntimeError("The API returned a repeated cursor")
seen_cursors.add(cursor)
params["cursor"] = cursor
return [rows[t] for t in sorted(rows)]
def main():
symbol = "CORN"
with requests.Session() as session:
session.headers.update({
"X-API-Key": os.environ["SIFTINGIO_API_KEY"],
"Accept-Encoding": "gzip",
})
bars = download_bars(
session,
symbol,
"2026-11-16T00:00:00Z",
"2026-11-17T23:59:59Z",
)
if not bars:
raise RuntimeError("No bars were returned for this date range")
filename = f"{symbol}_1h.csv"
with open(filename, "w", newline="", encoding="utf-8") as file:
writer = csv.writer(file)
writer.writerow(["symbol", "time_utc", "open", "high", "low", "close", "volume"])
for bar in bars:
time_utc = datetime.fromtimestamp(
bar["t"] / 1000, tz=timezone.utc
).isoformat()
writer.writerow([
symbol, time_utc,
bar["o"], bar["h"], bar["l"], bar["c"], bar["v"],
])
print(f"Saved {len(bars)} bars to {filename}")
if __name__ == "__main__":
main()
Run python commodity_history.py from the terminal where you set your key. Requests handles gzip decoding. The script orders the bars by timestamp and keeps one row per bar opening time, including when a page overlaps an earlier result.
To reuse it for wheat, change symbol to WHEAT. For gold, use XAUUSD. The CSV opens in Excel and also gives a Python notebook a straightforward input for charting or analysis. You can also use SiftingIO's historical data export for a browser-based download.
Stream agricultural prices, gold and oil over WebSocket#
Once your watchlist has a history panel, add the live price column. A commodity subscription uses product: "com" and an array of symbols:
{
"op": "subscribe",
"product": "com",
"symbols": ["CORN", "SOYBEAN", "WHEAT", "XAUUSD", "WTIUSD"]
}
This five-symbol example fits the Free plan's symbol allowance. For a larger watchlist, choose the plan with the access and capacity your application needs.
The following example uses the built-in WebSocket client in Node.js 22.4 or later. Save it as commodity_stream.mjs. It authenticates, waits for confirmation and then subscribes.
const key = process.env.SIFTINGIO_API_KEY;
if (!key) throw new Error("Set SIFTINGIO_API_KEY first");
const symbols = ["CORN", "SOYBEAN", "WHEAT", "XAUUSD", "WTIUSD"];
const latest = new Map();
const socket = new WebSocket("wss://stream.sifting.io/ws/v1");
let heartbeat;
socket.addEventListener("open", () => {
socket.send(JSON.stringify({ op: "auth", key }));
});
socket.addEventListener("message", ({ data }) => {
const message = JSON.parse(data);
if (message.f === "error") {
console.error("Stream error:", message.code);
socket.close();
return;
}
if (message.f === "ack" && message.op === "auth") {
socket.send(JSON.stringify({ op: "subscribe", product: "com", symbols }));
heartbeat = setInterval(() => {
if (socket.readyState === WebSocket.OPEN) {
socket.send(JSON.stringify({ op: "ping" }));
}
}, 25000);
return;
}
if (message.f !== "tick" || !symbols.includes(message.s)) return;
if (message.p == null || !Number.isFinite(message.t)) return;
const previous = latest.get(message.s);
if (previous && message.t < previous.t) return;
latest.set(message.s, message);
console.log(message.s, message.p, new Date(message.t).toISOString());
});
socket.addEventListener("close", () => {
clearInterval(heartbeat);
console.log("Stream closed");
});
socket.addEventListener("error", () => {
console.error("WebSocket connection error");
});
Run it with node commodity_stream.mjs. The terminal prints a symbol, price and UTC timestamp for each received price update. The latest map holds the newest accepted observation for each row of your watchlist.
The server identifies frame types with f. An ack confirms an operation, a tick carries a price update, and a pong answers a keepalive. The WebSocket protocol also documents authentication through the connection URL and the other available operations.
For an application that stays connected all day, add reconnection with a short, increasing delay. Authenticate and subscribe again after reconnecting. If you are building candles from the stream, refresh the affected interval from REST history before continuing the chart. Keep the original observation time with every saved update.
Turn the requests into a useful commodity dashboard#
Start with a small, clear screen: commodity name, symbol, latest price, its unit and the last update time. A user can then select a row to open its historical chart.
Load the chart's completed candles from REST. Keep the live price in the row updated from WebSocket. If you display a candle for the interval still in progress, label it as the current candle and refresh completed intervals from the historical endpoint.
That design works across several practical applications:
| Application | Suggested starting watchlist | Useful output |
|---|---|---|
| Agricultural market monitor | CORN, SOYBEAN, WHEAT | Grain prices, recent ranges and price alerts |
| Food and beverage research | COFFEE, COCOA, SUGAR, GASUSD | Ingredient and transport-cost context |
| Industrial materials dashboard | XCUUSD, XALUSD, XNIUSD, WTIUSD | Metals and energy trends on one screen |
| Precious metals application | XAUUSD, XAGUSD, XPTUSD, XPDUSD | Live metal prices with historical charts |
| Livestock market monitor | CATTLE, HOGSUSD, CORN, SOYBEAN | Livestock prices alongside feed-input markets |
For comparisons between different commodities, percentage changes over the same period are easier to read than raw price levels. Keep the actual units visible wherever you show a price. For deeper work on procurement budgets, the commodity cost model guide extends this into quantities and currency conversion.
Run these API requests on your backend when serving a customer-facing product. Your application can pass the permitted display data to its interface while keeping the provider key in server-side configuration. The web application integration guide covers that setup.
Choose a Commodities subscription for your application#
Start by requesting the symbols and date ranges your product will use. Then choose a subscription around the workload and how your customers will see the data.
Free is useful for evaluation and personal, non-commercial work. Pro supports commercial applications and customer-facing display under its plan terms. Ultra adds unlimited monthly REST calls and unlimited symbol subscriptions, with the published sustained request rate. Enterprise is available for custom coverage, capacity and distribution requirements.
The same commodity identifiers and API patterns carry through those plans. That means the corn request you use for an initial test can remain part of the application as it grows.
Compare Commodities plans to select your subscription, or create an account and run the first request. If your project needs an additional commodity, send the instrument name and intended use through the dataset request form.
Common questions#
Are corn, wheat and soybean prices available through one API?#
Yes. Use CORN, WHEAT and SOYBEAN with the Commodities REST endpoints. Subscribe to the same symbols on the WebSocket com product for live updates.
Does the same API key work for gold, silver and oil?#
Yes. XAUUSD, XAGUSD, WTIUSD and UKOUSD use the same authentication model. Select Commodities access on your account and reuse the request patterns in this guide.
How do you get historical agricultural commodity data?#
Request the symbol through /v1/hist/commodities/{symbol}/bars with a start date, end date and interval. Include gzip support, then follow meta.next_cursor to download the complete available result for that window.
Can you save the prices and build your own charts?#
Historical OHLCV bars provide the chart history, and WebSocket updates can be recorded by your application. Choose a plan that covers your storage, commercial use and display requirements. Pro and Ultra support business applications under their plan terms.
What is the first step?#
Create your API key, request CORN, download a short range of hourly bars and run the five-symbol stream. You will have a working starting point for an agricultural, metals or energy watchlist using the same integration.



