
What is a commodities api? A clear guide to price data interfaces and their uses
A commodities API gives developers programmatic access to commodity prices, quotes and historical data. Learn how REST and WebSocket APIs work and what to check before choosing a commodity data provider.
Imagine you are building a financial dashboard that tracks gold, crude oil and natural gas. Users expect prices to update throughout the day, and the application needs enough historical data to display price movements. Collecting these values manually from different websites quickly becomes difficult to maintain.
This is where a commodities API becomes useful.
A commodities API is a programmatic interface that allows an application to retrieve commodity market data from a data provider. Instead of scraping prices from web pages or maintaining separate data collection scripts, developers can request structured data and process it directly in their applications.
For fintech developers, the real question is not simply whether an API can return a commodity price. It is whether it provides the right instruments, update frequency and historical data for the product being built.
What data can a commodities API provide?
Commodity prices are used in more than one type of application. A market dashboard may need the latest price, while a charting tool needs historical prices and a monitoring service may require continuous updates.
A useful commodity price API should therefore be evaluated by the data it actually provides.
The main data types include:
Latest prices and Tick data. These provide the most recent available price and its associated timestamp. They are useful for price displays, watchlists and market monitoring. Depending on the API, responses may also include volume, turnover and other transaction fields.
Bid and Ask quotes. These show the buying and selling prices available for a supported instrument. They provide additional context beyond the latest price and can help developers build more informative market displays.
OHLC and historical time series. Open, High, Low and Close data is commonly used for candlestick charts, historical comparisons and price analysis. Developers can retrieve historical records through an HTTP request rather than collecting every past update themselves.
AllTick's Commodities API lists spot pricing, bid/ask quotes, OHLC candles and historical time series among its available data types. However, availability should always be checked against the specific instrument and account plan.
There is another detail that developers should not overlook: commodity prices do not all use the same unit.
For example, gold may be quoted in USD per troy ounce, crude oil in USD per barrel, and natural gas in USD per MMBtu. Comparing these prices without accounting for their units can produce misleading results.
The instrument type matters, too. Spot products, exchange-traded futures and CFDs are not interchangeable. AllTick's published commodity catalogue identifies its representative instruments as CFDs, so developers should not automatically treat these quotes as native exchange futures prices.
REST or WebSocket: Which interface should you use?
The choice depends on how your application consumes commodities market data.
REST is suitable when an application needs to request a price or retrieve historical records at a specific point. For example, a dashboard might request the latest gold and oil prices when a user opens the page.
WebSocket is more appropriate when prices need to keep updating while the application is running. Instead of repeatedly sending HTTP requests, the application maintains a connection and receives updates after subscribing to supported instruments.
These approaches solve different problems. REST handles on-demand retrieval, while WebSocket handles continuous streaming. A commodity monitoring application may use both: REST to load an initial market view and historical chart data, then WebSocket to maintain live price updates.
AllTick supports both access methods for its commodities data. Its newer REST API uses the X-API-Key authentication header, while the documented WebSocket interface uses a token in the connection URL. These are different integration conventions and should not be mixed.
Retrieving commodity prices with an API
A practical way to understand a commodity API is to request prices for two instruments and inspect the response.
AllTick's supported commodity codes include GOLD, Silver, USOIL, UKOIL, COPPER and NGAS. The exact spelling and capitalization matter, so developers should check the current instrument list before sending requests.
The following Python example uses AllTick's newer REST interface to request the latest quotes for gold and crude oil.
import os
import requests
from decimal import Decimal
API_KEY = os.getenv("ALLTICK_API_KEY")
if not API_KEY:
raise RuntimeError("Missing ALLTICK_API_KEY")
url = "https://quote.alltick.co/quote-b-api/v1/quote"
payload = {
"trace": "commodity-watchlist-001",
"data": {
"symbol_list": [
{"code": "GOLD"},
{"code": "USOIL"}
]
}
}
response = requests.post(
url,
headers={
"X-API-Key": API_KEY,
"Content-Type": "application/json"
},
json=payload,
timeout=10
)
response.raise_for_status()
result = response.json()
if result.get("ret") != 200:
raise RuntimeError(f"API request failed: {result}")
for item in result.get("data", {}).get("tick_list", []):
price = Decimal(item["price"])
print(
item["code"],
price,
item.get("tick_time")
)The example retrieves the latest available quote for each requested instrument. The application can then pass the returned values to a dashboard, store them for internal analysis or update a watchlist.
For continuous updates, developers can use AllTick's commodity WebSocket gateway. The documented trade subscription request uses cmd_id 22004, and successful subscriptions receive price updates through push messages with cmd_id 22998. The connection also requires a heartbeat every 10 seconds.
One distinction is important: retrieving the latest Tick does not mean retrieving historical Tick records. AllTick's latest-trade query documentation explicitly distinguishes current prices from historical trade-price queries. Applications that need past price movements should use the appropriate historical data interface instead.
What should you check before choosing a commodity price API?
A long list of supported symbols does not automatically make an API suitable for every project. A few checks can prevent substantial integration work later.
First, check instrument coverage. Confirm that the API supports the commodities your application needs. Gold and oil are common examples, but a project that also monitors copper, natural gas or other metals needs to verify those instruments individually.
Second, understand the instrument definition. Check whether a symbol represents a CFD, spot reference or another product type. Also confirm its quote currency, price unit and trading hours. Commodity markets do not all follow the same trading schedule, and daily breaks can create periods when prices stop updating normally.
Third, compare the available data with your application requirements. A latest-price feed may be enough for a simple watchlist, but a charting application also needs historical candles. A live monitoring service may need WebSocket updates rather than frequent REST polling.
Finally, review access limits and usage rights. Request frequency, symbol entitlements and WebSocket connection limits can vary by subscription plan. API access also does not automatically mean that data can be redistributed to application users. AllTick's published notice states that its data is provided for informational purposes, is not intended for trading or investing purposes, and must not be redistributed. Review the applicable terms before using the feed in a commercial product.
For developers building commodity dashboards, market-monitoring tools or internal research applications, AllTick provides access to precious metals and energy pricing through REST and WebSocket interfaces. Its supported examples include gold, silver, crude oil, natural gas and industrial metals.
Visit the AllTick data platform to review the available commodities, API access options and current documentation before integrating the data into your application.